Skip to content

AssumeUTXO: replace loadtxoutset RPC with a startup arg - #36778

Open
l0rinc wants to merge 12 commits into
bitcoin:masterfrom
l0rinc:l0rinc/assumeutxo-startup
Open

l0rinc wants to merge 12 commits into
bitcoin:masterfrom
l0rinc:l0rinc/assumeutxo-startup

Conversation

@l0rinc

@l0rinc l0rinc commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Problem: Loading a UTXO snapshot through RPC requires coordinating with the active chain, mempool, caches and advertised services while the node is running.

Fix: Replace the loadtxoutset RPC with -loadtxoutset=<file> and finish importing during chainstate initialization, before networking and mempool loading begin.
Require a receiver that has not advanced beyond genesis, already knows the snapshot base header and has no stored blocks beyond genesis or unfinished reindexing.
This removes runtime activation checks, temporary import cache resizing and service demotion while preserving snapshot validation, resumption and background validation.

@DrahtBot

DrahtBot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
Concept ACK fjahr, jeanpablojp

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #37094 (validation: validate assumeutxo snapshots with a single chainstate by fjahr)
  • #36990 (test: replace hard-coded RPC error codes by l0rinc)
  • #36629 (Add output script index and corresponding script history RPC by andrewtoth)
  • #36603 (Improve loadtxoutset performance by ajtowns)
  • #36268 (refactor: prune unused semi-colons by fanquake)
  • #34534 (rpc: Manual prune lock management (Take 2) by fjahr)
  • #33324 (blocks: add resumable reobfuscation for existing block files by l0rinc)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@DrahtBot

DrahtBot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task iwyu: https://github.com/bitcoin/bitcoin/actions/runs/42045836029/job/127308391176
LLM reason (✨ experimental): CI failed because IWYU/clang-format detected an uncommitted include change in src/init.cpp (<unordered_map>); the diff check then exited nonzero.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

When startup connects genesis to an empty chainstate, an index can catch up to genesis before its queued BlockConnected notification arrives.
Ignore that notification when a best block is already indexed, so Rewind never receives a null parent.
Startup snapshot loading will happen before the mempool is loaded, making this RPC scenario obsolete.

Drop the receiver setting that disabled mempool persistence for this scenario.
Startup snapshot loading will require a chainstate at genesis.
Remove the RPC scenarios that import with an active chain with at least as much work, or a different active fork.
Preserve the difficulty-field checks in the surviving import scenario.
This avoids adapting those scenarios only to delete them when the RPC is retired.
Start the receivers in the main, wallet and chainstate-tool tests at genesis while their producers keep the cached chain.
Use the producer's tip time for every node's mocktime in the main and wallet tests.
Supply the headers that the fresh receivers need in the wallet and chainstate-tool tests.

Run the file-path and invalidated-block checks on a receiver, using the producer for block-hash lookups.
Adjust the height and transaction-count checks and use the producer's snapshot metadata for the expected hash and coin count.

In the wallet pruning case, check the imported chainstates first, then supply the historical blocks the cached chain used to provide and keep the manual prune sanity check.

Remove the height check after invalidation on the headers-only receiver, whose chainstate remains at genesis.

Exercise a database-open failure before switching the test calls to startup loading.
Add -loadtxoutset=<file> and call the existing snapshot loader during chainstate initialization, before networking starts.
Both this option and the existing RPC use the same snapshot activation checks, including the requirement to know the base header.
The main import test retains the header index but removes the ordinary chainstate before importing.
Permit a missing active tip in the work comparisons while the RPC still needs those checks.
Publish the imported tip so startup can complete without an ordinary chainstate loaded from disk.
Treat interrupted imports as cancellation and report exceptions through the initialization error path.

Keep snapshot loading separate from reindexing and manual block-import modes.
Skip the GUI reindex retry when an import is requested, since these startup modes cannot be combined.
Check conflicting startup modes, missing snapshot files and option negation.
Require a receiving chainstate at genesis so a new snapshot import does not replace an existing chain.
Also reject unfinished reindexing and stored blocks beyond genesis, which startup could otherwise connect to that chainstate.

Check both a populated chainstate and an empty chainstate with stored blocks.
The latter must fail before connecting any of those blocks.
Use the startup option for the existing snapshot, wallet and chainstate-tool checks.
Update the failure checks in place.
A missing base header now fails startup.
Mock only the producer's clock, since receivers restart to import and lose theirs.

