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:
1 file changed
+10
-2
+10
-2
@@ -118,6 +118,7 @@ static const unsigned int MAX_HEADERS_RESULTS = 2000;
|
|||||||
static const int MAX_CMPCTBLOCK_DEPTH = 5;
|
static const int MAX_CMPCTBLOCK_DEPTH = 5;
|
||||||
/** Maximum depth of blocks we're willing to respond to GETBLOCKTXN requests for. */
|
/** Maximum depth of blocks we're willing to respond to GETBLOCKTXN requests for. */
|
||||||
static const int MAX_BLOCKTXN_DEPTH = 10;
|
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?
|
/** 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
|
* 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
|
* 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FlatFilePos block_pos{};
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
||||||
@@ -4376,14 +4378,20 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pindex->nHeight >= m_chainman.ActiveChain().Height() - MAX_BLOCKTXN_DEPTH) {
|
if (pindex->nHeight >= m_chainman.ActiveChain().Height() - MAX_BLOCKTXN_DEPTH) {
|
||||||
|
block_pos = pindex->GetBlockPos();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!block_pos.IsNull()) {
|
||||||
CBlock block;
|
CBlock block;
|
||||||
const bool ret{m_chainman.m_blockman.ReadBlockFromDisk(block, *pindex)};
|
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);
|
assert(ret);
|
||||||
|
|
||||||
SendBlockTransactions(pfrom, *peer, block, req);
|
SendBlockTransactions(pfrom, *peer, block, req);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// If an older block is requested (should never happen in practice,
|
// If an older block is requested (should never happen in practice,
|
||||||
// but can happen in tests) send a block response instead of a
|
// but can happen in tests) send a block response instead of a
|
||||||
|
|||||||
Reference in new issue
Block a user