fix: reduce GETBLOCKTXN disk read lock scope#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)
WalkthroughThis PR hardens GETBLOCKTXN message handling in the Dash peer-to-peer network layer. A compile-time assertion now enforces that the maximum block transaction depth does not exceed the minimum blocks retained. The serving logic for deep blocks has been refactored to capture the disk position from the block index, explicitly read the block from disk at that position, and verify the retrieved block's hash before responding, replacing an earlier approach that relied on assertions for success validation. Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Infer (1.2.0)src/net_processing.cppsrc/net_processing.cpp:6:10: error: 'net_processing.h' file not found with include; use "quotes" instead ... [truncated 2200 characters] ... __CTrans.CTrans_funct.get_clang_stmt_trans in file "src/clang/cTrans.ml" (inlined), line 5395, characters 4-69 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 97af883) |
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']
fix: reduce GETBLOCKTXN disk read lock scope
Issue being fixed or feature implemented
Recent
GETBLOCKTXNhandling selected and read the requested block from disk whileholding
cs_main. A peer can request recent block transactions repeatedly, so thedisk I/O should not extend the validation/global chain lock hold time.
What was done?
cs_main.cs_mainbefore reading the block from disk.sending
BLOCKTXN.returning instead of asserting.
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 depends
config.sitemake -j8 src/dashdshipBreaking Changes
None.
Checklist