backport: partial Merge bitcoin/bitcoin#26326: net: reduce LOCK(cs_main) scope in GETBLOCKTXN#7350
Conversation
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis PR adds a compile-time check that Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ No Merge Conflicts DetectedThis PR currently has no conflicts with other open PRs. |
6440dea to
97af883
Compare
|
✅ Review complete (commit 037d040) |
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
Targeted change narrows the cs_main hold window in GETBLOCKTXN by capturing the block file position under the lock and performing the disk read outside it, with a hash check that fails closed on stale/pruned/mismatched reads. Both agents concur the change is correct; only a minor log-granularity nitpick remains.
💬 1 nitpick(s)
| 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; |
There was a problem hiding this comment.
💬 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']
|
Is this not code we inherited from bitcoin? it is rare we want to accept a "fix" in their code. |
|
Good question. I checked this against upstream Bitcoin: the change is actually bringing this path back in line with the current inherited Bitcoin pattern, not inventing a Dash-only behavior. Bitcoin master already copies the recent block position under So I agree with the general rule — we should be cautious about “fixing” inherited Bitcoin code — but in this case the safer path is to follow the upstream Bitcoin fix rather than keep Dash on the older wider-lock version. |
Hmm; it seems then, that there may be a backport that we should backport instead of doing this adhoc? |
|
Yep — I traced it more precisely and there is an exact upstream Bitcoin commit for this:
That commit adds the same So I agree with your process concern: this should be treated as a Bitcoin backport, not as an ad-hoc Dash-only fix. If you prefer, I can close this PR and re-run it through the normal backport flow; otherwise I can update the PR metadata/commit message to explicitly cite the upstream commit. |
|
This pull request has conflicts, please rebase. |
97af883 to
c6ccbc6
Compare
|
This pull request has conflicts, please rebase. |
|
Rebased this onto current |
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
Cumulative review at c6ccbc6: the GETBLOCKTXN lock-scope reduction is correct — FlatFilePos is captured under cs_main, disk I/O runs lock-free, and the post-read hash check fails closed on stale/mismatched reads. No new in-scope defects in the latest delta. Carrying forward the prior nitpick about the log message conflating read failure with hash mismatch (already tracked in an unresolved inline thread).
💬 1 nitpick(s)
Note: GitHub does not allow me to submit APPROVE on my own PR, so this is posted as a COMMENT while preserving the verified non-blocking findings.
| 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; |
There was a problem hiding this comment.
💬 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 *hash != req.blockhash (the FlatFilePos captured under cs_main no longer points at the requested block, e.g. a race with reorg/prune/reindex in the very window this PR introduces). Splitting these into two messages would make the new lock-scope reduction easier to diagnose if it surfaces in the wild. Purely diagnostic quality; behavior is correct. Existing unresolved thread: #7350 (comment).
source: ['claude', 'codex']
|
Claw; please update this to actually be a backport, if it should so be instead of an adhoc change that doesn't accomplish / get shown in history as a backport |
…OCKTXN 613a45c net: reduce LOCK(cs_main) scope in GETBLOCKTXN (Andrew Toth) Pull request description: Inspired by bitcoin#11913 and bitcoin#26308. `cs_main` doesn't need to be locked while reading blocks. This removes the locks in `net_processing`. Dash notes: This is a partial backport of bitcoin#26326. It includes only the GETBLOCKTXN commit, adapted to Dash's current ReadBlockFromDisk API and post-read hash validation. The sibling upstream ProcessGetBlockData commit is not included in this PR.
c6ccbc6 to
037d040
Compare
|
Updated. I amended the PR head so the commit history now records this as a partial backport of bitcoin#26326, specifically bitcoin/bitcoin@613a45c ( |
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
Cumulative review at 037d040. Source tree is unchanged from c6ccbc6; the push only rewrote commit metadata into proper Dash partial-backport form. The GETBLOCKTXN lock-scope reduction is correct: FlatFilePos captured under cs_main, disk read runs lock-free, post-read hash check fails closed on mismatch/missing/pruned. Only carried-forward finding is a low-confidence log-diagnostic nitpick about line 4496 conflating two distinct failure modes.
💬 1 nitpick(s)
Carried-forward findings already raised (1)
These findings were not re-posted as new inline comments because an existing review thread already covers them.
- [NITPICK] (deduped existing open thread)
src/net_processing.cpp:4495-4497: Log message conflates I/O failure with hash mismatch — Two operationally distinct failures share one log message:ReadBlockFromDiskreturningstd::nullopt(OpenBlockFile failure, deserialization error, PoW header check failure — typically pruning/corruption) and a successful read whose*hash != req.blockhash(the FlatFilePos captured under cs_m...
Note: GitHub does not allow me to approve my own PR, so this is posted as a COMMENT while preserving the verified nonblocking finding.
backport: partial Merge bitcoin#26326
Upstream backport
This PR is a partial backport of bitcoin#26326:
net: reduce LOCK(cs_main) scope in GETBLOCKTXN)ProcessGetBlockDatacommit from the same Bitcoin PR.Issue being fixed or feature implemented
Recent
GETBLOCKTXNhandling selected and read the requested block from disk while holdingcs_main. A peer can request recent block transactions repeatedly, so the disk I/O should not extend the validation/global chain lock hold time.What was done?
cs_main.cs_mainbefore reading the block from disk.BLOCKTXN.How Has This Been Tested?
Tested on macOS arm64.
git diff --check upstream/develop...HEAD./configure --without-gui --disable-bench --disable-fuzz-binarywith the macOS arm64 dependsconfig.sitemake -j8 src/dashdshipAfter converting the PR history to backport metadata, the source tree stayed unchanged from the previously reviewed/rebased head.
Breaking Changes
None.
Checklist