@@ -41,12 +41,17 @@ static ChainstateLoadResult CompleteChainstateInitialization(
41
41
// new BlockTreeDB tries to delete the existing file, which
42
42
// fails if it's still open from the previous loop. Close it first:
43
43
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
+ }
50
55
51
56
if (options.wipe_block_tree_db ) {
52
57
pblocktree->WriteReindexing (true );
@@ -107,10 +112,15 @@ static ChainstateLoadResult CompleteChainstateInitialization(
107
112
for (Chainstate* chainstate : chainman.GetAll ()) {
108
113
LogPrintf (" Initializing chainstate %s\n " , chainstate->ToString ());
109
114
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
+ }
114
124
115
125
if (options.coins_error_cb ) {
116
126
chainstate->CoinsErrorCatcher ().AddReadErrCallback (options.coins_error_cb );
0 commit comments