changeset 23729:aa9d6c8df05b

Added Service Bit #4 for Xtreme Thinblocks Xtreme Thinblocks service enabled NODE_XTHIN = (1 << 4),
author Peter Tschipper <peter.tschipper@gmailcom>
date Mon, 07 Mar 2016 15:02:51 -0800
parents 7ec35f979a30
children 838c1d5e80cf
files src/main.cpp src/net.h src/protocol.h src/qt/guiutil.cpp src/unlimited.cpp
diffstat 5 files changed, 33 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/main.cpp	Mon Mar 07 20:49:11 2016 -0500
+++ b/src/main.cpp	Mon Mar 07 15:02:51 2016 -0800
@@ -79,7 +79,6 @@
 bool fAlerts = DEFAULT_ALERTS;
 bool fEnableReplacement = DEFAULT_ENABLE_REPLACEMENT;
 
-
 /** Fees smaller than this (in satoshi) are considered zero fee (for relaying, mining and transaction creation) */
 CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE);
 
@@ -1057,7 +1056,7 @@
             // -limitfreerelay unit is thousand-bytes-per-minute
             // At default rate it would take over a month to fill 1GB
             LogPrint("mempool", "Rate limit dFreeCount: %g => %g\n", dFreeCount, dFreeCount+nSize);
-            if ((dFreeCount + nSize) >= nFreeLimit*10*1000)
+            if ((dFreeCount + nSize) >= (nFreeLimit*10*1000 * nLargestBlockSeen / BLOCKSTREAM_CORE_MAX_BLOCK_SIZE))
                 return state.DoS(0, 
                        error("AcceptToMemoryPool : free transaction rejected by rate limiter"),
                        REJECT_INSUFFICIENTFEE, "rate limited free transaction");
