aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorMatt Corallo <git@bluematt.me>2017-01-05 15:15:40 -0500
committerMatt Corallo <git@bluematt.me>2017-01-05 15:16:34 -0500
commitc1ae4fcf7d5d85c182e36ff6f7a529f8a84aa372 (patch)
treeab3ebc2399867bab9a6e07a29e66d47bca229e0b /src/net_processing.cpp
parent9eb67f50008970d09a8253475d591cdad872692e (diff)
Avoid holding cs_most_recent_block while calling ReadBlockFromDisk
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index fdb70d6578..440696ae55 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -2894,15 +2894,20 @@ bool SendMessages(CNode* pto, CConnman& connman, std::atomic<bool>& interruptMsg
int nSendFlags = state.fWantsCmpctWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
- LOCK(cs_most_recent_block);
- if (most_recent_block_hash == pBestIndex->GetBlockHash()) {
- if (state.fWantsCmpctWitness)
- connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, *most_recent_compact_block));
- else {
- CBlockHeaderAndShortTxIDs cmpctblock(*most_recent_block, state.fWantsCmpctWitness);
- connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, cmpctblock));
+ bool fGotBlockFromCache = false;
+ {
+ LOCK(cs_most_recent_block);
+ if (most_recent_block_hash == pBestIndex->GetBlockHash()) {
+ if (state.fWantsCmpctWitness)
+ connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, *most_recent_compact_block));
+ else {
+ CBlockHeaderAndShortTxIDs cmpctblock(*most_recent_block, state.fWantsCmpctWitness);
+ connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, cmpctblock));
+ }
+ fGotBlockFromCache = true;
}
- } else {
+ }
+ if (!fGotBlockFromCache) {
CBlock block;
bool ret = ReadBlockFromDisk(block, pBestIndex, consensusParams);
assert(ret);