diff options
author | Matt Corallo <git@bluematt.me> | 2017-01-11 21:15:28 -0800 |
---|---|---|
committer | Matt Corallo <git@bluematt.me> | 2017-01-11 21:18:48 -0800 |
commit | 962f7f054fd9692f92d40c771cf3ba8ef0cde891 (patch) | |
tree | 1ff1ab9c0e2289e8895f56eab7e0143fb2dbe0cc | |
parent | 0df777db6d62a4fc3353edecdcc0094dc1abbd18 (diff) | |
download | bitcoin-962f7f054fd9692f92d40c771cf3ba8ef0cde891.tar.xz |
Call ActivateBestChain without cs_main/with most_recent_block
There is still a call to ActivateBestChain with cs_main if a peer
requests the block prior to it being validated, but this one is
more specifically-gated, so should be less of an issue.
-rw-r--r-- | src/net_processing.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 440696ae55..015921ebe9 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -964,8 +964,13 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam // before ActivateBestChain but after AcceptBlock). // In this case, we need to run ActivateBestChain prior to checking the relay // conditions below. + std::shared_ptr<const CBlock> a_recent_block; + { + LOCK(cs_most_recent_block); + a_recent_block = most_recent_block; + } CValidationState dummy; - ActivateBestChain(dummy, Params()); + ActivateBestChain(dummy, Params(), a_recent_block); } if (chainActive.Contains(mi->second)) { send = true; @@ -1525,8 +1530,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, uint256 hashStop; vRecv >> locator >> hashStop; - LOCK(cs_main); - // We might have announced the currently-being-connected tip using a // compact block, which resulted in the peer sending a getblocks // request, which we would otherwise respond to without the new block. @@ -1535,10 +1538,17 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, // for getheaders requests, and there are no known nodes which support // compact blocks but still use getblocks to request blocks. { + std::shared_ptr<const CBlock> a_recent_block; + { + LOCK(cs_most_recent_block); + a_recent_block = most_recent_block; + } CValidationState dummy; - ActivateBestChain(dummy, Params()); + ActivateBestChain(dummy, Params(), a_recent_block); } + LOCK(cs_main); + // Find the last block the caller has in the main chain const CBlockIndex* pindex = FindForkInGlobalIndex(chainActive, locator); |