Skip to content

Commit c1ae4fc

Browse files
committed
Avoid holding cs_most_recent_block while calling ReadBlockFromDisk
1 parent 9eb67f5 commit c1ae4fc

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/net_processing.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,15 +2894,20 @@ bool SendMessages(CNode* pto, CConnman& connman, std::atomic<bool>& interruptMsg
28942894

28952895
int nSendFlags = state.fWantsCmpctWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
28962896

2897-
LOCK(cs_most_recent_block);
2898-
if (most_recent_block_hash == pBestIndex->GetBlockHash()) {
2899-
if (state.fWantsCmpctWitness)
2900-
connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, *most_recent_compact_block));
2901-
else {
2902-
CBlockHeaderAndShortTxIDs cmpctblock(*most_recent_block, state.fWantsCmpctWitness);
2903-
connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, cmpctblock));
2897+
bool fGotBlockFromCache = false;
2898+
{
2899+
LOCK(cs_most_recent_block);
2900+
if (most_recent_block_hash == pBestIndex->GetBlockHash()) {
2901+
if (state.fWantsCmpctWitness)
2902+
connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, *most_recent_compact_block));
2903+
else {
2904+
CBlockHeaderAndShortTxIDs cmpctblock(*most_recent_block, state.fWantsCmpctWitness);
2905+
connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, cmpctblock));
2906+
}
2907+
fGotBlockFromCache = true;
29042908
}
2905-
} else {
2909+
}
2910+
if (!fGotBlockFromCache) {
29062911
CBlock block;
29072912
bool ret = ReadBlockFromDisk(block, pBestIndex, consensusParams);
29082913
assert(ret);

0 commit comments

Comments
 (0)