Skip to content

Commit

Permalink
validation: Stricter assumeutxo error handling in LoadChainstate
Browse files Browse the repository at this point in the history
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#27861
  • Loading branch information
ryanofsky committed Jun 15, 2023
1 parent b3db18a commit 9047337
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/init.cpp
Expand Up @@ -1530,7 +1530,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
}
}

if (status == node::ChainstateLoadStatus::FAILURE_INCOMPATIBLE_DB || status == node::ChainstateLoadStatus::FAILURE_INSUFFICIENT_DBCACHE) {
if (status == node::ChainstateLoadStatus::FAILURE_FATAL || status == node::ChainstateLoadStatus::FAILURE_INCOMPATIBLE_DB || status == node::ChainstateLoadStatus::FAILURE_INSUFFICIENT_DBCACHE) {
return InitError(error);
}

Expand Down
2 changes: 1 addition & 1 deletion src/node/chainstate.cpp
Expand Up @@ -207,7 +207,7 @@ ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSize
} else if (snapshot_completion == SnapshotCompletionResult::SUCCESS) {
LogPrintf("[snapshot] cleaning up unneeded background chainstate, then reinitializing\n");
if (!chainman.ValidatedSnapshotCleanup()) {
AbortNode("Background chainstate cleanup failed unexpectedly.");
return {ChainstateLoadStatus::FAILURE_FATAL, Untranslated("Background chainstate cleanup failed unexpectedly.")};
}

// Because ValidatedSnapshotCleanup() has torn down chainstates with
Expand Down
3 changes: 2 additions & 1 deletion src/node/chainstate.h
Expand Up @@ -42,7 +42,8 @@ struct ChainstateLoadOptions {
//! and exit cleanly in the interrupted case.
enum class ChainstateLoadStatus {
SUCCESS,
FAILURE,
FAILURE, //!< Generic failure which reindexing may fix
FAILURE_FATAL, //!< Fatal error which should not prompt to reindex
FAILURE_INCOMPATIBLE_DB,
FAILURE_INSUFFICIENT_DBCACHE,
INTERRUPTED,
Expand Down

0 comments on commit 9047337

Please sign in to comment.