Skip to content

Commit

Permalink
Merge bitcoin#9252: Release cs_main before calling ProcessNewBlock, o…
Browse files Browse the repository at this point in the history
…r processing headers (cmpctblock handling)

bd02bdd Release cs_main before processing cmpctblock as header (Suhas Daftuar)
680b0c0 Release cs_main before calling ProcessNewBlock (cmpctblock handling) (Suhas Daftuar)
  • Loading branch information
sipa authored and gladcow committed Apr 4, 2018
1 parent 36415f8 commit 085e9ce
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/net_processing.cpp
Expand Up @@ -2045,11 +2045,24 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
}
}

// When we succeed in decoding a block's txids from a cmpctblock
// message we typically jump to the BLOCKTXN handling code, with a
// dummy (empty) BLOCKTXN message, to re-use the logic there in
// completing processing of the putative block (without cs_main).
bool fProcessBLOCKTXN = false;
CDataStream blockTxnMsg(SER_NETWORK, PROTOCOL_VERSION);

// If we end up treating this as a plain headers message, call that as well
// without cs_main.
bool fRevertToHeaderProcessing = false;
CDataStream vHeadersMsg(SER_NETWORK, PROTOCOL_VERSION);

// Keep a CBlock for "optimistic" compactblock reconstructions (see
// below)
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
bool fBlockReconstructed = false;

{
LOCK(cs_main);
// If AcceptBlockHeader returned true, it set pindex
assert(pindex);
Expand Down Expand Up @@ -2125,9 +2138,8 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
// Dirty hack to jump to BLOCKTXN code (TODO: move message handling into their own functions)
BlockTransactions txn;
txn.blockhash = cmpctblock.header.GetHash();
CDataStream blockTxnMsg(SER_NETWORK, PROTOCOL_VERSION);
blockTxnMsg << txn;
return connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::BLOCKTXN, blockTxnMsg, nTimeReceived, chainparams));
fProcessBLOCKTXN = true;
} else {
req.blockhash = pindex->GetBlockHash();
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::GETBLOCKTXN, req));
Expand Down Expand Up @@ -2163,11 +2175,17 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
// Dirty hack to process as if it were just a headers message (TODO: move message handling into their own functions)
std::vector<CBlock> headers;
headers.push_back(cmpctblock.header);
CDataStream vHeadersMsg(SER_NETWORK, PROTOCOL_VERSION);
vHeadersMsg << headers;
return ProcessMessage(pfrom, NetMsgType::HEADERS, vHeadersMsg, nTimeReceived, chainparams, connman, interruptMsgProc);
fRevertToHeaderProcessing = true;
}
}
} // cs_main

if (fProcessBLOCKTXN)
return ProcessMessage(pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, nTimeReceived, chainparams, connman, interruptMsgProc);

if (fRevertToHeaderProcessing)
return ProcessMessage(pfrom, NetMsgType::HEADERS, vHeadersMsg, nTimeReceived, chainparams, connman, interruptMsgProc);

if (fBlockReconstructed) {
// If we got here, we were able to optimistically reconstruct a
Expand Down

0 comments on commit 085e9ce

Please sign in to comment.