changeset 23734:8d208de12bcc

Merge pull request #24 from ptschip/BUIP010_keep_orphans Do not purge orphans on peer disconnect
author gandrewstone <g.andrew.stone@gmail.com>
date Wed, 09 Mar 2016 15:05:10 -0500
parents 7ec35f979a30 71b9977a50b8
children 304b3a3add13
files
diffstat 8 files changed, 123 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/src/main.cpp	Mon Mar 07 20:49:11 2016 -0500
+++ b/src/main.cpp	Wed Mar 09 15:05:10 2016 -0500
@@ -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);
 
@@ -339,7 +338,7 @@
         nQueuedValidatedHeaders -= entry.fValidatedHeaders;
         mapBlocksInFlight.erase(entry.hash);
     }
-    EraseOrphansFor(nodeid);
+    //EraseOrphansFor(nodeid);  BUIP010 Xtreme Thinblocks - We do not want to delete orphans at any time.  We handle them when we accept a block
     nPreferredDownload -= state->fPreferredDownload;
 
     mapNodeState.erase(nodeid);
@@ -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;
@@ -5129,6 +5128,11 @@
         pfrom->thinBlock.hashPrevBlock = thinBlock.header.hashPrevBlock;
         pfrom->xThinBlockHashes = thinBlock.vTxHashes;
 
+        // Create the mapMissingTx from all the supplied tx's in the xthinblock
+        std::map<uint256, CTransaction> mapMissingTx;
+        BOOST_FOREACH(CTransaction tx, thinBlock.vMissingTx)
+            mapMissingTx[tx.GetHash()] = tx;
+
         // 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;
@@ -5142,7 +5146,7 @@
                 collision = true;
             mapPartialTxHash[cheapHash] = memPoolHashes[i];
         }
