Skip to content

Commit 9047337

Browse files
committed
validation: Stricter assumeutxo error handling in LoadChainstate
Make LoadChainstate return an explicit error when snapshot validation succeeds, but there is an error trying to replace the background chainstate with the snapshot chainstate. Previously in this case LoadChainstate would trigger a shutdown and return INTERRUPTED, now it will return an actual error code. There's no real change to behavior other than error message being formatted a little differently. Motivation for this change is to replace error handling via callbacks with error handling via return value ahead of bitcoin/bitcoin#27861
1 parent b3db18a commit 9047337

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
15301530
}
15311531
}
15321532

1533-
if (status == node::ChainstateLoadStatus::FAILURE_INCOMPATIBLE_DB || status == node::ChainstateLoadStatus::FAILURE_INSUFFICIENT_DBCACHE) {
1533+
if (status == node::ChainstateLoadStatus::FAILURE_FATAL || status == node::ChainstateLoadStatus::FAILURE_INCOMPATIBLE_DB || status == node::ChainstateLoadStatus::FAILURE_INSUFFICIENT_DBCACHE) {
15341534
return InitError(error);
15351535
}
15361536

src/node/chainstate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSize
207207
} else if (snapshot_completion == SnapshotCompletionResult::SUCCESS) {
208208
LogPrintf("[snapshot] cleaning up unneeded background chainstate, then reinitializing\n");
209209
if (!chainman.ValidatedSnapshotCleanup()) {
210-
AbortNode("Background chainstate cleanup failed unexpectedly.");
210+
return {ChainstateLoadStatus::FAILURE_FATAL, Untranslated("Background chainstate cleanup failed unexpectedly.")};
211211
}
212212

213213
// Because ValidatedSnapshotCleanup() has torn down chainstates with

src/node/chainstate.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ struct ChainstateLoadOptions {
4242
//! and exit cleanly in the interrupted case.
4343
enum class ChainstateLoadStatus {
4444
SUCCESS,
45-
FAILURE,
45+
FAILURE, //!< Generic failure which reindexing may fix
46+
FAILURE_FATAL, //!< Fatal error which should not prompt to reindex
4647
FAILURE_INCOMPATIBLE_DB,
4748
FAILURE_INSUFFICIENT_DBCACHE,
4849
INTERRUPTED,

0 commit comments

Comments
 (0)