changeset 23703:5f9289efe67a

fix garbage entry in unlimited fields. Touch up thinblock tests contributed by yarko L.
author Andrew Stone <g.andrew.stone@gmail.com>
date Tue, 23 Feb 2016 21:32:59 -0500
parents b934c46fd3a5
children 18da788aaa57
files src/qt/forms/unlimited.ui src/qt/unlimitedmodel.cpp src/test/thinblock_tests.cpp
diffstat 3 files changed, 41 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/qt/forms/unlimited.ui	Tue Feb 23 20:47:20 2016 -0500
+++ b/src/qt/forms/unlimited.ui	Tue Feb 23 21:32:59 2016 -0500
@@ -35,7 +35,7 @@
             <string extracomment="The largest block that will be mined"/>
            </property>
            <property name="text">
-            <string>Maximum Generated Block Size </string>
+            <string>Maximum Generated Block Size (bytes) </string>
            </property>
           </widget>
          </item>
@@ -223,7 +223,7 @@
          <item>
           <widget class="QLabel" name="label_3">
            <property name="text">
-            <string>Excessive Block Size </string>
+            <string>Excessive Block Size (in bytes)</string>
            </property>
           </widget>
          </item>
@@ -244,7 +244,7 @@
             <string extracomment="An excessive block normally blocks a chain from being accepted.  However, if the chain grows deeper than this accept the excessive block (and the chain)."/>
            </property>
            <property name="text">
-            <string>Excessive Acceptance Depth</string>
+            <string>Excessive Acceptance Depth (in blocks)</string>
            </property>
           </widget>
          </item>
--- a/src/qt/unlimitedmodel.cpp	Tue Feb 23 20:47:20 2016 -0500
+++ b/src/qt/unlimitedmodel.cpp	Tue Feb 23 21:32:59 2016 -0500
@@ -153,20 +153,42 @@
       switch (index.row())
         {
         case MaxGeneratedBlock:
-          maxGeneratedBlock = value.toULongLong();
-          settings.setValue("maxGeneratedBlock", (unsigned int) maxGeneratedBlock);
-          break;
+          {
+            uint64_t mgb = value.toULongLong(&successful);
+            if (successful)
+              {
+                maxGeneratedBlock = mgb;
+                settings.setValue("maxGeneratedBlock", (unsigned int) maxGeneratedBlock);
+              }
+          } break;
         case ExcessiveBlockSize:
-          excessiveBlockSize = value.toUInt();
-          if (excessiveBlockSize < 1000) excessiveBlockSize *= 1000000;  // If the user put in a size in MB then just auto fix
-          settingsToUserAgentString();
-          settings.setValue("excessiveBlockSize", excessiveBlockSize);
-          break;
+          {
+          unsigned int ebs = excessiveBlockSize;
+          ebs = value.toUInt();
+          if (ebs == 0)
+            {
+              float tmp = value.toFloat();
+              if (tmp<1000.0) ebs = (int) (tmp*1000000); // If the user put in a size in MB then just auto fix -- handle float separately to not round
+            }
+          if (ebs == 0) successful = false;
+          else
+            { 
+            if (ebs < 1000) ebs *= 1000000;  // If the user put in a size in MB then just auto fix
+            excessiveBlockSize = ebs;
+            settingsToUserAgentString();
+            settings.setValue("excessiveBlockSize", excessiveBlockSize);
+            }
+          } break;
         case ExcessiveAcceptDepth:
-          excessiveAcceptDepth = value.toUInt();
-          settingsToUserAgentString();
-          settings.setValue("excessiveAcceptDepth",excessiveAcceptDepth);
-          break;
+          {
+          unsigned int ead = value.toUInt(&successful);
+          if (successful)
+            {
+              excessiveAcceptDepth = ead;
+              settingsToUserAgentString();
+              settings.setValue("excessiveAcceptDepth",excessiveAcceptDepth);
+            }
+          } break;
         case UseReceiveShaping:
           if (settings.value("fUseReceiveShaping") != value)
             {
--- a/src/test/thinblock_tests.cpp	Tue Feb 23 20:47:20 2016 -0500
+++ b/src/test/thinblock_tests.cpp	Tue Feb 23 21:32:59 2016 -0500
@@ -44,7 +44,7 @@
     CBloomFilter filter = TestFilter();
     CBlock block = TestBlock();
     CThinBlock thinblock(block, filter);
-    CXThinBlock xthinblock(block, filter);
+    CXThinBlock xthinblock(block, &filter);
     BOOST_CHECK_EQUAL(9, thinblock.mapMissingTx.size());
     BOOST_CHECK_EQUAL(9, xthinblock.mapMissingTx.size());
 
@@ -52,7 +52,7 @@
     const uint256 random_hash = uint256S("3fba505b48865fccda4e248cecc39d5dfbc6b8ef7b4adc9cd27242c1193c7133");
     filter.insert(random_hash);
     CThinBlock thinblock1(block, filter);
-    CXThinBlock xthinblock1(block, filter);
+    CXThinBlock xthinblock1(block, &filter);
     BOOST_CHECK_EQUAL(9, thinblock1.mapMissingTx.size());
     BOOST_CHECK_EQUAL(9, xthinblock1.mapMissingTx.size());
 
@@ -60,7 +60,7 @@
     const uint256 hash_in_block = block.vtx[1].GetHash();
     filter.insert(hash_in_block);
     CThinBlock thinblock2(block, filter);
-    CXThinBlock xthinblock2(block, filter);
+    CXThinBlock xthinblock2(block, &filter);
     BOOST_CHECK_EQUAL(8, thinblock2.mapMissingTx.size());
     BOOST_CHECK_EQUAL(8, xthinblock2.mapMissingTx.size());
 
@@ -68,7 +68,7 @@
     BOOST_CHECK(!xthinblock2.collision);
     block.vtx.push_back(block.vtx[1]); //duplicate tx
     filter.clear();
-    CXThinBlock xthinblock3(block, filter);
+    CXThinBlock xthinblock3(block, &filter);
     BOOST_CHECK(xthinblock3.collision);
 }