-        for (map<uint256, CTransaction>::iterator mi = thinBlock.mapMissingTx.begin(); mi != thinBlock.mapMissingTx.end(); ++mi) {
+        for (map<uint256, CTransaction>::iterator mi = mapMissingTx.begin(); mi != mapMissingTx.end(); ++mi) {
             uint64_t cheapHash = (*mi).first.GetCheapHash();
             if(mapPartialTxHash.count(cheapHash)) //Check for collisions
                 collision = true;
@@ -5180,7 +5184,7 @@
             if (!hash.IsNull())
             {
                 bool inMemPool = mempool.lookup(hash, tx);
-                bool inMissingTx = thinBlock.mapMissingTx.count(hash) > 0;
+                bool inMissingTx = mapMissingTx.count(hash) > 0;
                 bool inOrphanCache = mapOrphanTransactions.count(hash) > 0;
 
                 if ((inMemPool && inMissingTx) || (inOrphanCache && inMissingTx))
@@ -5193,7 +5197,7 @@
                 else if (inMemPool && fXVal)
                     setPreVerifiedTxHash.insert(hash);
                 else if (inMissingTx)
-                    tx = thinBlock.mapMissingTx[hash];
+                    tx = mapMissingTx[hash];
             }
             if (tx.IsNull())
                 missingCount++;
@@ -5201,7 +5205,7 @@
             pfrom->thinBlock.vtx.push_back(tx);
         }
         pfrom->thinBlockWaitingForTxns = missingCount;
-        LogPrint("thin", "thinblock waiting for: %d, unnecessary: %d, txs: %d full: %d\n", pfrom->thinBlockWaitingForTxns, unnecessaryCount, pfrom->thinBlock.vtx.size(), thinBlock.mapMissingTx.size());
+        LogPrint("thin", "thinblock waiting for: %d, unnecessary: %d, txs: %d full: %d\n", pfrom->thinBlockWaitingForTxns, unnecessaryCount, pfrom->thinBlock.vtx.size(), mapMissingTx.size());
 
         if (pfrom->thinBlockWaitingForTxns == 0) {
             // We have all the transactions now that are in this block: try to reassemble and process.
@@ -5221,15 +5225,15 @@
         else if (pfrom->thinBlockWaitingForTxns > 0) {
             // This marks the end of the transactions we've received. If we get this and we have NOT been able to
             // finish reassembling the block, we need to re-request the transactions we're missing:
-            std::vector<uint64_t> vHashesToRequest;
+            std::set<uint64_t> setHashesToRequest;
             for (size_t i = 0; i < pfrom->thinBlock.vtx.size(); i++) {
                  if (pfrom->thinBlock.vtx[i].IsNull()) {
-                     vHashesToRequest.push_back(pfrom->xThinBlockHashes[i]);
+                     setHashesToRequest.insert(pfrom->xThinBlockHashes[i]);
                      LogPrint("thin", "Re-requesting tx ==> 8 byte hash %d\n", pfrom->xThinBlockHashes[i]);
                  }
             }
             // Re-request transactions that we are still missing
-            CXThinBlockTx thinBlockTx(thinBlock.header.GetHash(), vHashesToRequest);
+            CXRequestThinBlockTx thinBlockTx(thinBlock.header.GetHash(), setHashesToRequest);
             pfrom->PushMessage(NetMsgType::GET_XBLOCKTX, thinBlockTx);
             LogPrint("thin", "Missing %d transactions for xthinblock, re-requesting\n", 
                       pfrom->thinBlockWaitingForTxns);
@@ -5260,6 +5264,11 @@
         pfrom->thinBlock.hashPrevBlock = thinBlock.header.hashPrevBlock;
         pfrom->thinBlockHashes = thinBlock.vTxHashes;
 
+        // Create the mapMissingTx from all the supplied tx's in the xthinblock
+        std::map<uint256, CTransaction> mapMissingTx;
+        BOOST_FOREACH(CTransaction tx, thinBlock.vMissingTx) 
+            mapMissingTx[tx.GetHash()] = tx;
+
         LOCK(cs_main);
         int missingCount = 0;
         int unnecessaryCount = 0;
@@ -5273,7 +5282,7 @@
             if (!hash.IsNull())
             {
                 bool inMemPool = mempool.lookup(hash, tx);
-                bool inMissingTx = thinBlock.mapMissingTx.count(hash) > 0;
+                bool inMissingTx = mapMissingTx.count(hash) > 0;
                 bool inOrphanCache = mapOrphanTransactions.count(hash) > 0;
 
                 if ((inMemPool && inMissingTx) || (inOrphanCache && inMissingTx))
@@ -5286,7 +5295,7 @@
                 else if (inMemPool && fXVal)
                     setPreVerifiedTxHash.insert(hash);
                 else if (inMissingTx)
-                    tx = thinBlock.mapMissingTx[hash];
+                    tx = mapMissingTx[hash];
             }
             if (tx.IsNull())
                 missingCount++;
@@ -5294,7 +5303,7 @@
             pfrom->thinBlock.vtx.push_back(tx);
         }
         pfrom->thinBlockWaitingForTxns = missingCount;
-        LogPrint("thin", "thinblock waiting for: %d, unnecessary: %d, txs: %d full: %d\n", pfrom->thinBlockWaitingForTxns, unnecessaryCount, pfrom->thinBlock.vtx.size(), thinBlock.mapMissingTx.size());
+        LogPrint("thin", "thinblock waiting for: %d, unnecessary: %d, txs: %d full: %d\n", pfrom->thinBlockWaitingForTxns, unnecessaryCount, pfrom->thinBlock.vtx.size(), mapMissingTx.size());
 
         if (pfrom->thinBlockWaitingForTxns == 0) {
             // We have all the transactions now that are in this block: try to reassemble and process.
@@ -5337,9 +5346,14 @@
             Misbehaving(pfrom->GetId(), 20);
         }
 
+        // Create the mapMissingTx from all the supplied tx's in the xthinblock
+        std::map<uint64_t, CTransaction> mapMissingTx;
+        BOOST_FOREACH(CTransaction tx, thinBlockTx.vMissingTx) 
+            mapMissingTx[tx.GetHash().GetCheapHash()] = tx;
+
         for (size_t i = 0; i < pfrom->thinBlock.vtx.size(); i++) {
              if (pfrom->thinBlock.vtx[i].IsNull()) {
-                 pfrom->thinBlock.vtx[i] = thinBlockTx.mapTx[pfrom->xThinBlockHashes[i]];
+                 pfrom->thinBlock.vtx[i] = mapMissingTx[pfrom->xThinBlockHashes[i]];
                  pfrom->thinBlockWaitingForTxns--;
                  LogPrint("thin", "Got Re-requested tx ==> 8 byte hash %d\n", pfrom->xThinBlockHashes[i]);
              }
@@ -5374,12 +5388,12 @@
 
     else if (strCommand == NetMsgType::GET_XBLOCKTX && !fImporting && !fReindex) // return Re-requested xthinblock transactions
     {
-        CXThinBlockTx thinBlockTx;
-        vRecv >> thinBlockTx;
+        CXRequestThinBlockTx thinRequestBlockTx;
+        vRecv >> thinRequestBlockTx;
 
         // We use MSG_TX here even though we refer to blockhash because we need to track 
         // how many xblocktx requests we make in case of DOS
-        CInv inv(MSG_TX, thinBlockTx.blockhash); 
+        CInv inv(MSG_TX, thinRequestBlockTx.blockhash); 
         LogPrint("thin", "received get_xblocktx for %s peer=%d\n", inv.hash.ToString(), pfrom->id);
 
         // Check for Misbehaving and DOS
@@ -5406,16 +5420,19 @@
         const Consensus::Params& consensusParams = Params().GetConsensus();
         if (!ReadBlockFromDisk(block, (*mi).second, consensusParams))
             assert(!"cannot load block from disk");
-
+        
+        std::vector<CTransaction> vTx;
         for (unsigned int i = 0; i < block.vtx.size(); i++)
         { 
             uint64_t cheapHash = block.vtx[i].GetHash().GetCheapHash();
-            if(thinBlockTx.mapTx.count(cheapHash))
-                thinBlockTx.mapTx[cheapHash] = block.vtx[i];
-        }
-        }
+            if(thinRequestBlockTx.setCheapHashesToRequest.count(cheapHash))
+                vTx.push_back(block.vtx[i]);
+        }
+
         pfrom->AddInventoryKnown(inv);
+        CXThinBlockTx thinBlockTx(thinRequestBlockTx.blockhash, vTx);
         pfrom->PushMessage(NetMsgType::XBLOCKTX, thinBlockTx);
+        }
     }
     // BUIP010 Xtreme Thinblocks: end section
 
