mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
refactor: Pass chainstate parameters to MaybeCompleteSnapshotValidation
Remove hardcoded references to m_ibd_chainstate and m_snapshot_chainstate so MaybeCompleteSnapshotValidation function can be simpler and focus on validating the snapshot without dealing with internal ChainstateManager states. This is a step towards being able to validate the snapshot outside of ActivateBestChain loop so cs_main is not locked for minutes when the snapshot block is connected.
This commit is contained in:
@@ -169,15 +169,16 @@ ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSize
|
||||
Chainstate& validated_cs{chainman.InitializeChainstate(options.mempool)};
|
||||
|
||||
// Load a chain created from a UTXO snapshot, if any exist.
|
||||
bool has_snapshot = chainman.DetectSnapshotChainstate();
|
||||
Chainstate* assumeutxo_cs{chainman.LoadAssumeutxoChainstate()};
|
||||
|
||||
if (has_snapshot && options.wipe_chainstate_db) {
|
||||
if (assumeutxo_cs && options.wipe_chainstate_db) {
|
||||
// Reset chainstate target to network tip instead of snapshot block.
|
||||
validated_cs.SetTargetBlock(nullptr);
|
||||
LogInfo("[snapshot] deleting snapshot chainstate due to reindexing");
|
||||
if (!chainman.DeleteSnapshotChainstate()) {
|
||||
return {ChainstateLoadStatus::FAILURE_FATAL, Untranslated("Couldn't remove snapshot chainstate.")};
|
||||
}
|
||||
assumeutxo_cs = nullptr;
|
||||
}
|
||||
|
||||
auto [init_status, init_error] = CompleteChainstateInitialization(chainman, options);
|
||||
@@ -193,7 +194,9 @@ ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSize
|
||||
// snapshot is actually validated? Because this entails unusual
|
||||
// filesystem operations to move leveldb data directories around, and that seems
|
||||
// too risky to do in the middle of normal runtime.
|
||||
auto snapshot_completion = chainman.MaybeCompleteSnapshotValidation();
|
||||
auto snapshot_completion{assumeutxo_cs
|
||||
? chainman.MaybeValidateSnapshot(validated_cs, *assumeutxo_cs)
|
||||
: SnapshotCompletionResult::SKIPPED};
|
||||
|
||||
if (snapshot_completion == SnapshotCompletionResult::SKIPPED) {
|
||||
// do nothing; expected case
|
||||
|
||||
@@ -81,7 +81,7 @@ std::optional<uint256> ReadSnapshotBaseBlockhash(fs::path chaindir)
|
||||
return base_blockhash;
|
||||
}
|
||||
|
||||
std::optional<fs::path> FindSnapshotChainstateDir(const fs::path& data_dir)
|
||||
std::optional<fs::path> FindAssumeutxoChainstateDir(const fs::path& data_dir)
|
||||
{
|
||||
fs::path possible_dir =
|
||||
data_dir / fs::u8path(strprintf("chainstate%s", SNAPSHOT_CHAINSTATE_SUFFIX));
|
||||
|
||||
@@ -125,7 +125,7 @@ constexpr std::string_view SNAPSHOT_CHAINSTATE_SUFFIX = "_snapshot";
|
||||
|
||||
|
||||
//! Return a path to the snapshot-based chainstate dir, if one exists.
|
||||
std::optional<fs::path> FindSnapshotChainstateDir(const fs::path& data_dir);
|
||||
std::optional<fs::path> FindAssumeutxoChainstateDir(const fs::path& data_dir);
|
||||
|
||||
} // namespace node
|
||||
|
||||
|
||||
Reference in New Issue
Block a user