Skip to content

Commit 962f7f0

Browse files
committed
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.
1 parent 0df777d commit 962f7f0

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/net_processing.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,13 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
964964
// before ActivateBestChain but after AcceptBlock).
965965
// In this case, we need to run ActivateBestChain prior to checking the relay
966966
// conditions below.
967+
std::shared_ptr<const CBlock> a_recent_block;
968+
{
969+
LOCK(cs_most_recent_block);
970+
a_recent_block = most_recent_block;
971+
}
967972
CValidationState dummy;
968-
ActivateBestChain(dummy, Params());
973+
ActivateBestChain(dummy, Params(), a_recent_block);
969974
}
970975
if (chainActive.Contains(mi->second)) {
971976
send = true;
@@ -1525,8 +1530,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
15251530
uint256 hashStop;
15261531
vRecv >> locator >> hashStop;
15271532

1528-
LOCK(cs_main);
1529-
15301533
// We might have announced the currently-being-connected tip using a
15311534
// compact block, which resulted in the peer sending a getblocks
15321535
// request, which we would otherwise respond to without the new block.
@@ -1535,10 +1538,17 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
15351538
// for getheaders requests, and there are no known nodes which support
15361539
// compact blocks but still use getblocks to request blocks.
15371540
{
1541+
std::shared_ptr<const CBlock> a_recent_block;
1542+
{
1543+
LOCK(cs_most_recent_block);
1544+
a_recent_block = most_recent_block;
1545+
}
15381546
CValidationState dummy;
1539-
ActivateBestChain(dummy, Params());
1547+
ActivateBestChain(dummy, Params(), a_recent_block);
15401548
}
15411549

1550+
LOCK(cs_main);
1551+
15421552
// Find the last block the caller has in the main chain
15431553
const CBlockIndex* pindex = FindForkInGlobalIndex(chainActive, locator);
15441554

0 commit comments

Comments
 (0)