mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
init: Improve chainstate init db error messages
They should name the correct source of an error, or be generic if no clear source can be ascertained.
This commit is contained in:
parent
cd093049dd
commit
8f1246e833
3 changed files with 24 additions and 14 deletions
|
@ -1259,7 +1259,7 @@ static ChainstateLoadResult InitAndLoadChainstate(
|
||||||
return f();
|
return f();
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
LogError("%s\n", e.what());
|
LogError("%s\n", e.what());
|
||||||
return std::make_tuple(node::ChainstateLoadStatus::FAILURE, _("Error opening block database"));
|
return std::make_tuple(node::ChainstateLoadStatus::FAILURE, _("Error loading databases"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
auto [status, error] = catch_exceptions([&] { return LoadChainstate(chainman, cache_sizes, options); });
|
auto [status, error] = catch_exceptions([&] { return LoadChainstate(chainman, cache_sizes, options); });
|
||||||
|
@ -1639,7 +1639,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
if (status == ChainstateLoadStatus::FAILURE && !do_reindex && !ShutdownRequested(node)) {
|
if (status == ChainstateLoadStatus::FAILURE && !do_reindex && !ShutdownRequested(node)) {
|
||||||
// suggest a reindex
|
// suggest a reindex
|
||||||
bool do_retry = uiInterface.ThreadSafeQuestion(
|
bool do_retry = uiInterface.ThreadSafeQuestion(
|
||||||
error + Untranslated(".\n\n") + _("Do you want to rebuild the block database now?"),
|
error + Untranslated(".\n\n") + _("Do you want to rebuild the databases now?"),
|
||||||
error.original + ".\nPlease restart with -reindex or -reindex-chainstate to recover.",
|
error.original + ".\nPlease restart with -reindex or -reindex-chainstate to recover.",
|
||||||
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
|
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
|
||||||
if (!do_retry) {
|
if (!do_retry) {
|
||||||
|
|
|
@ -41,12 +41,17 @@ static ChainstateLoadResult CompleteChainstateInitialization(
|
||||||
// new BlockTreeDB tries to delete the existing file, which
|
// new BlockTreeDB tries to delete the existing file, which
|
||||||
// fails if it's still open from the previous loop. Close it first:
|
// fails if it's still open from the previous loop. Close it first:
|
||||||
pblocktree.reset();
|
pblocktree.reset();
|
||||||
pblocktree = std::make_unique<BlockTreeDB>(DBParams{
|
try {
|
||||||
.path = chainman.m_options.datadir / "blocks" / "index",
|
pblocktree = std::make_unique<BlockTreeDB>(DBParams{
|
||||||
.cache_bytes = static_cast<size_t>(cache_sizes.block_tree_db),
|
.path = chainman.m_options.datadir / "blocks" / "index",
|
||||||
.memory_only = options.block_tree_db_in_memory,
|
.cache_bytes = static_cast<size_t>(cache_sizes.block_tree_db),
|
||||||
.wipe_data = options.wipe_block_tree_db,
|
.memory_only = options.block_tree_db_in_memory,
|
||||||
.options = chainman.m_options.block_tree_db});
|
.wipe_data = options.wipe_block_tree_db,
|
||||||
|
.options = chainman.m_options.block_tree_db});
|
||||||
|
} catch (dbwrapper_error& err) {
|
||||||
|
LogError("%s\n", err.what());
|
||||||
|
return {ChainstateLoadStatus::FAILURE, _("Error opening block database")};
|
||||||
|
}
|
||||||
|
|
||||||
if (options.wipe_block_tree_db) {
|
if (options.wipe_block_tree_db) {
|
||||||
pblocktree->WriteReindexing(true);
|
pblocktree->WriteReindexing(true);
|
||||||
|
@ -107,10 +112,15 @@ static ChainstateLoadResult CompleteChainstateInitialization(
|
||||||
for (Chainstate* chainstate : chainman.GetAll()) {
|
for (Chainstate* chainstate : chainman.GetAll()) {
|
||||||
LogPrintf("Initializing chainstate %s\n", chainstate->ToString());
|
LogPrintf("Initializing chainstate %s\n", chainstate->ToString());
|
||||||
|
|
||||||
chainstate->InitCoinsDB(
|
try {
|
||||||
/*cache_size_bytes=*/chainman.m_total_coinsdb_cache * init_cache_fraction,
|
chainstate->InitCoinsDB(
|
||||||
/*in_memory=*/options.coins_db_in_memory,
|
/*cache_size_bytes=*/chainman.m_total_coinsdb_cache * init_cache_fraction,
|
||||||
/*should_wipe=*/options.wipe_chainstate_db);
|
/*in_memory=*/options.coins_db_in_memory,
|
||||||
|
/*should_wipe=*/options.wipe_chainstate_db);
|
||||||
|
} catch (dbwrapper_error& err) {
|
||||||
|
LogError("%s\n", err.what());
|
||||||
|
return {ChainstateLoadStatus::FAILURE, _("Error opening coins database")};
|
||||||
|
}
|
||||||
|
|
||||||
if (options.coins_error_cb) {
|
if (options.coins_error_cb) {
|
||||||
chainstate->CoinsErrorCatcher().AddReadErrCallback(options.coins_error_cb);
|
chainstate->CoinsErrorCatcher().AddReadErrCallback(options.coins_error_cb);
|
||||||
|
|
|
@ -97,13 +97,13 @@ class InitStressTest(BitcoinTestFramework):
|
||||||
|
|
||||||
files_to_delete = {
|
files_to_delete = {
|
||||||
'blocks/index/*.ldb': 'Error opening block database.',
|
'blocks/index/*.ldb': 'Error opening block database.',
|
||||||
'chainstate/*.ldb': 'Error opening block database.',
|
'chainstate/*.ldb': 'Error opening coins database.',
|
||||||
'blocks/blk*.dat': 'Error loading block database.',
|
'blocks/blk*.dat': 'Error loading block database.',
|
||||||
}
|
}
|
||||||
|
|
||||||
files_to_perturb = {
|
files_to_perturb = {
|
||||||
'blocks/index/*.ldb': 'Error loading block database.',
|
'blocks/index/*.ldb': 'Error loading block database.',
|
||||||
'chainstate/*.ldb': 'Error opening block database.',
|
'chainstate/*.ldb': 'Error opening coins database.',
|
||||||
'blocks/blk*.dat': 'Corrupted block database detected.',
|
'blocks/blk*.dat': 'Corrupted block database detected.',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue