Skip to content

Commit 8f1246e

Browse files
committed
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.
1 parent cd09304 commit 8f1246e

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

src/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ static ChainstateLoadResult InitAndLoadChainstate(
12591259
return f();
12601260
} catch (const std::exception& e) {
12611261
LogError("%s\n", e.what());
1262-
return std::make_tuple(node::ChainstateLoadStatus::FAILURE, _("Error opening block database"));
1262+
return std::make_tuple(node::ChainstateLoadStatus::FAILURE, _("Error loading databases"));
12631263
}
12641264
};
12651265
auto [status, error] = catch_exceptions([&] { return LoadChainstate(chainman, cache_sizes, options); });
@@ -1639,7 +1639,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
16391639
if (status == ChainstateLoadStatus::FAILURE && !do_reindex && !ShutdownRequested(node)) {
16401640
// suggest a reindex
16411641
bool do_retry = uiInterface.ThreadSafeQuestion(
1642-
error + Untranslated(".\n\n") + _("Do you want to rebuild the block database now?"),
1642+
error + Untranslated(".\n\n") + _("Do you want to rebuild the databases now?"),
16431643
error.original + ".\nPlease restart with -reindex or -reindex-chainstate to recover.",
16441644
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
16451645
if (!do_retry) {

src/node/chainstate.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ static ChainstateLoadResult CompleteChainstateInitialization(
4141
// new BlockTreeDB tries to delete the existing file, which
4242
// fails if it's still open from the previous loop. Close it first:
4343
pblocktree.reset();
44-
pblocktree = std::make_unique<BlockTreeDB>(DBParams{
45-
.path = chainman.m_options.datadir / "blocks" / "index",
46-
.cache_bytes = static_cast<size_t>(cache_sizes.block_tree_db),
47-
.memory_only = options.block_tree_db_in_memory,
48-
.wipe_data = options.wipe_block_tree_db,
49-
.options = chainman.m_options.block_tree_db});
44+
try {
45+
pblocktree = std::make_unique<BlockTreeDB>(DBParams{
46+
.path = chainman.m_options.datadir / "blocks" / "index",
47+
.cache_bytes = static_cast<size_t>(cache_sizes.block_tree_db),
48+
.memory_only = options.block_tree_db_in_memory,
49+
.wipe_data = options.wipe_block_tree_db,
50+
.options = chainman.m_options.block_tree_db});
51+
} catch (dbwrapper_error& err) {
52+
LogError("%s\n", err.what());
53+
return {ChainstateLoadStatus::FAILURE, _("Error opening block database")};
54+
}
5055

5156
if (options.wipe_block_tree_db) {
5257
pblocktree->WriteReindexing(true);
@@ -107,10 +112,15 @@ static ChainstateLoadResult CompleteChainstateInitialization(
107112
for (Chainstate* chainstate : chainman.GetAll()) {
108113
LogPrintf("Initializing chainstate %s\n", chainstate->ToString());
109114

110-
chainstate->InitCoinsDB(
111-
/*cache_size_bytes=*/chainman.m_total_coinsdb_cache * init_cache_fraction,
112-
/*in_memory=*/options.coins_db_in_memory,
113-
/*should_wipe=*/options.wipe_chainstate_db);
115+
try {
116+
chainstate->InitCoinsDB(
117+
/*cache_size_bytes=*/chainman.m_total_coinsdb_cache * init_cache_fraction,
118+
/*in_memory=*/options.coins_db_in_memory,
119+
/*should_wipe=*/options.wipe_chainstate_db);
120+
} catch (dbwrapper_error& err) {
121+
LogError("%s\n", err.what());
122+
return {ChainstateLoadStatus::FAILURE, _("Error opening coins database")};
123+
}
114124

115125
if (options.coins_error_cb) {
116126
chainstate->CoinsErrorCatcher().AddReadErrCallback(options.coins_error_cb);

test/functional/feature_init.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ def check_clean_start():
9797

9898
files_to_delete = {
9999
'blocks/index/*.ldb': 'Error opening block database.',
100-
'chainstate/*.ldb': 'Error opening block database.',
100+
'chainstate/*.ldb': 'Error opening coins database.',
101101
'blocks/blk*.dat': 'Error loading block database.',
102102
}
103103

104104
files_to_perturb = {
105105
'blocks/index/*.ldb': 'Error loading block database.',
106-
'chainstate/*.ldb': 'Error opening block database.',
106+
'chainstate/*.ldb': 'Error opening coins database.',
107107
'blocks/blk*.dat': 'Corrupted block database detected.',
108108
}
109109

0 commit comments

Comments
 (0)