3 minor findings · 6 suggestions
Findings
[minor] · Snapshot invalidation destroys views still used by staged connections
If background snapshot verification fails during a concurrent snapshot connection, destroying m_coins_views can turn the intended fatal shutdown into a use-after-free or crash; no occurrence was observed.
Location: src/validation.cpp:8599 (head).
Details and suggested fix
MaybeValidateSnapshot() marks the snapshot invalid and calls InvalidateCoinsDBOnDisk() before reporting the fatal error. That function settles an outstanding write-out run, but not staged connections. StageConnectTip() retains a raw BlockApplyView* owned by the destroyed views. Window workers dereference it without cs_main; even the serial path releases cs_main between validation and publication, which later dereferences the store and staged view again. Activation is serialized per chainstate, so another block-processing thread can activate the snapshot while the historical chainstate finishes verification. At base, the connection view and its reset guard stayed within one ConnectTip() lock hold. This concerns a snapshot that loaded successfully but later fails verification, indicating a software or hardware problem.
Mark the snapshot unusable immediately, but retain its views until its staged connections and workers have drained or been cancelled. Perform that drain without acquiring the affected activation mutex under cs_main, then destroy the views and rename the directory. A test holding a snapshot connection in flight during invalidation would cover the lifetime boundary.
[minor] · Write-out completion bypasses the compaction free-space guard
After IBD, a selected compaction following a write-out run bypasses the existing free-space reserve, allowing compaction on low local disk space where base would defer it.
Location: src/validation.cpp:2144 (head).
Details and suggested fix
StartWriteOutRun() checks space for the dirty coins it will write, but its completion calls CompactFullAsync() directly when ShouldCompactChainstate() selects compaction, approximately once in 320 calls outside IBD. Base and the head's synchronous flush instead exclude memory-only databases and check CheckDiskSpace(StoragePath(), AssumedChainStateSize() * 1_GiB), logging a deferral when that reserve is unavailable. Neither CompactFullAsync() nor CompactFull() performs a replacement check. A small write can therefore succeed and start a full compaction that consumes the remaining space and makes later chainstate writes fail, depending on the database layout. Route both completion paths through one helper retaining the memory-only exclusion, reserve check, and deferral warning.
[minor] · The kernel callback reentrancy ban excludes safe undo reads
During IBD, kernel block_connected callbacks can run on the effects executor, but the new blanket manager-call ban also forbids reading the connected block's already-written spent outputs.
Location: src/kernel/bitcoinkernel.h:504 (head).
Details and suggested fix
The effects executor's completion hook takes cs_main and applies notifications on its worker; the kernel's ImmediateTaskRunner invokes the user callback there. The hazardous case is a callback that reaches SettleUndoWrites() while later effects remain queued: WaitForIO() then waits for work that only the blocked executor can perform. Reading the notified block through btck_block_spent_outputs_read() does not have that problem, because its undo-write completion records the position before BlockConnected is delivered. Narrow the documented prohibition to operations that can wait on the executor, and explicitly permit reading the notified block's own spent outputs. This preserves a useful indexing operation without promising arbitrary reentrant block processing.
Optional improvements
[suggestion] · -par no longer limits window script verification
With default -prevoutfetchthreads, script-checked IBD window work ignores an explicit -par CPU limit, including the GUI setting that still promises to leave cores free.
Location: src/init.cpp:541 (head).
Details and suggested fix
-par configures the check queue, but RunConnectTask() calls ConnectBlock() with check_queue=nullptr, so window scripts execute on connect-pool workers. The default pool size comes from GetNumCores() independently of that setting. This can use more script-verification concurrency than a user selected with -par=1 or a negative value; blocks whose scripts are skipped by assumevalid do not exercise this concern. The command-line help acknowledges the exception, while the GUI still maps its core-reservation control only to par. Derive the default IBD script budget from an explicitly configured -par unless the user also overrides -prevoutfetchthreads. If the independent budget is intentional, update the GUI setting and tooltip to expose that distinction.
[suggestion] · Window tests do not force successful out-of-order continuation
The deterministic window tests never require a higher block to defer an input that a lower block later supplies, leaving continuation claiming and ordered publication dependent on timing-based coverage.
Location: src/test/validation_chainstate_tests.cpp:533 (head).
Details and suggested fix
WindowStepper::RunLowestBlock() executes tasks in staging order, and window_step_block_by_block expects zero deferrals. feature_connect_window.py compares final state but only reports the deferred count. The successful core test manually supplies the missing coin and calls FinishDeferredTransactions(), bypassing OnWindowBlockApplied()'s applied-prefix claim walk and continuation scheduling. Add controlled task selection or latches so that block N+1 spends an output of N and completes its first pass while N is held. Require the tip to remain below the held block, then release N and verify a nonzero deferral count, successful completion without serial retry, matching serial UTXOs, correct undo data, and height-ordered BlockConnected and UpdatedBlockTip. A controlled double-spend variant can also require serial retry and rejection.
[suggestion] · Kernel memory documentation omits pinned-block backpressure
The kernel header calls notification-pinned blocks byte-unbounded, although normal activation uses an estimated threshold of one eighth of the coins cache, at least 64 MiB, with reorganisation steps exempt.
Location: src/kernel/bitcoinkernel.h:1308 (head).
Details and suggested fix
btck_chainstate_manager_options_set_database_cache_bytes() says these blocks have “no limit in bytes”, while activation sets pinned_account's limit and waits when Admits() rejects further publication. Describe this estimated backpressure threshold and its reorganisation exception in the header, consistent with the implementation and reduce-memory.md. Do not present it as an exact allocation cap.
[suggestion] · Receive-path documentation describes code absent from this revision
O1, the -prevoutfetchthreads help, and reduce-memory.md describe asynchronous peer receive tasks and a PeerManagerImpl::WaitForPendingBlocks() that are not implemented at this head.
Location: src/validation.h:545 (head).
Details and suggested fix
PeerManagerImpl::ProcessBlock() still calls ProcessNewBlock() directly, using activate_async=false, so activation remains synchronous on the message handler. Only the ChainstateManager wait API exists, with test callers. The documentation nevertheless attributes ordering waits to peer-message handlers and describes received blocks waiting in memory for pool workers, including a one-worker special case. This misstates both the ordering preconditions and the option's resource effects. Describe window validation and tip prefetch here, and move the peer receive-task wording and wait reference into #46 alongside their implementation.
[suggestion] · IBD announcement tests do not ensure a block signal is pending
Both new transaction-ordering tests can pass without the admission-side settle because the effects executor may deliver BlockConnected before transaction submission begins.
Location: src/test/tip_snapshot_tests.cpp:225 (head).
Details and suggested fix
a_transaction_is_announced_after_the_block_in_ibd and its loaded-transaction variant connect a block, submit or load a transaction, and check {'b', 't'}. Nothing holds the block's completion back, and the executor can apply it as soon as it obtains cs_main. The loaded variant acknowledges this and relies on three repetitions. Add a controlled pending-signal fixture: hold an effect ahead of BlockConnected, coordinate the admission attempt on another thread, then release the effect and require exactly {'b', 't'}. Ensure no earlier periodic flush drains the held queue before admission. This should distinguish removal of SettleBlockSignalsBeforeTx() rather than rely on worker timing.
[suggestion] · User-visible validation changes lack release notes
The changed IBD CPU defaults, extra block-cache memory, coins_db_cache_bytes semantics, and kernel callback ordering are documented in help or headers but have no release-note entry.
Location: src/init.cpp:544 (head).
Details and suggested fix
The previous release notes describe -prevoutfetchthreads as eight prefetch workers, at most sixteen. This PR changes its default, maximum, and role, and makes -par independent of window script verification. It also adds -blockcache memory beyond -dbcache, changes coins_db_cache_bytes to an assigned share rather than the database's current cache size, and permits kernel block_connected to follow block_tip during IBD. Add a release-note fragment covering these migration-relevant changes, or explicitly identify where the stack's combined notes will land.