AssumeUTXO: allow retrying loadtxoutset after an interrupted load #36542

Closed
l0rinc wants to merge 2 commits from l0rinc/assumeutxo-recover-cleanup into master AGit
l0rinc commented 2026-10-15 11:35:04 +00:00 (Migrated from github.com)

Problem: An interrupted loadtxoutset can leave an incomplete chainstate_snapshot database without its required base_blockhash marker. A later call can fail to open that database, requiring the operator to remove it manually before retrying.

Fix: Wipe the snapshot database before opening it so a later call can replace incomplete data. LevelDB acquires the database lock before deleting files, so a database held open by another load cannot be wiped. Also correct the startup warning to identify the missing marker and explain that retrying replaces the directory.

**Problem:** An interrupted `loadtxoutset` can leave an incomplete `chainstate_snapshot` database without its required `base_blockhash` marker. A later call can fail to open that database, requiring the operator to remove it manually before retrying. **Fix:** Wipe the snapshot database before opening it so a later call can replace incomplete data. LevelDB acquires the database lock before deleting files, so a database held open by another load cannot be wiped. Also correct the startup warning to identify the missing marker and explain that retrying replaces the directory.
DrahtBot commented 2026-10-15 11:35:13 +00:00 (Migrated from github.com)

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
ACK cyb3ralbert

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:

  • #36990 (test: replace hard-coded RPC error codes by l0rinc)
  • #36778 (AssumeUTXO: replace loadtxoutset RPC with a startup arg by l0rinc)
  • #36603 (Improve loadtxoutset performance by ajtowns)
  • #36598 ([Demo] validation: remove AssumeUTXO 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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36542 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36542.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36542#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [cyb3ralbert](https://github.com/bitcoin/bitcoin/pull/36542#issuecomment-6497227759) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36990](https://github.com/bitcoin/bitcoin/pull/36990) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36990.svg"></sub> (test: replace hard-coded RPC error codes by l0rinc) * [#36778](https://github.com/bitcoin/bitcoin/pull/36778) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36778.svg"></sub> (AssumeUTXO: replace `loadtxoutset` RPC with a startup arg by l0rinc) * [#36603](https://github.com/bitcoin/bitcoin/pull/36603) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36603.svg"></sub> (Improve loadtxoutset performance by ajtowns) * [#36598](https://github.com/bitcoin/bitcoin/pull/36598) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36598.svg"></sub> ([Demo] validation: remove AssumeUTXO 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. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

🔵 Suggestion · Startup warning omits manual cleanup for abandoned snapshot loads

If the operator abandons the snapshot or a retry fails before database initialization, the warning provides no cleanup option for the unused directory, which remains on disk and triggers warnings on later startups.

Location: src/node/utxo_snapshot.cpp:60 (head).

🔵 Suggestion · Retry coverage stops before successful snapshot activation

The new malformed-directory fixture tests opening and failure cleanup, not successful activation after replacement or the corrected missing-marker startup warning.

Location: test/functional/feature_assumeutxo.py:221 (head).

🔵 Suggestion · Snapshot wipe omits its lock-based safety rationale

The new on-disk wipe relies on LevelDB acquiring the database lock before deleting files, but the call site does not explain that safety requirement or why replacement is needed.

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

Review coverage was incomplete.


Reviewed: 15a891d4021e · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:8541d3fafd3ea45d3ad824914bf78a806527457ae4801671a2c4a580beddb288:1e657457416e20a18d8d2d136919c48e28e1bfed7a76c26939ab1ca10a232c6a --> <!-- ralph-base:ab7e668cc6af5d716ad40166d1f88235a2f6d25d --> <!-- ralph-head:15a891d4021e0cf8c009127721ee1f1702dd9471 --> <!-- ralph-case:4c897591d92822464353b40c22f70241ecdceb30c5cc8f4b087a20d18a9c4aea --> **🔵 Suggestion · Startup warning omits manual cleanup for abandoned snapshot loads** If the operator abandons the snapshot or a retry fails before database initialization, the warning provides no cleanup option for the unused directory, which remains on disk and triggers warnings on later startups. Location: [`src/node/utxo_snapshot.cpp:60`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/15a891d4021e0cf8c009127721ee1f1702dd9471/src/node/utxo_snapshot.cpp#L60>) (head). **🔵 Suggestion · Retry coverage stops before successful snapshot activation** The new malformed-directory fixture tests opening and failure cleanup, not successful activation after replacement or the corrected missing-marker startup warning. Location: [`test/functional/feature_assumeutxo.py:221`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/15a891d4021e0cf8c009127721ee1f1702dd9471/test/functional/feature_assumeutxo.py#L221>) (head). **🔵 Suggestion · Snapshot wipe omits its lock-based safety rationale** The new on-disk wipe relies on LevelDB acquiring the database lock before deleting files, but the call site does not explain that safety requirement or why replacement is needed. Location: [`src/validation.cpp:5690`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/15a891d4021e0cf8c009127721ee1f1702dd9471/src/validation.cpp#L5690>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`15a891d4021e`](<https://git.fish.foo/bitcoin/bitcoin/commit/15a891d4021e0cf8c009127721ee1f1702dd9471>) · [Full review report](<https://review.fish.foo/traces/36542-15a891d4021e0cf8c009127721ee1f1702dd9471-1870-6.html>) · [Previous reports](<https://review.fish.foo/traces/36542/>) [permalink](<https://review.fish.foo/traces/36542-15a891d4021e0cf8c009127721ee1f1702dd9471-1870-6.html>)
l0rinc commented 2026-10-21 09:05:47 +00:00 (Migrated from github.com)

Found a simpler fix using the existing database wipe option, which lets interrupted loads be retried.

Found a simpler fix using the existing database wipe option, which lets interrupted loads be retried.
cyb3ralbert commented 2026-10-29 12:54:17 +00:00 (Migrated from github.com)

Should the regression test also cover a snapshot database whose LOCK is held by another process?

tACK 15a891d402

Tested on Linux aarch64 (Debian 13, GCC 14.2.0):

  • restart-retry-pruned, restart-retry-default, readable-leftover-retry, and locked-leftover-retry passed. The locked case returned RPC error -1, left the database files unchanged, and the retry succeeded after the lock was released.
  • feature_assumeutxo.py passed in a direct slot run on the same head.
Should the regression test also cover a snapshot database whose LOCK is held by another process? tACK 15a891d4021e0cf8c009127721ee1f1702dd9471 Tested on Linux aarch64 (Debian 13, GCC 14.2.0): - `restart-retry-pruned`, `restart-retry-default`, `readable-leftover-retry`, and `locked-leftover-retry` passed. The locked case returned RPC error `-1`, left the database files unchanged, and the retry succeeded after the lock was released. - `feature_assumeutxo.py` passed in a direct slot run on the same head.
l0rinc commented 2026-12-02 20:16:41 +00:00 (Migrated from github.com)

Closing in favor of #36598

Closing in favor of #36598
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36542
No description provided.