@@ -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 );
0 commit comments