@@ -6127,7 +6144,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 +6160,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	Wed Mar 09 15:05:10 2016 -0500
@@ -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	Wed Mar 09 15:05:10 2016 -0500
@@ -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	Wed Mar 09 15:05:10 2016 -0500
@@ -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/test/thinblock_tests.cpp	Mon Mar 07 20:49:11 2016 -0500
+++ b/src/test/thinblock_tests.cpp	Wed Mar 09 15:05:10 2016 -0500
@@ -45,24 +45,24 @@
     CBlock block = TestBlock();
     CThinBlock thinblock(block, filter);
     CXThinBlock xthinblock(block, &filter);
-    BOOST_CHECK_EQUAL(9, thinblock.mapMissingTx.size());
-    BOOST_CHECK_EQUAL(9, xthinblock.mapMissingTx.size());
+    BOOST_CHECK_EQUAL(9, thinblock.vMissingTx.size());
+    BOOST_CHECK_EQUAL(9, xthinblock.vMissingTx.size());
 
     /* insert txid not in block */
     const uint256 random_hash = uint256S("3fba505b48865fccda4e248cecc39d5dfbc6b8ef7b4adc9cd27242c1193c7133");
     filter.insert(random_hash);
     CThinBlock thinblock1(block, filter);
     CXThinBlock xthinblock1(block, &filter);
