-
Notifications
You must be signed in to change notification settings - Fork 1.2k
backport: partial Merge bitcoin/bitcoin#26326: net: reduce LOCK(cs_main) scope in GETBLOCKTXN #7350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -142,6 +142,7 @@ static constexpr auto BLOCK_STALLING_TIMEOUT_MAX{64s}; | |
| 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 | ||
|
|
@@ -4473,6 +4474,7 @@ void PeerManagerImpl::ProcessMessage( | |
| return; | ||
| } | ||
|
|
||
| FlatFilePos block_pos{}; | ||
| { | ||
| LOCK(cs_main); | ||
|
|
||
|
|
@@ -4483,13 +4485,20 @@ void PeerManagerImpl::ProcessMessage( | |
| } | ||
|
|
||
| if (pindex->nHeight >= m_chainman.ActiveChain().Height() - MAX_BLOCKTXN_DEPTH) { | ||
| CBlock block; | ||
| bool ret = ReadBlockFromDisk(block, pindex, m_chainparams.GetConsensus()); | ||
| assert(ret); | ||
| block_pos = pindex->GetBlockPos(); | ||
| } | ||
| } | ||
|
|
||
| SendBlockTransactions(pfrom, *peer, block, req); | ||
| if (!block_pos.IsNull()) { | ||
| CBlock block; | ||
| const auto hash = ReadBlockFromDisk(block, block_pos, m_chainparams.GetConsensus()); | ||
| if (!hash || *hash != req.blockhash) { | ||
| LogPrint(BCLog::NET, "Peer %d sent us a getblocktxn for a block we could not read\n", pfrom.GetId()); | ||
| return; | ||
|
Comment on lines
+4495
to
4497
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💬 Nitpick: Log line conflates disk read failure with hash mismatch After cs_main is released, two operationally distinct failures share one log line: ReadBlockFromDisk returning std::nullopt (OpenBlockFile failure, deserialization error, PoW header check failure — typically pruning or corruption) and a successful read whose source: ['claude', 'codex'] |
||
| } | ||
|
|
||
| SendBlockTransactions(pfrom, *peer, block, req); | ||
| return; | ||
| } | ||
|
|
||
| // If an older block is requested (should never happen in practice, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 Nitpick: Log message conflates I/O failure with hash mismatch
After dropping cs_main, the failure path emits the same "a block we could not read" line for two distinct conditions: ReadBlockFromDisk returning nullopt (open/deserialize/PoW failure) and the read succeeding with
*hash != req.blockhash(a stale FlatFilePos / disk-state inconsistency after the lock was released). Distinguishing these helps operators tell transient I/O or pruning issues from a position-vs-hash race. Diagnostic quality only; not a defect.source: ['claude']