@@ -4673,7 +4672,7 @@
                         if (IsThinBlocksEnabled() && IsChainNearlySyncd()) {
                             if (HaveConnectThinblockNodes() || (HaveThinblockNodes() && CheckThinblockTimer(inv.hash))) {
                                 // Must download a block from a ThinBlock peer
-                                if (pfrom->mapThinBlocksInFlight.size() < 1 && pfrom->nVersion >= THINBLOCKS_VERSION) { // We can only send one thinblock per peer at a time
+                                if (pfrom->mapThinBlocksInFlight.size() < 1 && pfrom->ThinBlockCapable()) { // We can only send one thinblock per peer at a time
                                     pfrom->mapThinBlocksInFlight[inv2.hash] = GetTime();
                                     inv2.type = MSG_XTHINBLOCK;
                                     std::vector<uint256> vOrphanHashes;
@@ -4689,7 +4688,7 @@
                             }
                             else {
                                 // Try to download a thinblock if possible otherwise just download a regular block
-                                if (pfrom->mapThinBlocksInFlight.size() < 1 && pfrom->nVersion >= THINBLOCKS_VERSION) { // We can only send one thinblock per peer at a time
+                                if (pfrom->mapThinBlocksInFlight.size() < 1 && pfrom->ThinBlockCapable()) { // We can only send one thinblock per peer at a time
                                     pfrom->mapThinBlocksInFlight[inv2.hash] = GetTime();
                                     inv2.type = MSG_XTHINBLOCK;
                                     std::vector<uint256> vOrphanHashes;
@@ -6127,7 +6126,7 @@
                     CBloomFilter filterMemPool;
                     if (HaveConnectThinblockNodes() || (HaveThinblockNodes() && CheckThinblockTimer(pindex->GetBlockHash()))) {
                         // Must download a block from a ThinBlock peer
-                        if (pto->mapThinBlocksInFlight.size() < 1 && pto->nVersion >= THINBLOCKS_VERSION) { // We can only send one thinblock per peer at a time
+                        if (pto->mapThinBlocksInFlight.size() < 1 && pto->ThinBlockCapable()) { // We can only send one thinblock per peer at a time
                             pto->mapThinBlocksInFlight[pindex->GetBlockHash()] = GetTime();
                             std::vector<uint256> vOrphanHashes;
                             for (map<uint256, COrphanTx>::iterator mi = mapOrphanTransactions.begin(); mi != mapOrphanTransactions.end(); ++mi)
@@ -6143,7 +6142,7 @@
                     }
                     else {
                         // Try to download a thinblock if possible otherwise just download a regular block
-                        if (pto->mapThinBlocksInFlight.size() < 1 && pto->nVersion >= THINBLOCKS_VERSION) { // We can only send one thinblock per peer at a time
+                        if (pto->mapThinBlocksInFlight.size() < 1 && pto->ThinBlockCapable()) { // We can only send one thinblock per peer at a time
                             pto->mapThinBlocksInFlight[pindex->GetBlockHash()] = GetTime();
                             std::vector<uint256> vOrphanHashes;
                             for (map<uint256, COrphanTx>::iterator mi = mapOrphanTransactions.begin(); mi != mapOrphanTransactions.end(); ++mi)
--- a/src/net.h	Mon Mar 07 20:49:11 2016 -0500
+++ b/src/net.h	Mon Mar 07 15:02:51 2016 -0800
@@ -493,10 +493,9 @@
     // BUIP010:
     bool ThinBlockCapable()
     {
-        if(nVersion >= THINBLOCKS_VERSION) return true;
+        if (nServices & NODE_XTHIN) return true;
         return false;
     }
-    
 
     void AddAddressKnown(const CAddress& addr)
     {
--- a/src/protocol.h	Mon Mar 07 20:49:11 2016 -0500
+++ b/src/protocol.h	Mon Mar 07 15:02:51 2016 -0800
@@ -260,6 +260,13 @@
     // but no longer do as of protocol version 70011 (= NO_BLOOM_VERSION)
     NODE_BLOOM = (1 << 2),
 
+    // BUIP010 - Xtreme Thinblocks - begin section
+    // NODE_XTHIN means the node supports Xtreme Thinblocks
+    // If this is turned off then the node will not service xthin requests nor  
+    // make xthin requests
+    NODE_XTHIN = (1 << 4),
+    // BUIP010 - Xtreme Thinblocks - end section
+
     // Bits 24-31 are reserved for temporary experiments. Just pick a bit that
     // isn't getting used, or one not being used much, and notify the
     // bitcoin-development mailing list. Remember that service bits are just
--- a/src/qt/guiutil.cpp	Mon Mar 07 20:49:11 2016 -0500
+++ b/src/qt/guiutil.cpp	Mon Mar 07 15:02:51 2016 -0800
@@ -909,6 +909,9 @@
             case NODE_BLOOM:
                 strList.append("BLOOM");
                 break;
+            case NODE_XTHIN:
+                strList.append("XTHIN");
+                break;
             default:
                 strList.append(QString("%1[%2]").arg("UNKNOWN").arg(check));
             }
--- a/src/unlimited.cpp	Mon Mar 07 20:49:11 2016 -0500
+++ b/src/unlimited.cpp	Mon Mar 07 15:02:51 2016 -0800
@@ -478,7 +478,7 @@
     {
         LOCK(cs_vNodes);
         BOOST_FOREACH (CNode* pnode, vNodes)
-            if (pnode->nVersion >= THINBLOCKS_VERSION)
+            if (pnode->ThinBlockCapable())
                 return true;
     }
     return false;
@@ -513,7 +513,14 @@
 
 bool IsThinBlocksEnabled() 
 {
-    return GetBoolArg("-use-thinblocks", true);
+    bool fThinblocksEnabled = GetBoolArg("-use-thinblocks", true);
+
+    // Enabling the XTHIN service should really be in init.cpp but because
+    // we want to avoid possile future merge conflicts with Core we can enable
+    // it here as it has little performance impact.
+    if (fThinblocksEnabled)
+        nLocalServices |= NODE_XTHIN;
+    return fThinblocksEnabled;
 }
 
 bool IsChainNearlySyncd() 
@@ -667,12 +674,14 @@
 
 void CheckNodeSupportForThinBlocks()
 {
-    // Check that a nodes pointed to with connect-thinblock actually supports thinblocks
-    BOOST_FOREACH(string& strAddr, mapMultiArgs["-connect-thinblock"]) {
-        if(CNode* pnode = FindNode(strAddr)) {
-            if(pnode->nVersion < THINBLOCKS_VERSION && pnode->nVersion > 0) {
-                LogPrintf("ERROR: You are trying to use connect-thinblocks but to a node that does not support it - Protocol Version: %d peer=%d\n", 
-                           pnode->nVersion, pnode->id);
+    if(IsThinBlocksEnabled()) {
+        // Check that a nodes pointed to with connect-thinblock actually supports thinblocks
+        BOOST_FOREACH(string& strAddr, mapMultiArgs["-connect-thinblock"]) {
+            if(CNode* pnode = FindNode(strAddr)) {
+                if(!pnode->ThinBlockCapable()) {
+                    LogPrintf("ERROR: You are trying to use connect-thinblocks but to a node that does not support it - Protocol Version: %d peer=%d\n", 
+                               pnode->nVersion, pnode->id);
+                }
             }
         }
     }