-    BOOST_CHECK_EQUAL(9, thinblock1.mapMissingTx.size());
-    BOOST_CHECK_EQUAL(9, xthinblock1.mapMissingTx.size());
+    BOOST_CHECK_EQUAL(9, thinblock1.vMissingTx.size());
+    BOOST_CHECK_EQUAL(9, xthinblock1.vMissingTx.size());
 
     /* insert txid in block */
     const uint256 hash_in_block = block.vtx[1].GetHash();
     filter.insert(hash_in_block);
     CThinBlock thinblock2(block, filter);
     CXThinBlock xthinblock2(block, &filter);
-    BOOST_CHECK_EQUAL(8, thinblock2.mapMissingTx.size());
-    BOOST_CHECK_EQUAL(8, xthinblock2.mapMissingTx.size());
+    BOOST_CHECK_EQUAL(8, thinblock2.vMissingTx.size());
+    BOOST_CHECK_EQUAL(8, xthinblock2.vMissingTx.size());
 
     /*collision test*/
     BOOST_CHECK(!xthinblock2.collision);
--- a/src/thinblock.cpp	Mon Mar 07 20:49:11 2016 -0500
+++ b/src/thinblock.cpp	Wed Mar 09 15:05:10 2016 -0500
@@ -20,7 +20,7 @@
         // NOTE: We always add the first tx, the coinbase as it is the one
         //       most often missing.
         if (!filter.contains(hash) || i == 0)
-            mapMissingTx[hash] = block.vtx[i];
+            vMissingTx.push_back(block.vtx[i]);
     }
 }
 
@@ -47,7 +47,7 @@
         // NOTE: We always add the first tx, the coinbase as it is the one
         //       most often missing.
         if ((filter && !filter->contains(hash256)) || i == 0)
-            mapMissingTx[hash256] = block.vtx[i];
+            vMissingTx.push_back(block.vtx[i]);
     }
 }
 
@@ -72,18 +72,18 @@
 
         // We always add the first tx, the coinbase as it is the one
         // most often missing.
-        if (i == 0) mapMissingTx[hash256] = block.vtx[i];
+        if (i == 0) vMissingTx.push_back(block.vtx[i]);
     }
 }
 
-
-
-CXThinBlockTx::CXThinBlockTx(uint256 blockHash, std::vector<uint64_t>& vHashesToRequest)
+CXThinBlockTx::CXThinBlockTx(uint256 blockHash, std::vector<CTransaction>& vTx)
 {
     blockhash = blockHash;
+    vMissingTx = vTx;
+}
 
-    CTransaction tx;
-    unsigned int n = vHashesToRequest.size();
-    for (unsigned int i = 0; i < n; i++)
-        mapTx[vHashesToRequest[i]] = tx;
+CXRequestThinBlockTx::CXRequestThinBlockTx(uint256 blockHash, std::set<uint64_t>& setHashesToRequest)
+{
+    blockhash = blockHash;
+    setCheapHashesToRequest = setHashesToRequest;
 }
--- a/src/thinblock.h	Mon Mar 07 20:49:11 2016 -0500
+++ b/src/thinblock.h	Wed Mar 09 15:05:10 2016 -0500
@@ -17,7 +17,7 @@
 public:
     CBlockHeader header;
     std::vector<uint256> vTxHashes; // List of all transactions id's in the block
-    std::map<uint256, CTransaction> mapMissingTx; // map of transactions that did not match the bloom filter
+    std::vector<CTransaction> vMissingTx; // vector of transactions that did not match the bloom filter
 
 public:
     CThinBlock(const CBlock& block, CBloomFilter& filter);
@@ -29,7 +29,7 @@
     inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
         READWRITE(header);
         READWRITE(vTxHashes);
-        READWRITE(mapMissingTx);
+        READWRITE(vMissingTx);
     }
 };
 
@@ -38,7 +38,7 @@
 public:
     CBlockHeader header;
     std::vector<uint64_t> vTxHashes; // List of all transactions id's in the block
-    std::map<uint256, CTransaction> mapMissingTx; // map of transactions that did not match the bloom filter
+    std::vector<CTransaction> vMissingTx; // vector of transactions that did not match the bloom filter
     bool collision;
 
 public:
@@ -52,7 +52,7 @@
     inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
         READWRITE(header);
         READWRITE(vTxHashes);
-        READWRITE(mapMissingTx);
+        READWRITE(vMissingTx);
     }
 };
 
@@ -64,10 +64,10 @@
 public:
     /** Public only for unit testing */
     uint256 blockhash;
-    std::map<uint64_t, CTransaction> mapTx; // map of missing transactions
+    std::vector<CTransaction> vMissingTx; // map of missing transactions
 
 public:
-    CXThinBlockTx(uint256 blockHash, std::vector<uint64_t>& vHashesToRequest);
+    CXThinBlockTx(uint256 blockHash, std::vector<CTransaction>& vTx);
     CXThinBlockTx() {}
 
     ADD_SERIALIZE_METHODS;
@@ -75,7 +75,29 @@
     template <typename Stream, typename Operation>
     inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
         READWRITE(blockhash);
-        READWRITE(mapTx);
+        READWRITE(vMissingTx);
+    }
+};
+// This class is used for retrieving a list of still missing transactions after receiving a "thinblock" message.
+// The CXThinBlockTx when recieved can be used to fill in the missing transactions after which it is sent
+// back to the requestor.  This class uses a 64bit hash as opposed to the normal 256bit hash.
+class CXRequestThinBlockTx
+{
+public:
+    /** Public only for unit testing */
+    uint256 blockhash;
+    std::set<uint64_t> setCheapHashesToRequest; // map of missing transactions
+
+public:
+    CXRequestThinBlockTx(uint256 blockHash, std::set<uint64_t>& setHashesToRequest);
+    CXRequestThinBlockTx() {}
+
+    ADD_SERIALIZE_METHODS;
+
+    template <typename Stream, typename Operation>
+    inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
+        READWRITE(blockhash);
+        READWRITE(setCheapHashesToRequest);
     }
 };
 #endif // BITCOIN_THINBLOCK_H
--- a/src/unlimited.cpp	Mon Mar 07 20:49:11 2016 -0500
+++ b/src/unlimited.cpp	Wed Mar 09 15:05:10 2016 -0500
@@ -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);
+                }
             }
         }
     }
