Skip to content

backport: bitcoin#29215, #29394, #29370, #29720, #29726, #30053, #29345, #29478, #29973, #29612, #30167, #29428, #30267, #30395, #29996, #30666, #30320, #30497, #29519, #30598, #30636, #30807, #30880, #30962, #30909, #32033, #34286, #34728, #34852 - #8079

Open
PastaPastaPasta wants to merge 75 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

AssumeUTXO stack (merge in this order; each PR holds the commits of the ones below it; #8272 has merged): #8078 → #8273 → #8079 → #8276. Review only the commits listed as new.

The snapshot loader in #8078 (bitcoin#27596 and its follow-ups) works, but it carries debt that upstream fixed after bitcoin#27596:

  • Faked counts. Activation fakes nTx and nChainTx for every block below the base and marks them BLOCK_ASSUMED_VALID. assumeutxo: Get rid of faked nTx and nChainTx values bitcoin/bitcoin#29370 removes the faking.
  • Loader and download bugs:
    • loadtxoutset accepts a base that is not in the best header chain, and doesn't report why it refuses a snapshot.
    • Historical block download starts from the wrong block when the snapshot chain diverges, and it can run before the snapshot chain.
    • AssumeUTXO nodes disconnect peers during IBD.
    • The background chainstate raises fork warnings.
  • Test flakes and missing coverage in feature_assumeutxo.py and wallet_assumeutxo.py.

Restack (2026-12-04). This PR now sits on the restacked #8273, on the per-chainstate Evo design that #8286 put on develop. Its commits are the versions knst ported onto that design in #8284. Compared with the previous head:

What was done?

New on top of #8273:

What to focus on: bitcoin#29370 (removes the faked counts), bitcoin#30666 (best-header tracking on every network), bitcoin#30497 and bitcoin#30598 (the loader's errors and metadata), and the two Dash commits.

How Has This Been Tested?

On Linux x86_64 (Debug, GCC, depends, -DWERROR=ON), this head builds. validation_chainstatemanager_tests, validation_chainstate_tests, evo_snapshot_tests, evo_db_tests and evo_islock_tests pass at this head.

At the top of the stack (#8276), the full test_dash passes, and so do feature_assumeutxo, feature_assumeutxo_dash, feature_assumeutxo_refusals, wallet_assumeutxo and rpc_dumptxoutset.

To test: test/functional/test_runner.py feature_assumeutxo.py wallet_assumeutxo.py feature_assumeutxo_dash.py rpc_dumptxoutset.py rpc_getchaintips.py rpc_invalidateblock.py.

Breaking Changes

Checklist:

  • I have performed a self-review of my own code
  • I have added or updated relevant unit/integration/functional/e2e tests
  • 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 in progress (commit 1755146) · live progress

  • Request priority review — click to give the rest of this review priority.

@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 29 commits December 4, 2026 07:36
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.
- The RPC holds cs_main while it reads the window's nChainTx values, not
  only while it selects the block: a rejected snapshot's base and the blocks
  above it get their counts rewritten under cs_main here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
faa30a4 rpc: Do not wait for headers inside loadtxoutset

Pull request description:

  loadtxoutset waited up to ten minutes for the snapshot base's header
  before activating. Fail immediately instead, asking the caller to sync
  headers and call it again.

Dash adaptations:
- contrib/devtools/test_utxo_snapshots.sh is not in this tree, so its hunk
  is dropped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
1ec6684 test: Add test for loadtxoutset when headers are not synced
2bc1ecf test: Remove unnecessary sync_blocks in assumeutxo tests

Pull request description:

  Test that loadtxoutset fails right away when the node lacks the snapshot
  base's header, which bitcoin#29345 changed from a ten-minute wait. Also drop a
  sync_blocks call that compared the disconnected nodes' identical cached
  chains.

Dash adaptations:
- The loading nodes here receive the new headers while n0 mines the
  snapshot chain, so the check runs on n3 after its datadir is wiped for
  the startup block import scenario, before it gets the headers, instead
  of on nodes 1 and 2 before the headers are ferried over.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…a snapshot twice

b259b0e [Test] Assumeutxo: ensure failure when importing a snapshot twice (Alfonso Roman Zubeldia)

Pull request description:

  I am getting familiar with the `assume_utxo` tests and I found that the scenario of trying to activate a snapshot twice is not covered. This test is to ensure failure when loading a snapshot if there is already a snapshot-based chainstate.

ACKs for top commit:
  fjahr:
    Code review ACK b259b0e
  kevkevinpal:
    tACK [b259b0e](bitcoin@b259b0e)
  achow101:
    ACK b259b0e
  rkrux:
    tACK [b259b0e](bitcoin@b259b0e)

Tree-SHA512: 3510861390d0e40cdad6861b728df04827a1b63e642f3d956aee66ed2770b1cb7e3aa3eb00c62eb9da0544703c943cc5296936c9ebfcac18c719741c354421bb
… of dumptxoutset output

542e13b rpc: Enhance metadata of the dumptxoutset output (Fabian Jahr)
4d8e5ed assumeutxo: Add documentation on dumptxoutset serialization format (Fabian Jahr)
c14ed7f assumeutxo: Add test for changed coin size value (Fabian Jahr)
de95953 rpc: Optimize serialization disk space of dumptxoutset (Fabian Jahr)

Pull request description:

  The second attempt at implementing the `dumptxoutset` space optimization as suggested in bitcoin#25675. Closes bitcoin#25675.

  This builds on the work done in bitcoin#26045, addresses open feedback, adds some further improvements (most importantly usage of compact size), documentation, and an additional test.

  The [original snapshot at height 830,000](bitcoin#29551) came in at 10.82 GB. With this change, the same snapshot is 8.94 GB, a reduction of 17.4%.

  This also enhances the metadata of the output file and adds the following data to allow for better error handling and make future upgrades easier:
  - A newly introduced utxo set magic
  - A version number
  - The network magic
  - The block height

ACKs for top commit:
  achow101:
    ACK 542e13b
  TheCharlatan:
    Re-ACK 542e13b
  theStack:
    ACK 542e13b

Tree-SHA512: 0825d30e5c3c364062db3c6cbca4e3c680e6e6d3e259fa70c0c2b2a7020f24a47406a623582040988d5c7745b08649c31110df4c10656aa25f3f27eb35843d99
…in#29612

efc1b5b test: Add coverage for txid coins count check when loading snapshot (Fabian Jahr)
6b60848 assumeutxo: Add network magic ctor param to SnapshotMetadata (Fabian Jahr)
1f1f998 assumeutxo: Deserialize trailing byte instead of Txid (Fabian Jahr)
359967e doc: Add release notes for bitcoin#29612 (Fabian Jahr)

Pull request description:

  This adds release notes for bitcoin#29612 and addresses post-merge review comments.

ACKs for top commit:
  maflcko:
    utACK efc1b5b
  theStack:
    utACK efc1b5b

Tree-SHA512: 3b270202e4f7b2576090ef1d970fd54a6840d96fc3621dddd28e888fb8696a97ff69af2e000bcee3b364316ca3f6e2a9b2f1694c6184f0e704dc487823127ce4
…d not be loaded

df6dc2a test: Assumeutxo: snapshots with less work should not be loaded (Hernan Marino)

Pull request description:

  This PR adds a test which checks that snapshots with less accumulated work than the node's active chain, should not be loaded and return with an error. Although in a different context of discussion the missing test was detect in a thread in bitcoin#29394 (see bitcoin#29394 (comment))

ACKs for top commit:
  maflcko:
    utACK df6dc2a
  kevkevinpal:
    utACK [df6dc2a](bitcoin@df6dc2a)
  achow101:
    ACK df6dc2a
  alfonsoromanz:
    Re ACK df6dc2a. Make is successful and the test passes.

Tree-SHA512: 07a394b4b288cc8ad3f66ed4e70dcda468db18113e9442eb7215cf491768432d55efaaa5b79d633094917e05475a30f0c5e4f64f8f2da293ba306891b4485560
…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 unrecognized-hash error names the hash and the metadata height and
  lists the available snapshot heights, as upstream at this point (bitcoin#29612
  comes earlier in this stack; bitcoin#30598 later drops the height).
- 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 looks the base up after activation for its tip_hash and
  base_height.
- test_invalid_mempool_state (from bitcoin#29394, earlier in this stack) takes 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 is taken: test_snapshot_with_less_work (bitcoin#29428, earlier in
  this stack) no longer restarts node 0 after the refusal. Node 0 keeps the
  pin that check installed until test_invalid_chainstate_scenarios()
  restarts it without one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fa5b892 rpc: Use untranslated error strings in loadtxoutset (MarcoFalke)
fa45865 refactor: Use named arguments to get path arg in loadtxoutset (MarcoFalke)

Pull request description:

  Motivation:
  * Some are not translated at all, anyway. See bitcoin#30267 (comment)
  * For others translation is not yet needed, because they are not called by the GUI (yet)
  * For others translations will never be needed, because they are RPC code. See bitcoin#30267 (comment)

  Also, while touching this:
  * Remove the trailing `\n`. See bitcoin#30267 (comment)
  * Add back the path. See bitcoin#30267 (comment)
  * Use named args to get the path.

ACKs for top commit:
  fjahr:
    re-ACK fa5b892
  tdb3:
    ACK fa5b892
  ryanofsky:
    Code review ACK fa5b892

Tree-SHA512: 46504dc5fd55a6274ef885dbe071aa9efb25bca247cd68cd86fb2ff066d70d295e0522e1fe42e63f1fdf7e4c89bd696220edaf06e33b804aba746492eafd852e
…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 <[email protected]>
…_FAILED_CHILD assignment

0bd53d9 test: add test for getchaintips behavior with invalid chains (Martin Zumsande)
ccd98ea test: cleanup rpc_getchaintips.py (Martin Zumsande)
f5149dd validation: mark blocks building on an invalid block as BLOCK_FAILED_CHILD (Martin Zumsande)
783cb73 validation: call RecalculateBestHeader in InvalidChainFound (Martin Zumsande)
9275e96 rpc: call RecalculateBestHeader as part of reconsiderblock (Martin Zumsande)
a51e917 validation: add RecalculateBestHeader() function (Martin Zumsande)

Pull request description:

  `m_best_header` (the most-work header not known to be on an invalid chain) can be wrong in the context of invalidation / reconsideration of blocks. This can happen naturally (a valid header is received and stored in our block tree db; when the full block arrives, it is found to be invalid) or triggered by the user with the `invalidateblock` / `reconsiderblock` rpc.

  We don't currently use `m_best_header` for any critical things (see OP of bitcoin#16974 for a list that still seems up-to-date), so it being wrong affects mostly rpcs.

  This PR proposes to recalculate it if necessary by looping over the block index and finding the best header. It also suggest to mark headers between an invalidatetd block and the previous `m_best_header` as invalid, so they won't be considered in the recalculation.
  It adds tests to `rpc_invalidateblock.py` and `rpc_getchaintips.py` that fail on master.

  One alternative to this suggested in the past would be to introduce a continuous tracking of header tips (bitcoin#12138).
  While this might be more performant, it is also more complicated, and situations where we need this data are only be remotely triggerable by paying the cost of creating a valid PoW header for an invalid block.
  Therefore I think it isn't necessary to optimise for performance here, plus the solution in this PR doesn't perform any extra steps in the normal node operation where no invalidated blocks are encountered.

  Fixes  bitcoin#26245

ACKs for top commit:
  fjahr:
    reACK 0bd53d9
  achow101:
    ACK 0bd53d9
  TheCharlatan:
    Re-ACK 0bd53d9

Tree-SHA512: 23c2fc42d7c7bb4f9b4ba4949646b3d0031dd29ed15484e436afd66cd821ed48e0f16a1d02f45477b5d0d73a006f6e81a56b82d9721e0dee2e924219f528b445
3c3548a validation: clarify final |= BLOCK_FAILED_VALID in InvalidateBlock (Matt Corallo)
aac5488 validation: correctly update BlockStatus for invalid block descendants (stratospher)
9e29653 test: check BlockStatus when InvalidateBlock is used (stratospher)
c996675 validation: fix traversal condition to mark BLOCK_FAILED_CHILD (stratospher)

Pull request description:

  This PR addresses 3 issues related to how `BLOCK_FAILED_CHILD` is set:
  1. In `InvalidateBlock()`
  - Previously, `BLOCK_FAILED_CHILD` was not being set when it should have been.
  - This was due to an incorrect traversal condition, which is fixed in this PR.

  2. In `SetBlockFailure()`
  - `BLOCK_FAILED_VALID` is now cleared before setting `BLOCK_FAILED_CHILD`.

  3. In `InvalidateBlock()`
  - if block is already marked as `BLOCK_FAILED_CHILD`, don't mark it as `BLOCK_FAILED_VALID` again.

  Also adds a unit test to check `BLOCK_FAILED_VALID` and `BLOCK_FAILED_CHILD` status in `InvalidateBlock()`.

  <details>
  <summary><h3>looking for feedback on an alternate approach</h3></summary>
  <br>

  An alternate approach could be removing `BLOCK_FAILED_CHILD` since even though we have a distinction between
  `BLOCK_FAILED_VALID` and `BLOCK_FAILED_CHILD` in the codebase, we don't use it for anything. Whenever we check for BlockStatus, we use `BLOCK_FAILED_MASK` which encompasses both of them. See  similar discussion in bitcoin#16856.

  I have a branch with this approach in https://github.com/stratospher/bitcoin/commits/2025_02_remove_block_failed_child/.
  Compared to the version in bitcoin#16856, it also resets `BLOCK_FAILED_CHILD` already on disk to `BLOCK_FAILED_VALID` when loading from disk so that we won't be in a dirty state in a no-`BLOCK_FAILED_CHILD`-world.

  I'm not sure if it's a good idea to remove `BLOCK_FAILED_CHILD` though. would be curious to hear what others think of this approach.

  thanks @ mzumsande for helpful discussion regarding this PR!
  </details>

ACKs for top commit:
  achow101:
    ACK 3c3548a
  TheCharlatan:
    Re-ACK 3c3548a
  mzumsande:
    re-ACK 3c3548a

Tree-SHA512: 83e0d29dea95b97519d4868135c965b86f6f43be50b15c0bd8f998b3476388fc7cc22b49c0c54ec532ae8222e57dfc436438f0c8e98f54757b384f220488b6a6

Dash adaptations:
- InvalidateBlock() keeps every invalidated block (or, after a stall, the
  last disconnected one) in m_failed_blocks, as this tree's header
  acceptance reads that set; upstream inserts only in the branch for a block
  that never was in the chain.
- The unit test takes cs_main directly instead of ChainstateManager::GetMutex()
  and includes validation.h and consensus/validation.h, which this
  blockchain_tests.cpp did not include.
- Follow-up to bitcoin#30666, ported earlier in this stack.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… 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 check is the last one in SnapshotActivationRefusal(), so it runs at
  load and again under the cs_main hold of the switch. Headers of a
  more-work fork that arrive while the snapshot is populated are refused
  like those known before the load. Upstream checks only at load. The
  refusal is logged and returned like the other refusals, with upstream's
  message.
- It takes the height from the base's block index entry, the form upstream
  reaches once bitcoin#30598 drops the height from the metadata.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y go to logs

fa530ec rpc: Return precise loadtxoutset error messages (MarcoFalke)
faa5c86 refactor: Use untranslated error message in ActivateSnapshot (MarcoFalke)

Pull request description:

  The error messages should never happen in normal operation. However, if
  they do, they are helpful to return to the user to debug the issue. For
  example, to notice a truncated file.

  This fixes bitcoin#28621

  Also includes a minor refactor commit.

ACKs for top commit:
  fjahr:
    Code review ACK fa530ec
  ryanofsky:
    Code review ACK fa530ec, just adjusting error messages a little since last review. (Thanks!)

Tree-SHA512: 224968c9b13d082ca2ed1f6a8fcc5f51ff16d6c96bd38c3679699505b54337b99cccaf7a8474391f6b11f9ccb101977b4e626898c1217eae95802e290cf105f1
…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 <[email protected]>
00618e8 assumeutxo: Drop block height from metadata (Fabian Jahr)

Pull request description:

  Fixes bitcoin#30514 which has more context and shows how the issue can be reproduced. Since the value in question is removed, there is no test to add to reproduce anything.

  This is an alternative approach to bitcoin#30516 with much of the [code being suggested there](bitcoin#30516 (comment)).

ACKs for top commit:
  maflcko:
    re-ACK 00618e8 🎌
  achow101:
    ACK 00618e8
  theStack:
    Code-review ACK 00618e8
  ismaelsadeeq:
    Re-ACK 00618e8
  mzumsande:
    ACK 00618e8

Tree-SHA512: db9575247bae838ad7742a27a216faaf55bb11e022f9afdd05752bb09bbf9614717d0ad64304ff5722a16bf41d8dea888af544e4ae26dcaa528c1add0269a4a8
…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 <[email protected]>
… 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.
- The waits for NODE_NETWORK in test_sync_from_assumeutxo_node, after the
  base block is stored, and in the n2 row, after completion, are
  bitcoin#30880's 19f4a7c (test: Wait for local services to
  update in feature_assumeutxo), folded in here. The n1 row waits the same
  way: the callback that restores NODE_NETWORK runs after the step that
  disabled the background chainstate, which getchainstates can already
  reflect.
- A snapshot rejected at completion does not restore NODE_NETWORK: the
  rejection requests a shutdown, and the next startup computes the service
  flags again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…re_assumeutxo

19f4a7c test: Wait for local services to update in feature_assumeutxo (Fabian Jahr)

Pull request description:

  Closes bitcoin#30878

  It seems like there is a race where the block is stored locally and `getblock` does not error anymore, but `ActivateBestChain` has not finished yet, so the local services are not updated yet either. Fix this by waiting for the local services to update.

  Can be reproduced locally by adding the sleep here:

  ```cpp
  ──────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  src/validation.cpp:3567: bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr< │
  ──────────────────────────────────────────────────────────────────────────────────────────────────────────┘
          }

          if (WITH_LOCK(::cs_main, return m_disabled)) {
              std::this_thread::sleep_for(std::chrono::seconds(10));
              // Background chainstate has reached the snapshot base block, so exit.

              // Restart indexes to resume indexing for all blocks unique to the snapshot
  ```

ACKs for top commit:
  maflcko:
    review-only ACK 19f4a7c
  achow101:
    ACK 19f4a7c
  pablomartin4btc:
    tACK 19f4a7c
  furszy:
    Code review ACK [19f4a7c](bitcoin@19f4a7c).

Tree-SHA512: 70dad3795988956c5e20f2d2d895fb56c5e3ce257c7547d3fd729c88949f0e24cb34594da1537bce8794ad02b2db44e7e46e995aa32539cd4dd84c4f1d4bb1c4
…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 invalidates the block
  with the spend conflicting with an InstantSend lock and checks that the
  warnings lack "We do not appear to fully agree" after the background
  chainstate connected blocks below it.
- 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 <[email protected]>
…_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 <[email protected]>
… successful

52482cb test: Check datadir cleanup after assumeutxo was successful (Fabian Jahr)

Pull request description:

  I noticed that the proper datadir cleanup after a successful restart of an assumutxo node does not seem to be covered in our tests. This is added here.

ACKs for top commit:
  l0rinc:
    utACK 52482cb
  mabu44:
    Re-ACK 52482cb
  Prabhat1308:
    re-ACK [`52482cb`](bitcoin@52482cb)
  TheCharlatan:
    Re-ACK 52482cb

Tree-SHA512: cc941afeba250050eaccf5112255d961253fec9b2683545454a0d2fbe4d542178394b301d169a9dd79edbf6b5d478d95282727dbb0aca96ee79d4cd1ff80f19b
… 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 <[email protected]>
bitcoin#29519's download refusal only covers FindNextBlocksToDownload. A chain
forking below the snapshot base still reaches the snapshot chainstate's
candidates when its blocks arrive another way (direct fetch of a short
fork, submitblock, blocks already on disk) once their parents below the
base are linked, which the background chainstate's progress provides. The
snapshot chainstate then disconnected its blocks down towards the base
until it stalled on Evo state below the base that it does not have, before
or after background validation reached the base, and reconnected them.

FindMostWorkChain now passes over candidates that do not descend from the
base while the snapshot chainstate's chain contains it. They stay in
setBlockIndexCandidates, and after the restart that promotes the snapshot
there is no base and the node follows them.

The test submits a more-work chain forking below the base to a snapshot
node whose background chainstate has not reached the base, and to one
that has validated it; both keep their tip without disconnecting a
block. After the promoting restart the node downloads a block of that
chain it has not seen.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants