diff options
author | Suhas Daftuar <sdaftuar@chaincode.com> | 2017-10-11 08:55:14 -0400 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2017-11-02 13:18:23 -0400 |
commit | bf191a71836f357d7949459f666db506dffd123b (patch) | |
tree | f6f410b14e72bda966ef09956617bdd04a72f9f2 /src | |
parent | d570aa4290bf678bab764aa58dde19167bc927f5 (diff) | |
download | bitcoin-bf191a71836f357d7949459f666db506dffd123b.tar.xz |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/net_processing.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 24d8d49c0c..87a3655307 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; + } + } + } } } |