@@ -682,8 +691,7 @@
 {
     if (inv.type == MSG_XTHINBLOCK)
     {
-      CXThinBlock xThinBlock(block, pfrom->pfilter);
-      //CXThinBlock xThinBlock(block);
+        CXThinBlock xThinBlock(block, pfrom->pfilter);
         int nSizeBlock = ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION);
         if (xThinBlock.collision == true) // If there is a cheapHash collision in this block then send a normal thinblock
         {
@@ -691,11 +699,11 @@
             int nSizeThinBlock = ::GetSerializeSize(xThinBlock, SER_NETWORK, PROTOCOL_VERSION);
             if (nSizeThinBlock < nSizeBlock) {
                 pfrom->PushMessage(NetMsgType::THINBLOCK, thinBlock);
-                LogPrint("thin", "TX HASH COLLISION: Sent thinblock - size: %d vs block size: %d => tx hashes: %d transactions: %d  peerid=%d\n", nSizeThinBlock, nSizeBlock, xThinBlock.vTxHashes.size(), xThinBlock.mapMissingTx.size(), pfrom->id);
+                LogPrint("thin", "TX HASH COLLISION: Sent thinblock - size: %d vs block size: %d => tx hashes: %d transactions: %d  peerid=%d\n", nSizeThinBlock, nSizeBlock, xThinBlock.vTxHashes.size(), xThinBlock.vMissingTx.size(), pfrom->id);
             }
             else {
                 pfrom->PushMessage(NetMsgType::BLOCK, block);
-                LogPrint("thin", "Sent regular block instead - xthinblock size: %d vs block size: %d => tx hashes: %d transactions: %d  peerid=%d\n", nSizeThinBlock, nSizeBlock, xThinBlock.vTxHashes.size(), xThinBlock.mapMissingTx.size(), pfrom->id);
+                LogPrint("thin", "Sent regular block instead - xthinblock size: %d vs block size: %d => tx hashes: %d transactions: %d  peerid=%d\n", nSizeThinBlock, nSizeBlock, xThinBlock.vTxHashes.size(), xThinBlock.vMissingTx.size(), pfrom->id);
             }
         }
         else // Send an xThinblock
@@ -704,11 +712,11 @@
             int nSizeThinBlock = ::GetSerializeSize(xThinBlock, SER_NETWORK, PROTOCOL_VERSION);
             if (nSizeThinBlock < nSizeBlock) {
                 pfrom->PushMessage(NetMsgType::XTHINBLOCK, xThinBlock);
-                LogPrint("thin", "Sent xthinblock - size: %d vs block size: %d => tx hashes: %d transactions: %d  peerid=%d\n", nSizeThinBlock, nSizeBlock, xThinBlock.vTxHashes.size(), xThinBlock.mapMissingTx.size(), pfrom->id);
+                LogPrint("thin", "Sent xthinblock - size: %d vs block size: %d => tx hashes: %d transactions: %d  peerid=%d\n", nSizeThinBlock, nSizeBlock, xThinBlock.vTxHashes.size(), xThinBlock.vMissingTx.size(), pfrom->id);
             }
             else {
                 pfrom->PushMessage(NetMsgType::BLOCK, block);
-                LogPrint("thin", "Sent regular block instead - xthinblock size: %d vs block size: %d => tx hashes: %d transactions: %d  peerid=%d\n", nSizeThinBlock, nSizeBlock, xThinBlock.vTxHashes.size(), xThinBlock.mapMissingTx.size(), pfrom->id);
+                LogPrint("thin", "Sent regular block instead - xthinblock size: %d vs block size: %d => tx hashes: %d transactions: %d  peerid=%d\n", nSizeThinBlock, nSizeBlock, xThinBlock.vTxHashes.size(), xThinBlock.vMissingTx.size(), pfrom->id);
             }
         }
     }
@@ -719,11 +727,11 @@
         int nSizeThinBlock = ::GetSerializeSize(thinBlock, SER_NETWORK, PROTOCOL_VERSION);
         if (nSizeThinBlock < nSizeBlock) { // Only send a thinblock if smaller than a regular block
             pfrom->PushMessage(NetMsgType::THINBLOCK, thinBlock);
-            LogPrint("thin", "Sent thinblock - size: %d vs block size: %d => tx hashes: %d transactions: %d  peerid=%d\n", nSizeThinBlock, nSizeBlock, thinBlock.vTxHashes.size(), thinBlock.mapMissingTx.size(), pfrom->id);
+            LogPrint("thin", "Sent thinblock - size: %d vs block size: %d => tx hashes: %d transactions: %d  peerid=%d\n", nSizeThinBlock, nSizeBlock, thinBlock.vTxHashes.size(), thinBlock.vMissingTx.size(), pfrom->id);
         }
         else {
             pfrom->PushMessage(NetMsgType::BLOCK, block);
-            LogPrint("thin", "Sent regular block instead - thinblock size: %d vs block size: %d => tx hashes: %d transactions: %d  peerid=%d\n", nSizeThinBlock, nSizeBlock, thinBlock.vTxHashes.size(), thinBlock.mapMissingTx.size(), pfrom->id);
+            LogPrint("thin", "Sent regular block instead - thinblock size: %d vs block size: %d => tx hashes: %d transactions: %d  peerid=%d\n", nSizeThinBlock, nSizeBlock, thinBlock.vTxHashes.size(), thinBlock.vMissingTx.size(), pfrom->id);
         }
     }
 }