[Pkg-bitcoin-commits] [bitcoin] 94/126: Disconnecting from bad outbound peers in IBD

Jonas Smedegaard dr at jones.dk
Mon Nov 13 20:02:57 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/0.15.1_dfsg-1
in repository bitcoin.

commit bf191a71836f357d7949459f666db506dffd123b
Author: Suhas Daftuar <sdaftuar at chaincode.com>
Date:   Wed Oct 11 08:55:14 2017 -0400

    Disconnecting from bad outbound peers in IBD
    
    When in IBD, we'd like to use all our outbound peers to help us
    sync the chain.  Disconnect any outbound peers whose headers have
    insufficient work.
    
    Github-Pull: #11490
    Rebased-From: c60fd71a65e841efe187992f46c583a704cc37f5
---
 src/net_processing.cpp          | 18 ++++++++++++++++++
 test/functional/minchainwork.py |  8 ++++++++
 2 files changed, 26 insertions(+)

diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 24d8d49..87a3655 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -2374,6 +2374,24 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
                 }
             }
         }
+        // If we're in IBD, we want outbound peers that will serve us a useful
+        // chain. Disconnect peers that are on chains with insufficient work.
+        if (IsInitialBlockDownload() && nCount != MAX_HEADERS_RESULTS) {
+            // When nCount < MAX_HEADERS_RESULTS, we know we have no more
+            // headers to fetch from this peer.
+            if (nodestate->pindexBestKnownBlock && nodestate->pindexBestKnownBlock->nChainWork < nMinimumChainWork) {
+                // This peer has too little work on their headers chain to help
+                // us sync -- disconnect if using an outbound slot (unless
+                // whitelisted or addnode).
+                // Note: We compare their tip to nMinimumChainWork (rather than
+                // chainActive.Tip()) because we won't start block download
+                // until we have a headers chain that has at least
+                // nMinimumChainWork, even if a peer has a chain past our tip,
+                if (!(pfrom->fInbound || pfrom->fWhitelisted || pfrom->m_manual_connection)) {
+                    pfrom->fDisconnect = true;
+                }
+            }
+        }
         }
     }
 
diff --git a/test/functional/minchainwork.py b/test/functional/minchainwork.py
index c7579d2..35cd7ad 100755
--- a/test/functional/minchainwork.py
+++ b/test/functional/minchainwork.py
@@ -27,6 +27,7 @@ class MinimumChainWorkTest(BitcoinTestFramework):
     def set_test_params(self):
         self.setup_clean_chain = True
         self.num_nodes = 3
+
         self.extra_args = [[], ["-minimumchainwork=0x65"], ["-minimumchainwork=0x65"]]
         self.node_min_work = [0, 101, 101]
 
@@ -74,6 +75,13 @@ class MinimumChainWorkTest(BitcoinTestFramework):
         self.nodes[0].generate(1)
 
         self.log.info("Verifying nodes are all synced")
+
+        # Because nodes in regtest are all manual connections (eg using
+        # addnode), node1 should not have disconnected node0. If not for that,
+        # we'd expect node1 to have disconnected node0 for serving an
+        # insufficient work chain, in which case we'd need to reconnect them to
+        # continue the test.
+
         self.sync_all()
         self.log.info("Blockcounts: %s", [n.getblockcount() for n in self.nodes])
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bitcoin/bitcoin.git



More information about the Pkg-bitcoin-commits mailing list