MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / InvalidateCoinsDBOnDisk

Method InvalidateCoinsDBOnDisk

src/validation.cpp:6220–6250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6218}
6219
6220util::Result<void> Chainstate::InvalidateCoinsDBOnDisk()
6221{
6222 // Should never be called on a non-snapshot chainstate.
6223 assert(m_from_snapshot_blockhash);
6224
6225 // Coins views no longer usable.
6226 m_coins_views.reset();
6227
6228 const fs::path db_path{StoragePath()};
6229 const fs::path invalid_path{db_path + "_INVALID"};
6230 const std::string db_path_str{fs::PathToString(db_path)};
6231 const std::string invalid_path_str{fs::PathToString(invalid_path)};
6232 LogInfo("[snapshot] renaming snapshot datadir %s to %s", db_path_str, invalid_path_str);
6233
6234 // The invalid storage directory is simply moved and not deleted because we may
6235 // want to do forensics later during issue investigation. The user is instructed
6236 // accordingly in MaybeValidateSnapshot().
6237 try {
6238 fs::rename(db_path, invalid_path);
6239 } catch (const fs::filesystem_error& e) {
6240 LogError("While invalidating the coins db: Error renaming file '%s' -> '%s': %s",
6241 db_path_str, invalid_path_str, e.what());
6242 return util::Error{strprintf(_(
6243 "Rename of '%s' -> '%s' failed. "
6244 "You should resolve this by manually moving or deleting the invalid "
6245 "snapshot directory %s, otherwise you will encounter the same error again "
6246 "on the next startup."),
6247 db_path_str, invalid_path_str, db_path_str)};
6248 }
6249 return {};
6250}
6251
6252bool ChainstateManager::DeleteChainstate(Chainstate& chainstate)
6253{

Callers 1

MaybeValidateSnapshotMethod · 0.80

Calls 4

PathToStringFunction · 0.85
_Function · 0.85
resetMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected