utxo split/3 tip facts

willcl-ark/bitcoin: PR #42

7 suggestions

Optional improvements

Link

[suggestion] · The GETBLOCKTXN depth check no longer shares the block facts' snapshot

Separate block-fact and tip-height reads can select a pruned position and reach assert(ret) during tightly timed pruning and rollback RPCs; no realistic production occurrence was identified, and the base already had a different theoretical pruning window.

Location: src/net_processing.cpp:4610 (head).

Details and suggested fix

LookupBlockFacts() releases cs_main before PublishedTip().height is sampled. On a pruning-enabled node, copy a non-cached block's position at height h while the tip is at least h + 288, let pruneblockchain remove an eligible file ending at h, then let invalidateblock lower the tip to h + 10 before the height read. The stale position passes the depth check, and the failed disk read reaches assert(ret). A peer can supply the request but cannot drive those RPCs. The base rejects this block from the blocktxn path before releasing the lock, although it retains a theoretical post-check pruning window if the chain advances hundreds of blocks.

Read ActiveChain().Height() in the same cs_main hold as the block facts. The lookup already takes that lock, so this restores the previous consistency argument without another acquisition.


Link

[suggestion] · RunWorkerTask() does not enforce its documented termination policy

With no production callers yet, RunWorkerTask() has a contract mismatch: ThreadPool captures wider exceptions in futures rather than terminating, and wait() alone never rethrows them.

Location: src/util/worker_task.h:37 (head).

Details and suggested fix

RunWorkerTask() catches std::runtime_error but lets other task exceptions escape, despite documenting that logic errors and failed allocations terminate. ThreadPool::Submit() wraps callables in std::packaged_task, which stores those exceptions in the returned future. The existing prefetch owner, CoinsViewOverlay::StopFetching(), illustrates the hazard by calling only wait() before discarding its futures. To enforce the stated policy for non-std::runtime_error task failures, add catch (...) { std::terminate(); } after the runtime-error handler and test that boundary through ThreadPool. The current direct-call test checks propagation, not termination.


Link

[suggestion] · PublishTip() accepts a tip ahead of its coins without a failed write-out

The new diagnostic accepts best_index == tip->pprev unconditionally, so it cannot distinguish a normal-operation O6 violation from the intended failed-write-out exception; no current violation was found.

Location: src/validation.cpp:3580 (head).

Details and suggested fix

On successful ConnectTip() and DisconnectTip() paths, the coins view is flushed and FlushStateToDisk() succeeds before SetTip(), so publication should require best_index == tip. The parent/child alternatives accommodate write-out failure, but the unconditional disjunction also accepts publication before a block's coins are applied. Record the failed write-out state and allow the adjacent-block alternatives only for that state, requiring equality otherwise. Keep the broader O8 check during FlushStateToDisk(), where those offsets are legitimate intermediate states.


Link

[suggestion] · The O7 assertion documentation is unfinished

The documentation leaves O7's partial enforcement locations unspecified and detaches its reference from the callback queue-order guarantee.

Location: src/validation.h:539 (head).

Details and suggested fix

validation.h stops O7 at “the block is stored and is the tip, or has left the chain, is checked” without naming where. The CValidationInterface comment in validationinterface.h ends with “(precondition O7 in validation.h, asserted by the sender). Several” after discussing synchronous callbacks. Complete O7 by naming the ConnectTip()/DisconnectTip() state checks and the senders' cs_main assertions, and clarify that those checks do not themselves assert queue order. Attach the O7 reference to the queue-order sentence and finish or remove the trailing fragment.


Link

[suggestion] · The mempool wait-rule registration lacks integration coverage

The DEBUG_LOCKORDER tests cover a synthetic mutex and cs_wallet, but not the mempool's registration; its diagnostic also identifies the lock only as cs.

Location: src/txmempool.cpp:180 (head).

Details and suggested fix

wait_under_a_no_wait_lock_detected registers its own test mutex, so it still passes if CTxMemPool stops registering cs. The wallet refusal test exercises a different registration. Add a DEBUG_LOCKORDER case that holds m_node.mempool->cs and expects SyncWithValidationInterfaceQueue() to throw before waiting, mirroring the wallet test's temporary handling of g_debug_lockorder_abort. Register the mempool lock with RegisterNoWaitLock("CTxMemPool::cs", &cs) so the case can also verify an identifiable diagnostic rather than the stringified cs.


Link

[suggestion] · The tip snapshot tests do not exercise independent readers

The new PublishedTip() tests would still pass if every read took cs_main, and they never exercise an outside reader during a multi-block reorganisation.

Location: src/test/tip_snapshot_tests.cpp:119 (head).

Details and suggested fix

CheckMatchesChain() takes cs_main before reading, and InsideTheHold::ActiveTipChange() runs synchronously on the writer's thread, where the mutex is recursive. The remaining reads are sequential; the chain test connects and invalidates only one additional block. Add coordinated reader/writer cases using promises or latches with bounded waits: require a reader to finish while another thread holds cs_main without changing the tip, then pause a multi-block reorganisation at an intermediate tip and require an outside reader to wait for final publication and return the final tip. Retain the same-thread callback case for recursive-lock behavior.


Link

[suggestion] · O10 describes receipt order instead of nSequenceId linking order

nSequenceId orders equal-work candidates by when they become linked, not necessarily by receipt, so the new O10 wording misstates the existing ordering contract.

Location: src/validation.h:548 (head).

Details and suggested fix

When a block's parent lacks chain transaction counts, ReceivedBlockTransactions() puts it in m_blocks_unlinked without assigning a fresh sequence ID. Once an ancestor arrives, the breadth-first queue assigns IDs to it and waiting descendants as it links them. CBlockIndexWorkComparator uses those IDs for the equal-work tiebreak. Reword O10 and the assignment-site tag to specify numbering under cs_main when blocks become fully linked, with waiting descendants numbered in queue-linking order. Assigning at receipt instead would change candidate preference; no production code change is needed.


Coverage details