Provider refusals
write_verifier: Provider declined the request because of a cybersecurity restriction. Experiments remain incomplete; static verification can continue.
2 minor findings · 9 suggestions
Findings
[minor] · Announced blocks can lose GETDATA requests during storage
For a locally submitted block, a peer's full-block fallback GETDATA can be discarded without reply during the off-lock write, delaying propagation; this timing-dependent failure was not observed.
Location: src/validation.cpp:4915 (head).
Details and suggested fix
When submitblock supplies a valid tip-extending block outside IBD, PrepareAcceptBlockStorage() announces it through NewPoWValidBlock() before releasing cs_main for the write. A high-bandwidth peer can then fall back from compact reconstruction to full-block GETDATA. Before FinishAcceptBlock() publishes the block, HaveNumChainTxs() is false, so ProcessGetBlockData() skips activation. BlockRequestAllowed() rejects the block before the recent-block cache is considered, and ProcessGetData() erases the request without replying or retaining it for completion. At base, the request waited for storage and could take the activation path. The affected peer must instead obtain the block elsewhere or wait for download recovery. Defer requests for being-stored entries until publication, while keeping the off-lock write and early compact relay.
[minor] · Queued pruning can trigger an avoidable low-disk shutdown
On a pruned node sharing a nearly full filesystem between blocks and chainstate, the coins space check can request shutdown before queued deletions free space that let the base continue.
Location: src/validation.cpp:3022 (head).
Details and suggested fix
Automatic pruning now queues UnlinkPrunedFiles() after persisting the block index, then immediately checks space for the coins write. The fixed block-index reserve can pass while the additional dirty-coins estimate fails solely because those deletions have not completed. The default KernelNotifications::fatalError() then requests shutdown. Base removed the files before this check; restart cleanup recovers the space but requires an unnecessary interruption. Keep the normal path asynchronous, retain the unlink completion handle, and on a failed coins-space check wait for this flush's deletions and recheck before calling FatalError(). The worker contract excludes cs_main, and the index still precedes deletion.
Optional improvements
[suggestion] · The durability test bypasses the production finish step
The new test can pass if production acceptance stops restoring the file's unsynced status after a write, because the test calls UnpinBlockFile() itself.
Location: src/test/durability_machine_tests.cpp:104 (head).
Details and suggested fix
After CreateAndProcessBlock() finishes, the test manually pins and unpins the already-stored tip's file, with no claim or write between them. It therefore checks the helper's bookkeeping rather than its production placement before ReceivedBlockTransactions(). Add a deterministic test that calls AcceptNewBlock(), synchronizes while storage is pending, then calls WriteNewBlock() and FinishNewBlock(). Assert that BLOCK_HAVE_DATA remains clear before finishing, that the file is Unsynced afterwards, and that the next sync makes it Synced. Use forced processing of a non-winning side-chain block so activation does not hide the observation with a flush. This exercises the actual durability handoff without threads or sleeps.
[suggestion] · In-flight invalidation and duplicate outcomes lack deterministic assertions
No deterministic test asserts the cached-invalid verdict, unpublished data and new_block reset after in-flight invalidation, or checks suppression of an in-progress duplicate.
Location: src/validation.cpp:4717 (head).
Details and suggested fix
FailedMeanwhile() chooses duplicate-invalid with BLOCK_CACHED_INVALID, which avoids discouraging inbound peers, and prevents publication after an ancestor becomes invalid. FinishNewBlock() also clears new_block on this path. Exercise these outcomes by accepting a block, invalidating its parent between stages, then writing and finishing it. Assert failure, the result and reject reason, new_block == false, and no BLOCK_HAVE_DATA. Separately accept the same block twice before finishing the first submission and assert that the second submission has prepared.store == false and new_block == false. The existing concurrent signal-ordering test does not assert these outcomes.
[suggestion] · The rollover test never exercises deferred trimming
The rollover fixture only checks immediate trimming, so it does not verify that a departed file stays untrimmed until its last pinned writer finishes.
Location: src/test/blockmanager_tests.cpp:376 (head).
Details and suggested fix
LeftBlockFileSetup uses WriteBlock() for every block and never takes a file pin. It cannot distinguish immediate trimming from the new m_blockfiles_to_trim path or verify that the pin count must reach zero. Add a staged case that claims and pins two writes in the old file, advances the cursor, and finishes those writes one at a time. Assert that the preallocated tail survives rollover and the first unpin, then that the last unpin trims the file to exactly nSize. Also check that both written blocks read back intact.
[suggestion] · O1 and O5 exclude a state the message handler can now observe
The ordering contract in validation.h still limits half-processed blocks to stored data or the delivering message, even though a concurrent submitblock call exposes the new being-stored state.
Location: src/validation.h:522 (head).
Details and suggested fix
After PrepareAcceptBlockStorage() returns, the header can be accepted and announced while transaction counts and block data remain unpublished. A non-message-handler submission leaves this state visible while the write runs. Nevertheless, O1 says the only intermediate state is stored-but-not-activated, and O5 confines received-but-not-stored blocks to the delivering message. Update O1 to distinguish being stored from stored-but-not-activated, and qualify O5 for non-message-handler submissions. Name ProcessGetBlockData() as an observer, since its existing activation check explicitly relies on O1 and cannot close the being-stored state.
[suggestion] · Out-of-order allocation lacks a chunk-boundary regression test
The new storage tests do not distinguish per-reservation allocation from the required monotonically growing allocation on Windows and macOS.
Location: src/test/blockmanager_tests.cpp:372 (head).
Details and suggested fix
Preallocate() must allocate from the recorded allocated end, not independently for each reservation. Otherwise, writing a later reservation first and allocating an earlier one afterwards can shrink the file through Windows SetEndOfFile() or macOS ftruncate(), removing the later block's bytes. Claim distinguishable blocks spanning allocation chunks within one file, write the later reservation first, then write the earlier reservations. Assert the final file size and exact block round-trips. This needs no concurrent execution. Native Linux posix_fallocate() does not shrink existing files, so the regression may only be distinguished by Windows and macOS runs.
[suggestion] · ConnectBlock() still documents exclusive block access for atomic checks
The ConnectBlock() contract still forbids sharing an immutable block even though its cited mutable check flags are now atomic.
Location: src/primitives/block.h:103 (head).
Details and suggested fix
validation.h requires exclusive use of block because CheckBlock() records results in mutable fields. This PR turns fChecked, m_checked_witness_commitment and m_checked_merkle_root into BlockCheckedFlag atomics, and AcceptNewBlock() explicitly supports concurrent checks of one block object. Update the contract to require that block contents remain unchanged during validation rather than requiring exclusive use. Keep the separate synchronization requirements for the coins view, validation caches and check queue.
[suggestion] · FlushBlockFile() retains unreachable finalization modes
Its sole remaining caller always selects false, false, leaving unused modes and a conditional undo flush that no longer occurs.
Location: src/node/blockstorage.cpp:972 (base).
Details and suggested fix
Rollover now uses TrimBlockFile() and TrimUndoFile(). The only remaining FlushBlockFile() caller is FlushChainstateBlockFile(), which disables both finalization flags, so !fFinalize || finalize_undo is always true. Remove both parameters, flush block and undo files with finalization disabled, and remove the selective-undo-flush explanation. Preserve the initialization guard, assertion, failure handling and unsynced-file bookkeeping. This makes the helper's actual behavior explicit instead of exposing unused combinations.
[suggestion] · The prune commit describes exclusion instead of cursor relocation
The commit message describes IsCursorFile() exclusion, but its patch permits pruning a lower-numbered cursor file and relocates its cursor, changing the safety rule reviewers need to check.
Location: src/node/blockstorage.h:318 at 89352ce92ea1 (commit) (commit).
Details and suggested fix
In 89352ce92ea11962389525854ca694fa0f39f640, relative to direct parent 519488a11599e4fd2a4b0831e1c511f1dfafdad0, both prune finders call LeaveCursorFile() after PruneOneBlockFile(). The helper moves matching cursors to MaxBlockfileNum() + 1 and may grow m_blockfile_info; it does not skip cursor files as the message claims. Reword the commit message to describe this relocation and explain how unused file numbers prevent a delayed unlink from deleting a newly claimed file. This preserves the actual rule needed to review lower-cursor pruning.
[suggestion] · The file-work commit mixes an independent read-path refactor
89352ce combines an unconsumed read/parse API split with concurrency-sensitive storage changes, making two independent changes harder to validate separately.
Location: src/node/blockstorage.h:583 at 89352ce92ea1 (commit) (commit).
Details and suggested fix
Extract the BlockBytes, ReadBlockBytes() and ParseBlock() changes from 89352ce92ea11962389525854ca694fa0f39f640 into a preparatory commit immediately after its current direct parent, 519488a11599e4fd2a4b0831e1c511f1dfafdad0. ReadBlock() can keep composing the same byte read and parse/check logic, and none of this PR's allocation or pruning changes consumes the new halves. This lets reviewers validate the read refactor separately from preallocation, deferred trimming, the I/O pool, asynchronous unlink and cursor relocation. The series description places the independent consumers in later PRs #45 and #48, so this is a commit-organization suggestion rather than a head defect.
Background
Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.
Documented decisions
The pre-AcceptBlock CheckBlock call was deliberately restored as defensive redundancy. The 2017 hardening proposal called it 'belt-and-suspenders'; the later documentation change tied its explanation to the 2019 invalid-block analysis. The pinned base explicitly explains the tradeoff: avoid caching a header as invalid because an unexpectedly malleable body fails CheckBlock, while accepting the small cost of repeating these relatively inexpensive checks.
Moving checks off cs_main changes synchronization, not the reason for separating body rejection from persistent header invalidity. The new split retains a distinct treatment for CheckBlock failure versus contextual failure; a duplicate or previously known header does not itself make a failed body check a cached-invalid verdict.
Early compact-block relay deliberately precedes full transaction validation. The historical invalid-compact-block proposal quotes BIP152: the sender must verify the header's transaction commitment, chain attachment, and proof of work, but may forward before checking valid UTXO spends. Consequently, a peer must not be banned merely because a reconstructed compact block subsequently fails full validation.
This explains why NewPoWValidBlock represents a narrower milestone than connected or fully valid. The base invokes it after block/contextual checks but before disk writing, outside IBD and only for a block extending the active tip. Head O4 explicitly preserves that placement. Relay eligibility must remain separate from the later publication of readable stored data; the inspected protocol source does not independently establish that preceding disk I/O is itself a protocol requirement.
Crash durability requires ordering across independently persisted stores, not merely successful writes. The 2018 block-file persistence proposal identified the danger of a durable block index referring to filesystem data lost after power failure, including the separate persistence of a newly created file's directory entry.
The relevant distinction is between unrecorded bytes that can be downloaded again and durable references to missing bytes. Trim-without-sync must be judged against the latter boundary, not against whether a file switch previously happened to sync. File contents, index references, and filesystem metadata are distinct durability concerns.
The stack's durability prerequisite explicitly requires syncing every block and undo file written since its last sync before recording their blocks in the index. It states that this is needed before later changes introduce multiple writers and remove sync-at-file-switch. A failed sync makes subsequent write-outs fail for that run.
The head flush still orders file synchronization before the synchronous index batch. This is the prerequisite that permits trimming a completed file without immediately syncing it. It also makes a sync between position reservation and completion insufficient: the eventual write must remain covered by a subsequent synchronization before its data reference is persisted.
Assumeutxo introduced separate block-file streams for historical validation and the active snapshot chainstate to prevent widely separated heights from becoming interleaved and impairing pruning.
Multiple blockfile cursors are intentional, not incidental bookkeeping. The maximum file number is therefore not the only possible active write position. Asynchronous deletion must account for a lower-numbered cursor as well as in-flight writes, while preserving the pruning benefit of height-separated files.
Ralph's inferences
In-progress duplicate suppression needs a weaker state than stored-data publication. A reservation can establish that another writer owns the work without establishing that readers can retrieve a complete block.
Head O2 explicitly separates 'being stored' from the atomic publication of BLOCK_HAVE_DATA, a usable position, and BLOCK_VALID_TRANSACTIONS after writing. Treating a second arrival as a duplicate prevents repeated storage work, but its immediate submitblock 'duplicate' response is not confirmation that the first write has finished, become durable, or ultimately succeeded. No inspected historical source establishes that immediate response as a prior requirement.
An accepted header's mutable chain-validity status must be reconsidered after off-lock work. Passing checks against an earlier context does not override an ancestor invalidation that occurs meanwhile.
The head propagates failure flags to existing descendants. Header acceptance distinguishes an already-known failed entry ('duplicate-invalid', BLOCK_CACHED_INVALID) from a new header whose parent is invalid ('bad-prevblk'). Peer handling gives those results different consequences: cached invalidity normally spares inbound peers, whereas invalid-parent results do not. These existing distinctions constrain both the recheck before claiming storage and the recheck before publishing transactions after writing.
Trimming allocation slack and establishing durable data are separate operations. Removing the file-switch sync shifts the durability boundary to index persistence; it does not remove that boundary.
A file can remain unsynced after its cursor leaves it, provided all relevant writes are synchronized before index references are committed. With off-lock writers, synchronization can occur before reserved bytes are actually written, so completion must restore the unsynced obligation. Head bookkeeping also defers trimming while writes remain in flight, separating final allocation cleanup from both write completion and durability.
Asynchronous pruning requires separate protection against deleting referenced bytes, deleting an in-flight writer's file, and reusing a filename awaiting deletion.
The inspected flush persists index changes before scheduling unlink. Head bookkeeping pins files with active writes and moves every cursor occupying a pruned file to an unclaimed number, rather than relying only on the maximum-numbered file being excluded. That prevents a delayed unlink from colliding with a fresh claim. Manual pruning remains synchronous so the request returns after removal; automatic pruning instead trades prompt space reclamation for less work under cs_main. The head explicitly notes that delayed reclamation can affect the subsequent low-disk-space check.