Restore the wallet after importing its snapshot so it can remain active during background validation.
This prepares the tests for retiring the RPC without mixing their setup changes into that commit.
Retire snapshot loading through RPC now that the startup option is available.
Keep a hidden method for existing callers and let the RPC fuzzer exercise it because it no longer reads files.
Leave the help text and migration guidance for the final documentation commit.
Existing imported snapshots still resume normally without the option.
Now that imports happen only at startup, the active chain cannot advance during an import and the mempool has not been loaded yet.
Startup also rejects a new import if a snapshot chainstate already exists.

Remove these checks from snapshot activation.
A supported snapshot has more work than the genesis chainstate, which cannot advance during import, so both work comparisons are redundant.
Remove the test helper's temporary tip rewind as well.
Also remove the unit and fuzz checks that attempt another import.

Only the old RPC needed the details of the snapshot's base block in the result.
Return no value on success and keep the error message on failure.
Keep the checks on the base header, the supported snapshot commitment and the snapshot contents.
Startup imports begin with an empty ordinary chainstate and finish before it can process blocks.
Give the snapshot loader the full cache budget directly, without shrinking and flushing the ordinary cache first or restoring it after failure.
Remove the old percentage split and its conversions.

Keep cache redistribution after the import and during background validation, including the forced flush of the imported block-index state.
The node now announces its limited ability to serve blocks before it accepts any peers.
Loading a snapshot therefore no longer needs to remove service flags from a running node.

Delete `RemoveLocalServices`, and update the fuzz test to keep track of flags as they are added.
The node can still announce full block service once background validation completes.
Describe the -loadtxoutset startup option in the user and design docs, the option and RPC help, and a release note.
Update comments, log messages and errors for startup loading, including the base-header error that asked to call loadtxoutset again.

Correct the swapped file and directory paths in the missing-base-blockhash warning.
@fjahr

fjahr commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Concept ACK

This would also resolve #36346

@jeanpablojp jeanpablojp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

I also read Ralph's review and confirmed two of its points, the major on getting headers into a node at genesis (on signet) and the minor on the restart message when -loadtxoutset is left in the config. I think both are worth fixing in this PR.

Comment thread src/init.cpp
kernel_cache_sizes,
args);
if (status == ChainstateLoadStatus::FAILURE && !do_reindex && !ShutdownRequested(node)) {
if (status == ChainstateLoadStatus::FAILURE && !do_reindex && !SnapshotImportRequested(args) && !ShutdownRequested(node)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could feature_reindex_init.py get a case for !SnapshotImportRequested(args)? The case below fails without it and passes with it.

        self.log.info("A requested snapshot import skips the reindex retry")
        self.stop_node(0)
        self.cleanup_folder(node.blocks_path / "index")
        node.assert_start_raises_init_error(
            extra_args=["-loadtxoutset=unused", "-test=reindex_after_failure_noninteractive_yes"],
            expected_msg="Error: Error initializing block database",
        )

@ajtowns

ajtowns commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Concept -1 for me -- for assumeutxo to be meaningfully usable, snapshots need to be downloaded via p2p, so the snapshot load needs to happen while the system is running, not at startup. I understand the appeal, and have now implemented "loadtxoutset" as a startup argument myself twice, but I think it's fundamentally a dead end.

@l0rinc

l0rinc commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

for assumeutxo to be meaningfully usable, snapshots need to be downloaded via p2p

I don't think these are incompatible. We could defer block synchronization until the headers and the snapshot have been downloaded via P2P and the snapshot has been activated, avoiding corner cases such as importing a snapshot whose base block is on a different branch from our active chain.

I think it's fundamentally a dead end

It's no secret that my preferred solution would be to remove the dual-chainstate AssumeUTXO machinery altogether. I'm trying to get there in smaller steps that eliminate edge cases and reduce complexity along the way, even if the intermediate states aren't ideal in isolation.

If these individual simplifications don't make sense on their own, we'd have to consider the removal in one much larger step - which I'd prefer to avoid since I expect more pushback there and want to find if there's a simpler set that we would mostly agree on.

@ajtowns

ajtowns commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

If your end state is "remove assumeutxo altogether" then this would be a step in that direction, though I believe describing that as just "remove the dual-chainstate implemention" is deceptive.

If the aim is to continue supporting assumeutxo (and improve it) then the steps need to be be "(1) provide a non-dual-chainstate assumeutxo implementation, (2) remove the dual-chainstate assumeutxo implementation", but moving the code to startup only isn't helpful to either step.

@l0rinc

l0rinc commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

moving the code to startup only isn't helpful to either step

It's removing a few corner cases, and I have a few other similar open PRs carving out chunks.
Do you have a better idea how to propose the removal in smaller chunks to find out what the consensus is about this contentious feature?

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.

5 participants