changeset 23723:8db896c8a117

small changes from review of xtreme thin blocks round 2
author Andrew Stone <g.andrew.stone@gmail.com>
date Mon, 07 Mar 2016 17:59:16 -0500
parents 4e6fe918712d
children e4cf7dea7306
files src/main.cpp src/main.h src/unlimited.cpp src/unlimited.h
diffstat 4 files changed, 24 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/main.cpp	Sun Mar 06 08:24:08 2016 -0800
+++ b/src/main.cpp	Mon Mar 07 17:59:16 2016 -0500
@@ -78,8 +78,6 @@
 uint64_t nPruneTarget = 0;
 bool fAlerts = DEFAULT_ALERTS;
 bool fEnableReplacement = DEFAULT_ENABLE_REPLACEMENT;
-//! The largest block size that we have seen since startup
-uint64_t nLargestBlockSeen; // BU - Xtreme Thinblocks
 
 
 /** Fees smaller than this (in satoshi) are considered zero fee (for relaying, mining and transaction creation) */
@@ -614,6 +612,7 @@
     // BU - we do not limit the size of orphans.  There is no danger to having memory overrun since the
     //      orphan cache is limited to only 5000 entries by default. Only 500MB of memory could be consumed
     //      if there were some kind of orphan memory exhaustion attack.
+    //      Dropping any tx means they need to be included in the thin block when it it mined, which is inefficient.
     //unsigned int sz = tx.GetSerializeSize(SER_NETWORK, CTransaction::CURRENT_VERSION);
     //if (sz > 5000)
     //{
@@ -1004,14 +1003,10 @@
          * be annoying or make others' transactions take longer to confirm. */
         static const double maxFeeCutoff = boost::lexical_cast<double>(GetArg("-maxlimitertxfee", DEFAULT_MAXLIMITERTXFEE)); /* maximum feeCutoff in satoshi per byte */
 	static const double initFeeCutoff = boost::lexical_cast<double>(GetArg("-minlimitertxfee", DEFAULT_MINLIMITERTXFEE)); /* starting value for feeCutoff in satoshi per byte*/
-        static uint64_t maxBlockSize = GetArg("-blockmaxsize", BLOCKSTREAM_CORE_MAX_BLOCK_SIZE); 
         static const int nLimitFreeRelay = GetArg("-limitfreerelay", DEFAULT_LIMITFREERELAY); 
         // get current memory pool size
         uint64_t poolBytes = pool.GetTotalTxSize();
 
-        // get the blocksize we're working with which will be the largest block seen
-        maxBlockSize = std::max(maxBlockSize, nLargestBlockSeen);
-
 	// Calculate feeCutoff in satoshis per byte:
 	//   When the feeCutoff is larger than the satoshiPerByte of the 
 	//   current transaction then spam blocking will be in effect. However
@@ -1028,17 +1023,17 @@
         // When the mempool starts falling use an exponentially decaying ~24 hour window:
         feeCutoff *= pow(1.0 - 1.0/86400, (double)(nNow - nLastTime));
 
-        if (poolBytes < maxBlockSize) {
+        if (poolBytes < nLargestBlockSeen) {
             feeCutoff = std::max(feeCutoff, initFeeCutoff);
             nFreeLimit = std::min(nFreeLimit, (double)nLimitFreeRelay);
         }
-        else if(poolBytes < (maxBlockSize * MAX_BLOCK_SIZE_MULTIPLYER)) {
+        else if(poolBytes < (nLargestBlockSeen * MAX_BLOCK_SIZE_MULTIPLIER)) {
             // Gradually choke off what is considered a free transaction
-            feeCutoff = std::max(feeCutoff, initFeeCutoff + ((maxFeeCutoff - initFeeCutoff) * (poolBytes - maxBlockSize) / (maxBlockSize * (MAX_BLOCK_SIZE_MULTIPLYER-1))));
+            feeCutoff = std::max(feeCutoff, initFeeCutoff + ((maxFeeCutoff - initFeeCutoff) * (poolBytes - nLargestBlockSeen) / (nLargestBlockSeen * (MAX_BLOCK_SIZE_MULTIPLIER-1))));
 
             // Gradually choke off the nFreeLimit as well but leave at least DEFAULT_MIN_LIMITFREERELAY
             // So that some free transactions can still get through
-            nFreeLimit = std::min(nFreeLimit, ((double)nLimitFreeRelay - ((double)(nLimitFreeRelay - DEFAULT_MIN_LIMITFREERELAY) * (double)(poolBytes - maxBlockSize) / (maxBlockSize * (MAX_BLOCK_SIZE_MULTIPLYER-1)))));
+            nFreeLimit = std::min(nFreeLimit, ((double)nLimitFreeRelay - ((double)(nLimitFreeRelay - DEFAULT_MIN_LIMITFREERELAY) * (double)(poolBytes - nLargestBlockSeen) / (nLargestBlockSeen * (MAX_BLOCK_SIZE_MULTIPLIER-1)))));
             if(nFreeLimit < DEFAULT_MIN_LIMITFREERELAY)
                 nFreeLimit = DEFAULT_MIN_LIMITFREERELAY;
         }
@@ -5135,6 +5130,7 @@
         pfrom->xThinBlockHashes = thinBlock.vTxHashes;
 
         // Create a map of all 8 bytes tx hashes pointing to their full tx hash counterpart 
+        // We need to check all transaction sources (orphan list, mempool, and new (incoming) transactions in this block) for a collision.
         bool collision = false;
         std::map<uint64_t, uint256> mapPartialTxHash;
         LOCK(cs_main);
--- a/src/main.h	Sun Mar 06 08:24:08 2016 -0800
+++ b/src/main.h	Mon Mar 07 17:59:16 2016 -0500
@@ -144,9 +144,6 @@
 extern CFeeRate minRelayTxFee;
 extern bool fAlerts;
 extern bool fEnableReplacement;  // BU TODO is this RBF flag?
-//! The largest block size that we have seen since startup
-extern uint64_t nLargestBlockSeen; // BU - Xtreme Thinblocks
-
 
 // BU - Xpress Validation: begin section
 /**
@@ -162,18 +159,6 @@
 static std::set<uint256> setUnVerifiedOrphanTxHash;
 // BU - Xpress Validation: end section
 
-// BU - Xtreme Thinblocks Auto Mempool Limiter - begin section
-/** The default value for -minrelaytxfee */
-static const char DEFAULT_MINLIMITERTXFEE[] = "0.0";
-/** The default value for -maxrelaytxfee */
-static const char DEFAULT_MAXLIMITERTXFEE[] = "5.0";
-/** The number of block heights to gradually choke spam transactions over */
-static const unsigned int MAX_BLOCK_SIZE_MULTIPLYER = 3;
-/** The minimum value possible for -limitfreerelay when rate limiting */
-static const unsigned int DEFAULT_MIN_LIMITFREERELAY = 1;
-// BU - Xtreme Thinblocks Auto Mempool Limiter - end section
-
-
 /** Best header we've seen so far (used for getheaders queries' starting points). */
 extern CBlockIndex *pindexBestHeader;
 
--- a/src/unlimited.cpp	Sun Mar 06 08:24:08 2016 -0800
+++ b/src/unlimited.cpp	Mon Mar 07 17:59:16 2016 -0500
@@ -49,6 +49,9 @@
 // BUIP010 Xtreme Thinblocks Variables
 std::map<uint256, uint64_t> mapThinBlockTimer;
 
+//! The largest block size that we have seen since startup
+uint64_t nLargestBlockSeen=BLOCKSTREAM_CORE_MAX_BLOCK_SIZE; // BU - Xtreme Thinblocks
+
 std::string UnlimitedCmdLineHelp()
 {
     std::string strUsage;
@@ -584,7 +587,7 @@
         }
     }
     else 
-        nLargestBlockSeen = std::max(nSizeBlock, (uint64_t)BLOCKSTREAM_CORE_MAX_BLOCK_SIZE);
+        nLargestBlockSeen = std::max(nSizeBlock, nLargestBlockSeen);
 
     LogPrint("thin", "Processed Block %s in %.2f seconds\n", inv.hash.ToString(), (double)(GetTimeMicros() - startTime) / 1000000.0);
     
--- a/src/unlimited.h	Sun Mar 06 08:24:08 2016 -0800
+++ b/src/unlimited.h	Mon Mar 07 17:59:16 2016 -0500
@@ -29,6 +29,20 @@
 extern unsigned int excessiveAcceptDepth;
 extern unsigned int maxMessageSizeMultiplier;
 
+// BU - Xtreme Thinblocks Auto Mempool Limiter - begin section
+/** The default value for -minrelaytxfee */
+static const char DEFAULT_MINLIMITERTXFEE[] = "0.0";
+/** The default value for -maxrelaytxfee */
+static const char DEFAULT_MAXLIMITERTXFEE[] = "5.0";
+/** The number of block heights to gradually choke spam transactions over */
+static const unsigned int MAX_BLOCK_SIZE_MULTIPLIER = 3;
+/** The minimum value possible for -limitfreerelay when rate limiting */
+static const unsigned int DEFAULT_MIN_LIMITFREERELAY = 1;
+// BU - Xtreme Thinblocks Auto Mempool Limiter - end section
+
+//! The largest block size that we have seen since startup
+extern uint64_t nLargestBlockSeen; // BU - Xtreme Thinblocks
+
 extern std::vector<std::string> BUComments;
 extern void settingsToUserAgentString();