Skip to content

backport: bitcoin#29215, #29370, #29720, #29726, #30053, #30267, #29996, #30320, #29519, #30636, #30807, #30962, #30909, #34286, #34728, #34852 - #8079

Draft
PastaPastaPasta wants to merge 77 commits into
dashpay:developfrom
PastaPastaPasta:feat/assumeutxo-hardening
Draft

PastaPastaPasta wants to merge 77 commits into
dashpay:developfrom
PastaPastaPasta:feat/assumeutxo-hardening

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

The snapshot loader in #8078 (bitcoin#27596 and its follow-ups) works, but it carries three kinds of debt that upstream fixed after bitcoin#27596 and that Dash has not taken yet:

Update (2026-11-09). Rebased onto develop 6271b740e99d, after #8071, #8073 and #8067 merged. #8067's two commits dropped out of the stack as already upstream (same patch-ids). bitcoin#28218 (in #8071) moves IsInitialBlockDownload to the ChainstateManager; the stack now calls m_chainman.IsInitialBlockDownload(), as upstream's AssumeUTXO code does, and every changed caller previously asked the active chainstate, so behaviour is unchanged. At the new heads, every commit builds (gcc-11 --enable-werror), the targeted unit suites pass at each layer tip, and fork CI passed on the rebased head before the W11 fixes (run 42681492785).

W11 review (2026-11-09). An independent validation review found the Dash fixes correct and raised small items, now applied: the wizard clears its state-unavailable label itself when masternode state is readable again (a zero-candidate test row fails without it); a mempool load stopped by the guard is not counted as tried, so the shutdown dump keeps mempool.dat; the guard test asserts the guard's log line; test-only clean-ups in the end-to-end and retry tests. Fork CI passed on the new head 2b55ab304120 (run 42717799078), including the ASan, TSan and multiprocess jobs.

Update (2026-11-10). Adds bitcoin#30636 (test-only) in upstream merge order, after bitcoin#29519; the commits above it are unchanged apart from one context line in the bitcoin#30807 test hunk. A check of the older fork PRs this stack supersedes found no Dash fix that the stack lost; their upstream test PRs are now each ported or listed below with a reason. All 44 PR checks passed on the new head cc9c8e781113. Fork CI (run 42750009710) passed too, including the ASan, TSan and multiprocess jobs, except for one unit test in linux64_nowallet-build: test_mempool_protx_key_changed_conflict_chain_legacy, a test from develop whose setup check fails at random about once in 1,001 runs. The same job passed in the PR checks on this head.

Update (2026-11-10, rebase). Rebased onto develop 041e450769b, after #8070, #8081 and #8083 merged, with #8069's rebased commits underneath. #8070 made four changes the stack had to follow:

  • It split llmq/options.h into llmq/utils.h and llmq/options_args.h. The stack's includes switch to match.
  • It moved Params() to m_chainman.GetParams() in llmq/quorumsman.cpp. The stack keeps the chainman lookup on the lines it moves.
  • It gave the CGovernanceManager constructor a data-directory argument. Two new test constructions pass it.
  • It removed node/interface_ui.h from validation.cpp (kernel: Remove util/system from kernel library, interface_ui from validation. bitcoin/bitcoin#27636). Because of this, the Evo-state warning now reaches the GUI through a new kernel::Notifications::evoStateWarningChanged() hook. Its node override calls uiInterface.NotifyAlertChanged(), as the direct call did before; -alertnotify is still not run for this warning. From feat: emit, pin, seed and verify the v4 evo snapshot section #7601 on, validation raises it only when the warning text changes. Two existing test scenarios now count these alerts.

The commit count is unchanged. Every changed commit builds, the targeted unit suites pass at the #7887, #7601 and #8079 tips, and the kernel library still links on its own. All PR checks passed on the pushed head 82ec5b8225d7, and fork CI passed on it too (run 42865398622), including the ASan, TSan and multiprocess jobs.

Update (2026-11-10, second rebase). Rebased onto develop 9c981d925b4, after #7939, #7815, #7678, #8085, #8088 and #8092 merged, with #8069's rebased commits underneath. Every commit replays without a conflict. One test needed a change: #8085 adds a unit test that sends QFCOMMITMENT messages from the test body, so the commit that turns -checkevobinding on in the unit-test fixtures now opens an active-chain view for it, as it already did for that file's other tests. At the #8079 tip the build and every unit suite pass. So do the AssumeUTXO functional tests, feature_loadblock and feature_remove_pruned_files_on_startup, both with default settings and with -blockcompression=3 (#7939 leaves compression off by default), and feature_pruning and rpc_rawtransaction. All PR checks passed on the pushed head bca9621846a9, including the ASan, TSan and multiprocess jobs.

Update (2026-11-11, third rebase). Rebased onto develop b4b4d852e34, after #8082 and #8084 merged. The only conflict was in src/init.cpp: develop's bitcoin#26296 backport drops the /* Continued */ log markers, including one in the startup repair block that #7887 moves into FinishImportedStartup(). The block stays moved and loses the marker. The one marker the stack added itself, on the refusal to activate a snapshot while an earlier rejected one is still on disk (#8078), is gone too, and every log call the stack adds ends its format with a newline, as the new clang-tidy check requires. #7887's GETDATA changes merge onto bitcoin#27675's rewrite of that path unchanged. The commit count is unchanged. At the #8079 tip the build and every unit suite pass, and so do the AssumeUTXO functional tests, feature_loadblock, feature_remove_pruned_files_on_startup, feature_pruning, rpc_rawtransaction, mempool_reorg, mempool_limit, and the P2P tests on the paths bitcoin#27675 changed (p2p_getdata, p2p_tx_download, p2p_invalid_tx and p2p_filter).

Update (2026-11-11, fourth rebase). Rebased onto develop b2172a9cf8a, after #7623, #8076, #7975, #7835 and #8052 merged. It also takes #8049's new revision (e392e45): a DKG phase thread now checks for a stop request first, and while background validation is incomplete it waits only at round start. The commit count is unchanged. #8052 applied without conflicts; two develop changes needed adapting:

Update (2026-11-11, fifth rebase). Takes #8049's newer revision (5aa5ad6), which changes only its unit test: instead of a 200 ms timeout, the test now waits for the DKG handler's "waiting for snapshot background validation" log line. Apart from context lines next to that test, the stack's own commits are unchanged.

All PR checks passed on the pushed head 69f6610a3179, including the ASan, TSan and multiprocess jobs.

At the #8079 tip the build, every unit suite and test_dash-qt pass, and so do the AssumeUTXO functional tests and p2p_platform_ban. One develop merge earlier, on the same patches, feature_llmq_rotation and feature_llmq_signing (with and without --spork21) passed. Before #8049's new revision was taken, the functional tests listed for the third rebase passed too, along with wallet_assumeutxo, wallet_backup, wallet_basic and wallet_importdescriptors.

Update (2026-11-11, sixth rebase). Rebased onto develop 7d85e330840, after #8095, #8105, #8080, #8097 and #8094 merged. It also takes #8049's newer revision (ec71e73), which again changes only its unit test and a header comment: the in-round check now runs the wait on another thread from Idle, so only the snapshot check can end it. Every commit replays without a conflict. #8095 changes how the miner picks its best ChainLock, in the same function where this stack reads the previous block's coinbase ChainLock (#7593). The two changes are independent, and the stack's commit applies unchanged. At the #8079 tip the build and five runs of validation_chainstatemanager_tests pass. So do the AssumeUTXO functional tests, wallet_assumeutxo, feature_llmq_chainlocks and feature_governance.

Update (2026-11-11, seventh rebase). Rebased onto develop ce9ef663c9e, after #8104 merged. #8104 takes a block's final commitments out of the mineable pool only once the block has been accepted, instead of in ProcessCommitment(). Three commits needed adapting. In ProcessCommitment() this stack keeps its per-view mined-commitment cache and drops the pool removal, as #8104 does (#7887). In RollforwardBlock() the removal runs after this stack's snapshot-input capture, which can still fail, so a block that fails there keeps its commitments in the pool (#7601). The third change is a reflowed declaration. As before #8104, the removal runs for blocks that either chainstate connects, and it reads no Evo state. A block that stalls on missing snapshot data now also keeps its commitments in the pool. Each adapted commit compiles on its own. At the #8079 tip the build passes, and so do llmq_blockprocessor_tests, validation_chainstatemanager_tests, validation_chainstate_tests, feature_llmq_dkgerrors, feature_llmq_rotation, the AssumeUTXO functional tests and wallet_assumeutxo.

Update (2026-11-11, eighth rebase). Rebased onto develop 95cfb5b8f2a, after #8110 merged. #8110 replaces functional casts in Dash code with static_cast. One commit needed adapting: the commit that makes work modifiers exact (#7593) deletes the block-based GetNonNullCoinbaseChainlock() overload, in which #8110 had changed a cast, so the deletion stands. Every other commit applies unchanged, and a source check found no new C-style or functional casts in the stack's Dash files. At the #8079 tip the build passes, including dash-qt, and so do quorum_proofs_tests, llmq_commitment_tests, evo_cbtx_tests, coinjoin_tests, evo_snapshot_tests, test_dash-qt, feature_llmq_chainlocks, feature_llmq_rotation, the AssumeUTXO functional tests and wallet_assumeutxo.

All PR checks passed on the pushed head 47f0f13051fd, including the ASan, TSan and multiprocess jobs.

Update (2026-11-12, ninth rebase). Rebased onto develop c68d3cd81fc, after #8116, #8100, #8112, #8119, #8114, #8120, #8121 and #8127 merged. One commit needed adapting: #8100 adds a governance reorg unit test, and this stack's commit that rejects unbound Evo reads (#7887) now opens an active-chain turn at the start of that test, as it does for the file's other tests that call into the node. Without it the test fails with EvoViewBindingError under -checkevobinding. Every other commit applies unchanged. #8121's ChainLock check in CreateNewBlock() and getblocktemplate runs before any Evo read, and #8119's PeriodicStats() runs inside the stack's scheduler binding. At the #8079 tip the build passes, including dash-qt, and so do governance_vote_processing_tests, llmq_chainlock_tests, spork_tests, coinjoin_inouts_tests, validation_chainstatemanager_tests, test_dash-qt, feature_governance, feature_llmq_chainlocks, feature_stats, interface_bitcoin_cli, mining_basic, the AssumeUTXO functional tests and wallet_assumeutxo. #8099, which merged after this rebase, touches no file in this stack, and a trial merge passes interface_rest and rpc_deprecated.

All PR checks passed on the pushed head 178b55606bfd, including the ASan, TSan and multiprocess jobs. linux64_asan-build needed one rerun: its first run failed the develop unit test test_mempool_protx_key_changed_conflict_chain_basic at parent_sorts_first. That test fails about once in 1,001 runs on develop too, because its 1000-try grind for a child txid that sorts after a random parent txid can come up empty.

Update (2026-11-13, tenth rebase). Rebased onto develop 5c34dcfbf79, after #8099, #8135, #8130 and #8131 merged, and onto the reworked #8066 (db5aac0) and #8069 (b8e3318); #8049 is unchanged.

  • feat(interfaces): look up a Platform quorum at its signed Core height #8069 is now one commit. It reads the Platform window with the throwing mined-commitment walkers, and no longer adds the non-throwing ScanMinedCommitments* scans, CDBIterator::HasError or the table-corruption test helper.
    • feat: isolate Evo state per chainstate while an AssumeUTXO snapshot is active #7887 now carries CDBIterator::HasError in a new commit (feat(dbwrapper): report LevelDB iterator read errors), because its generation walkers need it. The corruption helper moved into evo_db_tests.cpp, its only user.
    • The stack's edits to the removed scans were dropped, along with the one test that covered only them (scan_mined_commitments_reports_missing_history). The scan-coverage proofs (TraverseScanSequences and its tests) are unchanged.
  • Behaviour change. In a snapshot view, getPlatformQuorum now returns UNAVAILABLE instead of FOUND for a quorum in the readable part of a window that reaches history the view lacks.
    • Each such lookup raises the "Snapshot state unavailable" warning until the next lookup succeeds.
    • Nothing becomes INVALID, and the change lasts only until the snapshot is validated and promoted.
    • Two interfaces_tests rows changed to match.
  • fix: keep a background chainstate's BLS scheme off other threads #8066 no longer captures the BLS scheme in CBLSBatchVerifier or CBLSWorker. No stack path runs either inside a scheme override or for the background chainstate.
  • Checks:
    • The tip builds with no warnings.
    • These pass: 15 targeted unit suites, test_dash-qt, and the AssumeUTXO, governance, ChainLock, stats, CLI and mining functional tests.
    • The HasError commit and its first caller compile at their own positions, and a HasError-always-false mutant fails evo_db_tests.

All PR checks passed on the pushed head a9f00137eabf, including the ASan, TSan and multiprocess jobs.

Update (2026-11-13, eleventh rebase). Rebased onto develop 01023ded78b, after #8141, #8108, #8111, #8113, #8115, #8117, #8118, #8122 and #8069 merged. #8069 merged at b8e3318, the revision this stack already carried, so its commit leaves the bottom of the stack and nothing above it changes; #8049 and #8066 are unchanged. Every commit replays without a conflict. #8113 added a CoinJoin unit test, coinjoin_maintenance_runs_for_every_wallet, that calls DoMaintenance directly rather than through the scheduler, so it tripped -checkevobinding. "feat(evo): reject unbound Evo reads during dual operation" now binds the active Evo view in that test, as it already does in the other tests that drive the node the way a dispatcher does; in the node, CoinJoin maintenance already runs inside the scheduler's binding. Apart from those two test lines, git range-diff shows all 66 stack commits and the four #8049 and #8066 commits identical. At the tip the build has no warnings, every unit test suite passes, and so do the AssumeUTXO, ChainLock, CLI, mining, CoinJoin RPC, address-index, rpc_blockchain and rpc_masternode functional tests.

All PR checks passed on the pushed head 215ef4bcde2f, including the ASan, TSan and multiprocess jobs.

Update (2026-11-14, twelfth rebase). #8145 replaces #8066. Instead of a per-thread override of the process-wide BLS scheme flag, it removes the flag and takes every scheme from the data or the block. The stack now sits on #8145 (537d8a7, on develop d2fb5e7) and #8049. #8078 is the first layer that can run a snapshot chainstate next to a background one, so it needs one of the two fixes; the layers below it were written against the flag. Seventeen of the 66 stack commits changed. Four differ only in context, one of them the fuzz RPC lists in the bitcoin#27596 merge, which keep loadtxoutset and getchainstates beside develop's new entries. One keeps both sides of a regtest checkpoint conflict. The other twelve drop what existed only for the flag: the scheme guards in ConnectTip and DisconnectTip, the scheme restore before an evo::LocalStateError is rethrown, and the scheme override in ForceSignalDBUpdate. They also take #8145's scheme-free signatures for CbTx decoding, GetNonNullCoinbaseChainlock, VerifyEvoSnapshotBaseBlock and the work-block modifier, whose hash now uses #8145's expression. Two tests changed: the mid-connect rejection test, still run with v19 activating above the snapshot base, now checks that the background chainstate takes over instead of checking the flag, and the work-modifier test now covers the mined signature, because a pre-v19 legacy coinbase ChainLock cannot exist (it needs v20). The commit that turns -checkevobinding on in the unit-test fixtures also binds three tests that #8145 adds and the CoinJoin queue test that develop gained in #7955, and one commit's edit to a test #8145 deletes is gone. No commit was dropped. Every layer tip builds with no warnings and passes #8145's lint-bls-scheme.py. Every unit suite passes at the #7887 and #8079 tips. At the #8079 tip test_dash-qt passes, and so do the AssumeUTXO, ChainLock, asset-lock, EHF, ProTx-version, quorum-RPC and rpc_dumptxoutset functional tests and the functional tests develop changed since the last rebase, apart from the ZMQ test, which needs a ZMQ build.

All PR checks passed on the pushed head 89eff4f3b9ed, including the ASan, TSan and multiprocess jobs.

  • Faked counts. Activation fakes nTx and nChainTx for every block below the base and marks them BLOCK_ASSUMED_VALID. feat: load AssumeUTXO snapshots with loadtxoutset and validate them in the background (regtest only) #8078 has to carry two exceptions in CheckBlockIndex and a BlockManager::m_faked_tx_height to keep its checks from aborting on those values. assumeutxo: Get rid of faked nTx and nChainTx values bitcoin/bitcoin#29370 removes the faking, which is the root fix.
  • Loader and download bugs. loadtxoutset accepts a base that is not in the best header chain, and it reports no reason when it refuses. Historical block download starts from the wrong block when the snapshot chain diverges from the node's chain, and can run before the snapshot chain. AssumeUTXO nodes disconnect peers during IBD. The background chainstate raises fork warnings. getchaintxstats returns wrong numbers while counts are unset. The wallet RPCs assume m_chain_tx_count, and -reindex before validation was untested.
  • Test flakes and missing coverage in feature_assumeutxo.py and wallet_assumeutxo.py.

Taking the root fix also exposed a gap that upstream has too. A snapshot chainstate raises the blocks it connects above its base to CHAIN and SCRIPTS validity. If the snapshot is then dropped before background validation reached the base (-reindex-chainstate, or a restart after a rejection), those blocks keep a validity claim that no validated ancestor backs. With BLOCK_ASSUMED_VALID gone, CheckBlockIndex rejects that state, and in the same run a rejection raised while the snapshot chainstate connects a block can reach FindMostWorkChain's release assert. bitcoin/master has the same gap after -reindex-chainstate and no upstream fix. It is repaired here, in two places.

Stack position. This is the fifth layer. It depends on #8078 (L4a), #7601, #7593, #7887, and below those #8145 and #8049; none of them has merged (#8067 and #8069 have). Against develop the PR shows 77 commits; only the top 18 belong to this PR. It stays a draft until the layers below it merge. L4a and this PR are meant to merge together.

Two decisions a reviewer should check:

What was done?

18 commits: 16 upstream merges and 2 Dash commits. Each commit message lists the upstream commits, the Dash adaptations and the omitted hunks.

Upstream test-only PRs not ported (not required for correctness): bitcoin#29478 (needs bitcoin#29345), bitcoin#30817 and bitcoin#30892 (need bitcoin#29553), bitcoin#34377 (renames a wallet in a pruned-node row that does not exist here). bitcoin#29617 and bitcoin#31907: the two loader guards they cover, a coin above the base height and an amount outside MoneyRange, run before the content-hash check, which rejects the same files. Upstream's rows overwrite fixed offsets of a deterministic first coin, and this file's first coin varies between runs, so they need an adapted port (a splice for the height row and bitcoin#31907's helpers for the amount); deferred to a test follow-up before production enablement. bitcoin#30880 is folded into the bitcoin#30807 commit. bitcoin#30403's tip-at-base row needs bitcoin#29428's helper (the refusal is covered by the unit case chainstatemanager_evo_snapshot_needs_more_work_than_the_active_chain). bitcoin#32033's cleanup is checked through the snapshot directory in feature_assumeutxo_refusals.py (its log-line assertion is not ported). bitcoin#30455 needs a pruned snapshot node, which Dash refuses. bitcoin#32746 removes a workaround from bitcoin#29553, which is deferred, and depends on bitcoin#30666, which is absent. bitcoin#30214, bitcoin#29553 and bitcoin#30598 are deferred; no code in this stack depends on them.

How Has This Been Tested?

Environment: gcc-11 --enable-werror release configuration with Qt, sqlite and no BDB, and clang-19 with -Wthread-safety -Werror, in containers on Linux x86_64; functional tests with dash_hash. Head: dc81f37b7c0b.

Review and fork CI:

Not run locally: --extended functional tests, the sanitizer builds (TSan for the atomic nLocalServices and snapshot_download_completed path, ASan/UBSan for getchaintxstats), test_dash-qt and per-commit unit suites for the commits that did not change. The fork CI runs above cover the extended functional tests and the ASan and TSan jobs. The code-review-validator and code-simplifier passes ran as the W11 review above.

Run locally at this head:

Fail-without-fix. Each mutant ran in its own copy with only the stated source change, next to an unmutated control that passed:

The three rows that exercise a dropped snapshot (node 3 in feature_assumeutxo.py, node X's -reindex-chainstate row in feature_assumeutxo_dash.py, and the unit case above) aborted in CheckBlockIndex on the plain bitcoin#29370 port. They are left unchanged by the repair and are its tests.

Breaking Changes

None for any network except regtest, where the loader is the only way to get a snapshot chainstate. getchaintxstats fields txcount, window_tx_count and txrate can now be absent while counts are unset, as upstream.

Known limitations, not fixed here:

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

@thepastaclaw

thepastaclaw commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

🕓 Review not started yet because this PR is a draft.

  • Request normal review — click when the PR is ready for review.
  • Request priority review — click to move this review to the front of the queue.

Commit 89eff4f. Normal review starts when eligible; priority review starts as soon as a slot is available.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

This pull request has conflicts, please rebase.

@PastaPastaPasta
PastaPastaPasta force-pushed the feat/assumeutxo-hardening branch from dc81f37 to 91294b1 Compare November 9, 2026 19:14
@PastaPastaPasta
PastaPastaPasta force-pushed the feat/assumeutxo-hardening branch 2 times, most recently from 2b55ab3 to cc9c8e7 Compare November 10, 2026 03:31
@PastaPastaPasta PastaPastaPasta changed the title backport: bitcoin#29215, #29370, #29720, #29726, #30053, #30267, #29996, #30320, #29519, #30807, #30962, #30909, #34286, #34728, #34852 backport: bitcoin#29215, #29370, #29720, #29726, #30053, #30267, #29996, #30320, #29519, #30636, #30807, #30962, #30909, #34286, #34728, #34852 Nov 10, 2026
@github-actions

Copy link
Copy Markdown

This pull request has conflicts, please rebase.

@github-actions

Copy link
Copy Markdown

This pull request has conflicts, please rebase.

@github-actions

Copy link
Copy Markdown

This pull request has conflicts, please rebase.

PastaPastaPasta and others added 27 commits November 14, 2026 08:39
Two activations could run at once: the snapshot chainstate is only installed
at the end, so the check for an existing one let a second loadtxoutset through.
The second one failed, at the latest on the first one's database lock, and its
cleanup then rebalanced the caches, deleted the snapshot directory and
abandoned the generation of the activation still running.

ActivateSnapshot now refuses, before it changes anything, while another
activation is running.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Promotion renames the background chainstate directory to chainstate_todelete
and deletes it at the end. When that deletion failed, or the node stopped
before it, the directory stays; the next startup removes it, unless it
reindexes. A snapshot loaded after such a reindex then failed its promotion
on the rename, and startup aborted until the user removed the directory.

The leftover is of no use, so promotion removes it durably before the rename.
A failure to remove it aborts the node with its own message, as a failed
rename does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n a snapshot is rejected

The rejection makes the background chainstate active, but its candidates
held only ancestors of the base. Blocks the snapshot chain had connected
above the base were missing, so the next CheckBlockIndex aborted (with
-checkblockindex, the regtest default).

Re-list them with RestoreBlockIndexCandidates, the rule startup applies.

Inherited from bitcoin#25740; bitcoin/master still has it, so there is no
upstream fix to backport.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…check in ActivateSnapshot

33c48c1 validation: Check if mempool exists before asserting in ActivateSnapshot (TheCharlatan)

Pull request description:

  The mempool is an optional component of the chainstate manager, so don't assume its presence and instead check if it is there first.

Dash: pulled forward from the later assumeutxo backports. After a
snapshot rejection the active chainstate has no mempool (next commit),
so a second activation in the same run must reach the "a snapshot
chainstate already exists" refusal instead of this assert.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A rejected snapshot handed its mempool to the validated chainstate. The
mempool's transactions were accepted against the snapshot tip, so with
-checkmempool (the regtest default) the check that follows completion
aborted on a child of a transaction mined above the base, instead of
the node stopping with its error. After a rejection raised while the
snapshot chainstate connects a block, the validated chainstate can be
far below the base, and it met that mempool with historical blocks.

Leaving the mempool with the rejected chainstate is not enough: a
rejection raised mid-step returns through that chainstate's mempool
update after its coins views were reset.

Detach the mempool from both chainstates for the rest of the run.
Transactions are refused with no-mempool. Nothing is removed, so no
InstantSend lock is dropped through the removal notification, and
DumpMempool still saves the mempool for the next startup to
re-validate.

This drops the handback from "validation: move the mempool to the
snapshot chainstate on activation" (dashpay#7553); develop cannot reach it
without the snapshot loader.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…onger holds the mempool

A snapshot rejection detaches the mempool from both chainstates, and a
snapshot activation moves it from the background chainstate to the
snapshot one. A mempool load (importmempool, or the load at startup)
that started on the other chainstate, or after the rejection, then
reached AcceptToMemoryPool's assertion that the chainstate has a
mempool. Stop the load instead. bitcoin/master has the same gap after a
rejection.

If the mempool moved to another chainstate while the startup load ran,
the load is not marked as tried. The shutdown dump then keeps mempool.dat
instead of overwriting it with a partial pool, and savemempool refuses
until the next start, which loads the file again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
chainstatemanager_activate_snapshot deferred an InstantSend conflict on a
stalled snapshot chainstate but never retried it. Keep the NetInstantSend
alive and retry the deferred conflict through RetryUnresolvedConflicts:

- on the next tip, while the stall persists, the retry defers it again and
  leaves no block invalid and the lock in place;
- once a ChainLock covers the conflicting block, the retry drops the lock
  and leaves the chain where it is.

A retry that succeeds once the unavailability clears is not reachable in a
run: stalls stick until restart, and the queue is in memory.

The work thread's call to RetryUnresolvedConflicts stays covered by review
only: catching its removal would mean running the thread on a timer, which
makes the test timing-dependent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
feature_assumeutxo_dash.py checked only the evo section dumptxoutset writes.
Extend it so that three cold nodes, which know only the headers, load node 0's
dumps at bases 3, 23 and 18 blocks into a rotation cycle (the last inside the
mining window), with the regtest default -checkblockindex:

- node X refuses a mutated coin, a mutated evo section, and a pin with either
  hash of another dump. -reindex and then -reindex-chainstate drop snapshots
  whose chains connected blocks above the base, and plain IBD follows.
- node R loads a section that adds an EHF signal, under a pin taken from that
  section. Background validation over P2P rejects it at completion: the node
  stops, keeps chainstate_snapshot_INVALID, misbehaves no peer and marks no
  block invalid. After the restart it refuses another snapshot while the
  rejected one is kept, then syncs from blocks. R's mempool holds a child of
  a transaction mined at base+1, valid only on the snapshot chain: node 0
  takes the parent's InstantSend lock before mine_quorum mines it and keeps
  its output locked (lockunspent) for R. Completion must still stop the node
  cleanly with that child in the mempool.
- node A takes a transaction spending snapshot coins into its mempool with an
  InstantSend lock from a carried quorum, and connects InstantSend,
  withdrawal and EHF traffic above the base. A carried platform quorum
  verifies the withdrawal's signature. An InstantSend lock disconnects a
  block A mined with a conflicting spend. With the background chainstate
  just past blocks before v19, a basic-scheme ChainLock is accepted with no
  misbehaviour. An EHF signal of a quorum the snapshot does not carry stalls
  the snapshot chain, also across a restart; background validation still
  completes in the same run, and an InstantSend lock two cycles old verifies
  after completion (bitcoin#31556). A masternode key is refused while the
  snapshot is unpromoted, and the restart that promotes it connects the
  stalled block.

The network adds two EvoNodes for platform quorums and activates v19 at
height 60, so a background chainstate can be before v19 while the snapshot
chain is after it.

The test now takes about 100 s, so test_runner.py lists it first among the
base tests under five minutes.
…tate is readable

registeredCollateralExclusion checks that the wizard keeps its collateral
candidates and shows the "state unavailable" label while the masternode list
cannot be read, as it cannot under a snapshot view below the base. Once the
list is readable again, a refresh cleared that label only through the
collateral combo box's index-change signal. A refresh that lists no
candidate, with the combo box empty before and after, emits no signal, so the
label stayed until the page changed.

Clear the label on the readable path of the refresh, and check both halves:
with one candidate, and with none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…state after loading

9315754 test: assumeutxo: spend coin from snapshot chainstate after loading

Pull request description:

  Submit a transaction that spends a coin only the snapshot chainstate knows
  (the coinbase of the first block the loading node lacks) and check that it
  enters the mempool and spends the coin.

Dash adaptations:
- The output pays the coinbase value less a 0.001 DASH fee, instead of
  upstream's fixed 24.99, which is specific to Bitcoin's subsidy.
- The coin is the coinbase of block START_HEIGHT + 1, which n0 mines to its
  deterministic key; the MiniWallet transactions at EXTRA_TX_HEIGHTS spend
  other coins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lues

9d9a745 assumeutxo: Remove BLOCK_ASSUMED_VALID flag
ef174e9 test: assumeutxo snapshot block CheckBlockIndex crash test
0391458 test: assumeutxo stale block CheckBlockIndex crash test
ef29c8b assumeutxo: Get rid of faked nTx and nChainTx values
9b97d5b doc: Improve comments describing setBlockIndexCandidates checks
0fd915e validation: Check GuessVerificationProgress is not called with disconnected block
63e8fc9 ci: add getchaintxstats ubsan suppressions
f252e68 assumeutxo test: Add RPC test for fake nTx and nChainTx values

Pull request description:

  Snapshot activation no longer fakes nTx and nChainTx for the blocks below
  the base, and BLOCK_ASSUMED_VALID goes. nTx and nChainTx stay 0 until a
  block's transactions are known; only the base gets the pinned nChainTx.
  CheckBlockIndex() checks the exact nChainTx sum and restarts its "first
  missing/invalid" tracking at the snapshot base.

Dash adaptations:
- This removes the interim the bitcoin#27596 commit added while counts were faked:
  CheckBlockIndex()'s two exceptions to the monotonic nChainTx check and
  BlockManager::m_faked_tx_height. The monotonic check gives way to bitcoin#28562's
  exact sum check (73700fb), which the bitcoin#28562 commit left out, in its
  bitcoin#29370 form.
- BLOCK_ASSUMED_VALID also covered the block index a dropped snapshot leaves
  behind (-reindex-chainstate, or a restart after a rejection): blocks it
  connected above a base whose ancestors were never validated keep CHAIN and
  SCRIPTS validity, which CheckBlockIndex now rejects. LoadBlockIndex lowers
  such blocks to the level their ancestors back up, and never below
  TRANSACTIONS. bitcoin/master has the same gap after -reindex-chainstate.
- CheckBlockIndex() keeps tracking ChainLock-conflicting ancestors beside
  the invalid ones, and the candidate checks skip both.
- BLOCK_STATUS_RESERVED keeps the value 256. No released version of this
  tree loads a snapshot, so no block index on disk has faked counts and no
  compatibility code is needed (upstream's compatibility note).
- The loop at the snapshot switch keeps marking the chain's entries dirty
  but changes none of them: the BLOCK_OPT_WITNESS faking that upstream
  keeps there is SegWit-only.
- clientversion.h is included for FormatFullVersion() in the new warnings.
- Dash unit tests: the cold-importer fixture (ForgetBlocks) resets the
  forgotten entries as CreateAndActivateUTXOSnapshot() now does; the
  switch-recheck case no longer looks for the removed flag; the failed-
  preparation case checks that only the switch sets a count, the base's
  pinned nChainTx.
- feature_assumeutxo.py counts the transactions of each block from its
  EXTRA_TX_HEIGHTS rows rather than upstream's every third block, checks the
  dump's nChainTx against that count, and adds the stale block as upstream.
- The ubsan suppressions use this tree's file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A snapshot rejected before background validation reached its base left the
base with the transaction count from the snapshot metadata, and the blocks
above it counted from that. Restoring the validated chainstate's candidates
then offered it blocks above an unlinked gap: the next block in the shutdown
window failed FindMostWorkChain's assert, and -checkblockindex failed on the
counts and on validity.

Give the base and the blocks above it the state the next startup derives
without the snapshot: counts only through linked parents, unlinked blocks with
data back in m_blocks_unlinked, and CHAIN/SCRIPTS validity only where
validated ancestors back it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2342b46 test: Add coverage for getchaintxstats in assumeutxo context
faf2a67 rpc: Reorder getchaintxstats output
fa2dada rpc: Avoid getchaintxstats invalid results

Pull request description:

  getchaintxstats computed its window from nChainTx values that are unset
  while an assumeutxo snapshot is being validated, and reported wrong or
  wrapped counts. Omit txcount, window_tx_count and txrate when they are
  unknown, and drop the ubsan suppressions bitcoin#29370 added for this RPC.

Dash adaptations:
- The window count is a plain value with a flag instead of std::optional:
  gcc-11 reports -Wmaybe-uninitialized on upstream's form, which
  --enable-werror turns into an error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…idated

b7ba60f test: add coverage for -reindex and assumeutxo
e57f951 init, validation: Fix -reindex option with an existing snapshot

Pull request description:

  Restarting with -reindex or -reindex-chainstate while a snapshot
  chainstate exists must delete it, and a snapshot can be loaded again
  afterwards.

Dash adaptations:
- e57f951 is equivalent in this tree and not applied: node::LoadChainstate()
  deletes the snapshot chainstate directory with
  DeleteSnapshotChainstateFromDisk() before it detects a snapshot, when
  reindexing, so no snapshot chainstate is created that would need
  deleting, and the validated chainstate is initialized with the node's
  mempool from the start. Upstream's DeleteSnapshotChainstate() and its
  mempool handover therefore have no counterpart.
- The test's coin count comes from the dump, as in the rest of the file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…not open file

ee67bba test: added test coverage to loadtxoutset

Pull request description:

  Check that loadtxoutset fails with a clear error for a path that does
  not exist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…invalid chain

2f9bde6 test: Remove unnecessary restart in assumeutxo test
19ce3d4 assumeutxo: Check snapshot base block is not marked invalid
80315c0 refactor: Move early loadtxoutset checks into ActiveSnapshot

Pull request description:

  ActivateSnapshot() returns a util::Result, so loadtxoutset reports why a
  load failed, and the checks that loadtxoutset made before calling it move
  into it. A base block in an invalid chain is refused.

Dash adaptations:
- 19ce3d4 is equivalent here: SnapshotActivationRefusal() already
  refuses a base whose chain has a block marked failed or ChainLock-
  conflicting, at load and again at the switch, so no second check is added.
  test_snapshot_block_invalidated runs on n0, the node with the downloaded
  chain, restarted with the pin for this check only (it never loads a
  snapshot), and matches the refusal's message.
- The snapshot metadata has no base height in this tree (bitcoin#29612 is not
  ported), so the unrecognized-hash error names the hash only, without the
  available heights.
- loadtxoutset still waits for the base header (bitcoin#29345 is not ported), so it
  keeps a hash check before that wait, with the same message, rather than
  wait for a header that cannot be authorized.
- The refusals that this tree logs keep their log lines, which its tests and
  operators read; each now also returns its reason. Dash's own failures
  (another activation running, an earlier rejected snapshot, the Evo
  publication) return theirs too.
- loadtxoutset keeps reporting the tip it activated.
- test_invalid_mempool_state comes from bitcoin#29394, which this file lacked, in
  its bitcoin#30267 form, with n2 started with -persistmempool=0 as there. It
  overlaps a unit case of the refusals commit; both are kept.
- 2f9bde6 and the hunks for bitcoin#29428's test_snapshot_with_less_work,
  bitcoin#29478's test_headers_not_synced, bitcoin#29612's metadata rows and bitcoin#29973's
  double load are not applicable: those tests are not in this file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ent chain + test

5b7f70b test: loadtxoutset in divergent chain with less work
d35efe1 p2p: Start downloading historical blocks from common ancestor

Pull request description:

  When the active chain tip is not an ancestor of the snapshot base, the
  background chainstate must download the snapshot's history from the last
  common ancestor of its tip and the base, not from its own tip.

Dash adaptations:
- The divergent-chain node is a fifth node (n4): n3 is the node that drops
  its snapshot with -reindex-chainstate. It is authorized with the same
  -assumeutxodata pin as the other loading nodes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the best header chain

55b6d7b validation: Don't load a snapshot if it's not in the best header chain.

Pull request description:

  Refuse a snapshot whose base is not an ancestor of the best known header:
  the node could not reorg away from it before background validation ends.

Dash adaptations:
- The snapshot metadata carries no base height in this tree (bitcoin#29612 is not
  ported), so the check takes the height from the base's block index entry.
- As upstream, the check runs once at load; it is not part of
  SnapshotActivationRefusal(), which is repeated at the switch. It follows
  that function's checks, so an invalid base is reported as such first, as
  upstream orders its invalid-chain check before this one.
- Invalidating a block moves the best header back and reconsidering it does
  not restore it (bitcoin#30666 is not ported). The unit cases that reconsider the
  base before loading again set the best header back to the base.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ore background chain

49d569c p2p: For assumeutxo, download snapshot chain before background chain
7a88551 p2p: Restrict downloading of blocks for snapshot chain

Pull request description:

  Download the snapshot chain's blocks first by resetting the last common
  block of each peer to at least the snapshot base, and do not download
  from peers whose best chain lacks the snapshot base, since the node could
  not reorg to their chain before background validation ends.

Upstream adds no test; the functional rows that sync a snapshot node from
n0 cover the download order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…operate on snapshot chainstate

917e70a test: assumeutxo: check that UTXO-querying RPCs operate on snapshot chainstate

Pull request description:

  Inspired by some manual testing I did for bitcoin#28553, this PR checks that RPCs which explicitly query the UTXO set database (i.e. `gettxoutsetinfo`, `scantxoutset` and `gettxout`) operate on the snapshot chainstate as expected.

Applies unchanged. In Dash both RPCs also flush the snapshot chainstate's
Evo state from the RPC thread while the background chainstate runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… nodes during IBD

992f83b test: add coverage for assumeUTXO honest peers disconnection
6d5812e assumeUTXO: fix peers disconnection during sync

Pull request description:

  A node with a snapshot chainstate advertised NODE_NETWORK although it
  cannot serve the blocks below the base, so IBD peers requested them, got
  no answer and disconnected it as stalling. loadtxoutset now replaces
  NODE_NETWORK with NODE_NETWORK_LIMITED, startup does not set NODE_NETWORK
  while background sync is in progress, and NODE_NETWORK returns when
  background validation completes (restart_indexes becomes
  snapshot_download_completed).

Dash adaptations:
- Snapshots are refused on pruned nodes here, so feature_assumeutxo.py's n1
  is a full node: its checks expect NODE_NETWORK_LIMITED only while it is in
  dual mode and NODE_NETWORK again after completion, as for n2, instead of
  upstream's pruned-node checks.
- test_sync_from_assumeutxo_node waits for NODE_NETWORK after the base block
  is stored, since background completion can follow the block's storage. The
  n1 and n2 rows likewise wait for NODE_NETWORK after completion: the callback
  that restores it runs after the step that disabled the background
  chainstate, which getchainstates can already reflect.
- A snapshot rejected at completion keeps NODE_NETWORK_LIMITED until the
  next restart: the node stays up after a rejection in this tree, and the
  advertisement is conservative, never dishonest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…or background chainstate

c0a0c72 validation: Disable CheckForkWarningConditions for background chainstate

Pull request description:

  The background chainstate's tip lags far behind, so comparing it with the
  best invalid block raised a fork warning for a fork that the active chain
  does not have.

Dash adaptations:
- feature_assumeutxo_dash.py's dual-mode scenario checks that the warnings
  lack "We do not appear to fully agree" after the background chainstate
  connected blocks below a block invalidated by an InstantSend lock.
- As upstream until bitcoin#30214, the step that completes background validation
  reports NORMAL, so that one step still evaluates the condition; the next
  active step resets it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_tx_count, Improve wallet RPC errors

9d2d9f7 rpc: Include assumeutxo as a failure reason of rescanblockchain
595edee test, assumeutxo: import descriptors during background sync
d73ae60 rpc: Improve importdescriptor RPC error messages
27f99b6 validation: Don't assume m_chain_tx_count in GuessVerificationProgress
42d5d53 interfaces: Add helper function for wallet on pruning

Pull request description:

  GuessVerificationProgress() can legitimately see a block without a
  transaction count, e.g. a wallet rescan below a snapshot base, so it
  returns 0 with a debug log instead of an Assume. importdescriptors and
  rescanblockchain name the assumeutxo background sync as the likely cause
  when blocks are unavailable.

Dash adaptations:
- 42d5d53 (Chain::getPruneHeight) is not ported: it needs GetPruneHeight()
  from bitcoin#29668, which this tree lacks. rescanblockchain therefore reports
  pruning whenever the node has pruned, as before; a node with a snapshot
  chainstate never prunes here, so the assumeutxo message is unaffected.
- m_chain_tx_count is nChainTx in this tree; the log names dashd.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… promoted

bitcoin#33604 is not adopted. Before the restart that promotes a validated
snapshot, Dash cannot disconnect below the base's carried Evo state, so
downloading from such peers only stalls and churns the chain. bitcoin#29519's
refusal, which keys on the snapshot base, already lasts until promotion here,
because no snapshot base exists after the promoting restart.

Its test is replaced by this one. The snapshot node, validated but not yet
restarted, still reports its snapshot base in getchainstates. It refuses a
peer whose more-work chain forks below the base, without an Evo state error,
and keeps its tip. The restart promotes it, so getchainstates no longer
reports a snapshot base, and it then reorgs to that chain below the old base,
through the validated chainstate's Evo state. The fork is mined to a fresh
address: with the mock time fixed, the usual address would rebuild the block
just invalidated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5cd5794 test: verify node state after restart in assumeutxo

Pull request description:

  Replace the TODO after the restart during background sync with checks of
  the chainstates and of wallet loading, which still needs the blocks below
  the snapshot.

Dash adaptations:
- The pruned-node rows that use the same error helper are absent: a node
  does not load snapshots with -prune in this tree.
- A blank line precedes the nested helper, for this tree's flake8 (E306).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…o.py

faa68ed test: Fix intermittent issue in wallet_assumeutxo.py

Pull request description:

  -stopatheight may let a few more blocks through during shutdown. Sync the
  node to the pause height with submitblock instead of restarting it, and
  unload the wallets so the loading checks still apply.

Dash adaptations:
- setup_network() keeps its form; the pruned-node rows are absent, as for
  bitcoin#34286.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…xo.py

faf71d6 test: [refactor] Use verbosity=0 named arg
99996f6 test: Fix intermittent issue in feature_assumeutxo.py

Pull request description:

  Sync n1 to the pause height with submitblock instead of a -stopatheight
  restart, which could stop a few blocks later than expected.

Dash adaptations:
- The blockfile segmentation checks between the two hunks are absent, as
  the segmentation is not part of this tree (bitcoin#27596's commit).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

This pull request has conflicts, please rebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants