mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
validation: remove snapshot datadirs upon validation failure
If a UTXO snapshot fails to validate, don't leave the resulting datadir on disk as this will confuse initialization on next startup and we'll get an assertion error.
This commit is contained in:
parent
34d1590331
commit
ad67ff377c
1 changed files with 16 additions and 1 deletions
|
@ -4876,7 +4876,22 @@ bool ChainstateManager::ActivateSnapshot(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!snapshot_ok) {
|
if (!snapshot_ok) {
|
||||||
WITH_LOCK(::cs_main, this->MaybeRebalanceCaches());
|
LOCK(::cs_main);
|
||||||
|
this->MaybeRebalanceCaches();
|
||||||
|
|
||||||
|
// PopulateAndValidateSnapshot can return (in error) before the leveldb datadir
|
||||||
|
// has been created, so only attempt removal if we got that far.
|
||||||
|
if (auto snapshot_datadir = node::FindSnapshotChainstateDir()) {
|
||||||
|
// We have to destruct leveldb::DB in order to release the db lock, otherwise
|
||||||
|
// DestroyDB() (in DeleteCoinsDBFromDisk()) will fail. See `leveldb::~DBImpl()`.
|
||||||
|
// Destructing the chainstate (and so resetting the coinsviews object) does this.
|
||||||
|
snapshot_chainstate.reset();
|
||||||
|
bool removed = DeleteCoinsDBFromDisk(*snapshot_datadir, /*is_snapshot=*/true);
|
||||||
|
if (!removed) {
|
||||||
|
AbortNode(strprintf("Failed to remove snapshot chainstate dir (%s). "
|
||||||
|
"Manually remove it before restarting.\n", fs::PathToString(*snapshot_datadir)));
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue