Provider refusals
judge: Provider declined the request because of a cybersecurity restriction. The final assessment is unavailable.
Review failed during the final assessment.
Earlier concerns neither republished nor resolved: 5 suggestions. See the Run archive for their assessments.
Background
Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.
Documented decisions
Keeping temporary reorganisation states behind cs_main was an explicit safety decision, not merely incidental locking. The 2017 activation change says internal data structures could be inconsistent if the lock were released after merely attempting a reorganisation; activation should retain the lock until it has made forward progress, except when stopping for hardware, disk-space, or similar system failures.
The base still implements this forward-progress loop. Its observable boundary is each completed cs_main hold, not necessarily completion of the entire ActivateBestChain call: activation deliberately releases the lock periodically for responsiveness and callback draining. Publishing every individual disconnect or connect would expose a different set of tip observations from those available to an outside cs_main reader.
Tip notifications must be enqueued in chain-update order. In issue #12978, developers reproduced UpdatedBlockTip notifications arriving in reverse order when P2P and RPC activation threads released cs_main before enqueueing. The observed consequence was a block-announcement failure; the resulting fix retained cs_main through notification enqueueing.
The base queues BlockConnected and UpdatedBlockTip before releasing the activation hold. Publication therefore has an ordering relationship with generating those events, but does not imply that background subscribers have already consumed them. A published frontier and a drained notification queue are distinct milestones.
Source 1 · Source 2 · Source 3
Moving wallet notifications to an ordered background queue traded synchronous coupling for explicit catch-up barriers. The historical explanation ties notification order to the wallet's use of mempool membership as a spendability proxy. The wallet synchronization helper was simplified to enqueue a callback and wait when the wallet was not already caught up.
Wallet RPCs are concrete consumers of a completed chain frontier plus ordered notification delivery. The pinned developer notes require wallet results to reflect at least the chain state a client could have observed before entering the RPC. The wallet and BaseIndex both retain catch-up mechanisms; a cheap tip observation cannot itself promise that wallet or index state is contemporaneous. Waiting also cannot retain a lock required by the callbacks: the base wallet helper excludes cs_wallet, and queue synchronization excludes cs_main.
Flush-error handling balances two goals: avoiding durable metadata that refers to non-durable block data, and preserving in-memory work when a filesystem failure may be transient. The older discussion questioned abandoning state-saving immediately. The later flush-error proposal explicitly skips index/coins writes in the failing call while permitting later retries, including shutdown flushes, and states that ConnectTip and DisconnectTip can fail after applying coins changes but before moving the chain tip.
This explains why a parent/child coins-best-block mismatch is a permitted failure state rather than evidence of a partially applied block. The base applies a complete block transition to CoinsTip, attempts the required disk flush, and only then changes m_chain. A failed connect can leave coins one child ahead; a failed disconnect can leave coins at the tip's parent. The head publication assertion accommodates those adjacent states instead of imposing unconditional equality during shutdown/error handling.
Source 1 · Source 2 · Source 3
Using a GETBLOCKTXN disk position after releasing cs_main is an existing optimization with an explicit retention premise. The 2024 change copied FlatFilePos under the lock, moved the disk read outside it, and added a static assertion that MAX_BLOCKTXN_DEPTH is no greater than MIN_BLOCKS_TO_KEEP. Its comment says a block passing that recent-height test cannot be pruned before the read.
The affected path already relied on recent-block retention rather than holding cs_main throughout disk access. BlockFacts changes the representation of the copied index information; it does not create the original unlocked-read contract. That contract is specific to sufficiently recent blocks and is not a general promise that every copied block-file position remains readable.
Ralph's inferences
The affected callers fall into different consistency classes. The selected RPC/interface height, hash, and time getters, and peer work/time heuristics, need copied tip facts. Wallet/index catch-up barriers, block validation, and callers combining the tip with coins, mempool, or chain ancestry need stronger synchronization. The historical boundary does not imply that a tip remains current after a read returns.
This is the distinction underlying the supplied call-site migration. The head constructs one snapshot from the current chainstate under cs_main, whereas existing wallet/index synchronization explicitly coordinates additional state. Preserving the observable frontier is separate from promising an atomic view across independently read subsystems.
Synchronous validation callbacks mark different processing stages from queued connection notifications. In the base, BlockChecked runs directly after ConnectBlock, before the overlay flush, required disk flush, and tip movement. Its net-processing subscriber handles peer punishment and compact-block announcer selection and explicitly notes that the tip has not yet been updated. NewPoWValidBlock directly performs fast compact-block announcement. ActiveTipChange is also invoked directly rather than queued.
A successful BlockChecked verdict is therefore not a publication or durability milestone: later write-out can still fail without moving the tip. Conversely, an outside reader preserving cs_main visibility must not overtake synchronous notifications performed before the hold ends. Queued callbacks require ordered submission, not completion before publication. The supplied patch's immediate-runner exception would also make nominally queued callbacks reentrant during submission, but that runner was not independently verified.
The GETBLOCKTXN height comparison is a serving-depth policy, not proof that the requested block belongs to the active chain. A separately observed completed tip height can change which response path is selected, but it does not itself pin the file. The existing fallback for older blocks sends a full block so a malicious peer must receive the data whose disk read it induced, limiting cheap disk-I/O amplification.
This separates the reasons for the depth cutoff from the lifetime of copied positions. The historical recent-block retention argument supports unlocked reads, while the depth policy limits adversarial resource asymmetry. The inspected evidence does not justify interpreting either as an unlimited guarantee across arbitrary concurrent reorgs or long delays between copying and reading.
Provisional findings
The final assessment failed. These findings passed source verification but have not received final adjudication. Severity and publication suitability remain provisional. The review remains failed.
1 minor finding · 9 suggestions
Findings
[minor] · GETBLOCKTXN depth check now uses a tip read after the hold that saw the data
Block availability and position are copied under cs_main, but the recent-block depth test reads PublishedTip() afterwards. If the block's file is pruned and the tip is rewound to within 10 blocks of it in between, the stale position passes the check and the unchanged assert(ret) aborts the node.
Location: src/net_processing.cpp:4610 (head).
Details and suggested fix
In the base, BLOCK_HAVE_DATA, the depth comparison against ActiveChain().Height() and GetBlockPos() were all read in one cs_main hold. A block passing that check was within 10 of the tip at a moment when its data was known to exist. That is the premise of the unlocked read and of assert(ret), as commit 613a45cd put it: the block 'cannot get pruned after we release cs_main above'.
At the head, LookupBlockFacts() runs under its own WITH_LOCK(cs_main, ...). The comparison then uses m_chainman.PublishedTip().height after that lock is released. The following sequence becomes possible on a pruning node:
- A peer requests a block at height h at least about 288 blocks below the tip. Its file is still present, so the copied facts have HaveData and a position.
- Before the height is read, pruning removes that file. Pruning is per file and keyed on the tip height at prune time (
GetPruneRange,nHeightLast > last_block_can_prune).PruneOneBlockFileclears HAVE_DATA and the position in the index, but not in the copied BlockFacts. - The tip is rewound to about h+10, for example by
invalidateblock. InvalidateBlock publishes after every disconnect, so the published height falls step by step. The rewind only needs data from files above the pruned one. The requested block can be on the active chain itself, since the rewind stops above it. PublishedTip().height - 10 <= h, soblock_posis set to the stale position.OpenBlockFilefails,ReadRawBlockIntoreturnsReadRawError::IO,ReadBlockreturns false, andassert(ret)aborts the node. Bitcoin Core keeps asserts enabled in release builds.
In the base, step 1 fails the depth test and takes the full-block fallback, which rechecks availability.
O11 in validation.h says a copied position 'stays readable afterwards, or the reader handles the failed read'. This caller does neither.
The split also saves no locking. cs_main is already held for the copy, and PublishedTip() takes cs_main again whenever a tip change is unpublished.
Fix: compute the depth decision inside the same WITH_LOCK that copies the facts, against ActiveChain().Height() or CurrentTipSnapshot().height, and copy data_pos only if the check passes. Keep the disk read outside the lock as before. The alternative is to handle a failed read instead of asserting.
The trigger needs pruning plus a deep tip decrease overlapping the handler. No production occurrence was identified, and the timing window is narrow.
Optional improvements
[suggestion] · Test an outside reader during an unpublished multi-block reorganisation
The tests never read PublishedTip() from another thread while a tip-changing hold is open, and never run a multi-block reorganisation. The API's central promise, that outside readers never see a tip a reorganisation passes through, is therefore not directly tested.
Location: src/test/tip_snapshot_tests.cpp:157 (head).
Details and suggested fix
published_tip_is_read_without_cs_main starts with BOOST_REQUIRE(!chainman.TipUnpublished()), so it covers only the fast path. Reads while the tip is unpublished happen only from InsideTheHold::ActiveTipChange and the explicit MarkTipChanged() block, both on the thread that already holds cs_main. The other cases connect or invalidate a single block.
Some regressions are already covered. Line 135 would catch the fallback returning the stale published value. Clang thread-safety analysis would likely flag a fallback that drops LOCK(cs_main), since CurrentTipSnapshot() is EXCLUSIVE_LOCKS_REQUIRED(::cs_main).
Other regressions would pass the current suite. Examples: publishing between the disconnect and connect steps of a reorganisation, or moving the publication ahead of the hold's signal queueing. These are exactly what the later PRs in the stack must preserve.
Suggested test: start a competing-chain reorganisation of several blocks and pause it inside the hold after a disconnect, with TipUnpublished() true. Start a PublishedTip() reader on another thread and check that it does not complete during the hold. Release the hold, then check that the reader returns the final frontier (hash, height, sequence) and not an intermediate tip. Release the paused writer before any failing assertion so the test cannot hang.
[suggestion] · Background-chainstate connects send published-tip readers back to cs_main
MarkTipChanged() is called for every chainstate's tip move, but only the current chainstate's tip is published. During assumeutxo background validation, every background ActivateBestChain hold therefore makes getblockcount, getbestblockhash, getNumBlocks, getHeight and the anti-DoS work threshold wait for cs_main, though the published value is unchanged.
Location: src/validation.cpp:3323 (head).
Details and suggested fix
Chainstate::ConnectTip() (validation.cpp:3323) and DisconnectTip() (3217) call m_chainman.MarkTipChanged() without checking which chainstate they run on. CurrentTipSnapshot() and PublishTip() describe only CurrentChainstate(). That function skips any chainstate with a TargetBlockHash(), which includes the historical chainstate validating a snapshot.
As a result, every background-validation hold sets m_tip_unpublished. Until that hold's TipPublisher runs, PublishedTip() takes cs_main and waits. The value finally published differs from the previous one only in its sequence number.
The PR's stated gain is that readers 'no longer wait behind a hold that does not move the tip'. That gain does not apply for the whole of background sync after loadtxoutset, which can be long. Correctness is unaffected; readers behave as in the base.
The cases where a background hold does change the published value already set the flag themselves. UpdateIBDStatus() sets it before latching (3548), and the invalid-snapshot path calls MarkTipChanged() (6378). Successful snapshot validation does not change CurrentChainstate().
Possible change: mark only when this == &m_chainman.CurrentChainstate(), or keep a separate counter for background moves. The sequence documentation ('counts the tip changes of every chainstate') would need adjusting, though no consumer outside the tests reads it. If the current behaviour is intended, say in tip_snapshot.h and the PR that background-validation holds still send readers to cs_main.
[suggestion] · O6 check in PublishTip() cannot catch the reordering it is meant to exclude
The Assume accepts the tip's parent or child as the coins' best block in every case. Those offsets are legitimate only after a failed write-out, so a future reordering that moves the tip before its coins are applied would still pass.
Location: src/validation.cpp:3582 (head).
Details and suggested fix
validation.h lists O6, 'The tip is the fully connected frontier: its coins are in the tip view', as asserted in PublishTip(). The check is Assume(best_index && (best_index == tip || best_index == tip->pprev || best_index->pprev == tip)).
On successful paths the coins' best block equals the tip when TipPublisher publishes:
DisconnectTip()flushes its view into CoinsTip and returns on a failedFlushStateToDiskbeforeMarkTipChanged()andSetTip().ConnectTip()flushes the view and callsFlushStateToDiskbeforeSetTip().
The neighbouring cases arise only after such a write-out fails, following earlier progress in the same hold. Suppose a later change moves SetTip(*pindexNew) before the block's coins are applied, which is the kind of reordering the stack (#43/#45) risks. The best block would then be the new tip's parent, and the Assume would still pass.
Suggestion: record the failed write-out state in ConnectTip/DisconnectTip, allow the neighbouring-block cases only when it is set, and otherwise require best_index == tip. The wider O8 check in FlushStateToDisk() can stay as it is, since both offsets are legitimate there.
[suggestion] · Loading-time publication happens before later tip moves and before notifications in the same hold
The TipSnapshot contract says loading publishes at a point after which the hold moves no tip. In fact LoadChainstate's single cs_main hold publishes from AddChainstate and from each LoadChainTip, then moves further tips, and LoadChainTip publishes before it sends blockTip.
Location: src/validation.cpp:4920 (head).
Details and suggested fix
node/tip_snapshot.h promises publication 'after ... the hold's signals are queued and its notifications sent'. It then excepts loading: 'Loading the chain and activating a snapshot publish before their hold ends, at a point after which it moves no tip.'
In LoadChainstate(), a single LOCK(cs_main) covers the following:
LoadAssumeutxoChainstate()→AddChainstate(), which callsPublishTip(). The new current chainstate has no tip yet at that point, so a no-tip value is published.CompleteChainstateInitialization(), which callsLoadChainTip()for every chainstate in turn. Each call does MarkTipChanged, SetTip and PublishTip.- In the snapshot-success case, a second initialization pass.
So tips move after earlier publications in the same hold. Within LoadChainTip(), PublishTip() (4920) also runs before the blockTip notification (4947).
After AddChainstate() publishes, m_tip_unpublished is false, so a fast-path reader during loading would get the interim value without waiting. In the base, such a reader blocked on cs_main.
Either document that loading-time publication can precede notifications and further tip initialisation in the enclosing hold, or defer these publications to the end of the outer loading scope.
[suggestion] · RunWorkerTask's 'both terminate' claim depends on an unchecked caller requirement the worker pool does not meet
The helper rethrows logic errors and bad_alloc and states that they terminate because callers run tasks in noexcept or top-level contexts. ThreadPool runs tasks inside std::packaged_task, which captures exceptions in the future instead.
Location: src/util/worker_task.h:37 (head).
Details and suggested fix
util::RunWorkerTask() (worker_task.h:43-47) catches std::runtime_error and nothing else. The comment says a logic error or failed allocation will 'terminate, because every caller runs the task where an exception that leaves it does (a noexcept function, or a thread with nothing above it)'.
The helper has no callers. The repository's worker pool does not meet that condition. ThreadPool::WorkerThread() runs a std::packaged_task<void()>, and Submit() wraps the callable in one and warns that exceptions are 'silently discarded' if the future is ignored. A std::logic_error escaping RunWorkerTask on a pool worker would be stored in the future: rethrown on the owner's thread by get(), or lost after wait(). It would not terminate.
The test comment at util_worker_task_tests.cpp:38 ('would terminate a worker thread') repeats the inaccurate claim.
Fix: enforce the contract in the helper, e.g. catch (...) { std::terminate(); } after the runtime_error handler. Alternatively, state the noexcept-wrapper requirement explicitly for pool tasks and correct the test comment.
[suggestion] · Truncated sentence at the end of the CValidationInterface threading comment
The new class comment ends with a dangling '(precondition O7 in validation.h, asserted by the sender). Several', so it is unclear what O7 refers to and whether text was lost.
Location: src/validationinterface.h:63 (head).
Details and suggested fix
The paragraph the PR adds on which thread each callback runs on ends at validationinterface.h:62-63 with '...or right after it is released (see there).' followed by '(precondition O7 in validation.h, asserted by the sender). Several'. The parenthetical is not attached to any sentence, and 'Several' begins a sentence that is never finished.
This comment is the reference for subscribers, including kernel users, and the PR names this ordering contract as one later PRs must keep. Attach the O7 reference to the sentence about queued callbacks (e.g. '...in the order the events were queued (precondition O7 in validation.h, asserted by the sender)') and remove or complete 'Several'.
[suggestion] · Split the wait-under-lock tooling out of the ordering-preconditions commit
Commit 65380388 bundles the O1-O15 documentation and Assume checks with an unrelated DEBUG_LOCKORDER mechanism that hooks EnterCritical. The two can be reviewed and bisected independently.
Location: src/sync.h:110 at 65380388ffcc (commit) (commit).
Details and suggested fix
Commit 65380388ffcc ('validation, sync: ordering preconditions, a check for waiting under a lock') contains two independent changes:
(a) The O1-O15 list in validation.h, the O-tags and Assume checks in validation.cpp and net_processing.cpp, and the callback threading documentation.
(b) The wait rule: declarations and macros in sync.h (NO_WAIT_LOCK, AssertMayWait, WaitedWorkScope/WAITED_FOR_UNDER_LOCK), the CheckWaitedWork hook in EnterCritical and the registry in sync.cpp, registrations in txmempool.cpp, wallet.cpp and the ChainstateManager constructor, AssertMayWait in SyncWithValidationInterfaceQueue/LimitValidationInterfaceQueue, the WAITED_FOR_UNDER_LOCK scope in coins.cpp, and the tests in sync_tests, mempool_tests and wallet_tests.
The sync.* changes reference no O-number, and the O-tags use only Assume/AssertLockHeld. The commit message describes the two in separate paragraphs.
A reviewer currently has to check the Assume conditions against flush-failure states and, at the same time, an EnterCritical hook that runs on every non-try lock in DEBUG_LOCKORDER builds. A bisect landing on this commit after a DEBUG_LOCKORDER abort cannot tell which half caused it.
The overlapping files (validationinterface.cpp, validation.cpp) change in separate hunks, so either order builds and the final tree is unchanged. RunWorkerTask is a third topic in the same commit (see commit_flow:2).
[suggestion] · Land util::RunWorkerTask with its first caller
Commit 65380388 adds RunWorkerTask and its tests with no caller. Its exception-boundary contract can only be judged together with the task runner that uses it.
Location: src/util/worker_task.h:41 at 65380388ffcc (commit) (commit).
Details and suggested fix
src/util/worker_task.h and util_worker_task_tests.cpp are added in commit 65380388, and nothing in the tree calls RunWorkerTask (the commit message says 'No task uses it yet'). The helper has nothing to do with the ordering preconditions or the wait rule it is bundled with.
Its key design choice is to catch only std::runtime_error and to rely on 'every caller' running it where escaping exceptions terminate. That choice depends on how callers submit tasks, and the repository's ThreadPool captures exceptions in a future. Without a caller in this PR, reviewers cannot check the claim.
Move the header and test into the stack PR that first calls it (#43 or #45 per the stack description), or at least into a separate commit with its own rationale. This removes code that is unused in this PR and does not affect the rest of the change.
[suggestion] · Move tip_snapshot_tests include fixes into the commit that adds the test
a9a85d9d adds InsideTheHold (a CValidationInterface subclass with std::vector members) without the matching includes. 65380388 adds only those two includes to the file.
Location: src/test/tip_snapshot_tests.cpp:13 at 65380388ffcc (commit) (commit).
Details and suggested fix
In commit a9a85d9d18b3, src/test/tip_snapshot_tests.cpp uses CValidationInterface and std::vector in InsideTheHold, but its includes (lines 5-17) omit <validationinterface.h> and <vector>. That commit compiles only through transitive includes.
Commit 65380388ffcc changes this file only to add #include <validationinterface.h> and #include <vector>, which is unrelated to that commit's subject. Fold the two lines into a9a85d9d, where the code that needs them is introduced.