mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 15:50:07 +01:00
net: reduce LOCK(cs_main) scope in GETBLOCKTXN
Also adds a static assertion that MAX_BLOCKTXN_DEPTH <= MIN_BLOCKS_TO_KEEP
This commit is contained in:
@@ -118,6 +118,7 @@ static const unsigned int MAX_HEADERS_RESULTS = 2000;
|
||||
static const int MAX_CMPCTBLOCK_DEPTH = 5;
|
||||
/** Maximum depth of blocks we're willing to respond to GETBLOCKTXN requests for. */
|
||||
static const int MAX_BLOCKTXN_DEPTH = 10;
|
||||
static_assert(MAX_BLOCKTXN_DEPTH <= MIN_BLOCKS_TO_KEEP, "MAX_BLOCKTXN_DEPTH too high");
|
||||
/** Size of the "block download window": how far ahead of our current height do we fetch?
|
||||
* Larger windows tolerate larger download speed differences between peer, but increase the potential
|
||||
* degree of disordering of blocks on disk (which make reindexing and pruning harder). We'll probably
|
||||
@@ -4366,6 +4367,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
||||
return;
|
||||
}
|
||||
|
||||
FlatFilePos block_pos{};
|
||||
{
|
||||
LOCK(cs_main);
|
||||
|
||||
@@ -4376,15 +4378,21 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
||||
}
|
||||
|
||||
if (pindex->nHeight >= m_chainman.ActiveChain().Height() - MAX_BLOCKTXN_DEPTH) {
|
||||
CBlock block;
|
||||
const bool ret{m_chainman.m_blockman.ReadBlockFromDisk(block, *pindex)};
|
||||
assert(ret);
|
||||
|
||||
SendBlockTransactions(pfrom, *peer, block, req);
|
||||
return;
|
||||
block_pos = pindex->GetBlockPos();
|
||||
}
|
||||
}
|
||||
|
||||
if (!block_pos.IsNull()) {
|
||||
CBlock block;
|
||||
const bool ret{m_chainman.m_blockman.ReadBlockFromDisk(block, block_pos)};
|
||||
// If height is above MAX_BLOCKTXN_DEPTH then this block cannot get
|
||||
// pruned after we release cs_main above, so this read should never fail.
|
||||
assert(ret);
|
||||
|
||||
SendBlockTransactions(pfrom, *peer, block, req);
|
||||
return;
|
||||
}
|
||||
|
||||
// If an older block is requested (should never happen in practice,
|
||||
// but can happen in tests) send a block response instead of a
|
||||
// blocktxn response. Sending a full block response instead of a
|
||||
|
||||
Reference in New Issue
Block a user