@@ -1057,6 +1057,10 @@ bool AppInitParameterInteraction(const ArgsManager& args)
10571057 .chainparams = chainman_opts_dummy.chainparams ,
10581058 .blocks_dir = args.GetBlocksDirPath (),
10591059 .notifications = chainman_opts_dummy.notifications ,
1060+ .block_tree_db_params = DBParams{
1061+ .path = args.GetDataDirNet () / " blocks" / " index" ,
1062+ .cache_bytes = 0 ,
1063+ },
10601064 };
10611065 auto blockman_result{ApplyArgsManOptions (args, blockman_opts_dummy)};
10621066 if (!blockman_result) {
@@ -1199,18 +1203,33 @@ static ChainstateLoadResult InitAndLoadChainstate(
11991203 .signals = node.validation_signals .get (),
12001204 };
12011205 Assert (ApplyArgsManOptions (args, chainman_opts)); // no error can happen, already checked in AppInitParameterInteraction
1206+
12021207 BlockManager::Options blockman_opts{
12031208 .chainparams = chainman_opts.chainparams ,
12041209 .blocks_dir = args.GetBlocksDirPath (),
12051210 .notifications = chainman_opts.notifications ,
1211+ .block_tree_db_params = DBParams{
1212+ .path = args.GetDataDirNet () / " blocks" / " index" ,
1213+ .cache_bytes = cache_sizes.block_tree_db ,
1214+ .wipe_data = do_reindex,
1215+ },
12061216 };
12071217 Assert (ApplyArgsManOptions (args, blockman_opts)); // no error can happen, already checked in AppInitParameterInteraction
1218+
1219+ // Creating the chainstate manager internally creates a BlockManager, opens
1220+ // the blocks tree db, and wipes existing block files in case of a reindex.
1221+ // The coinsdb is opened at a later point on LoadChainstate.
12081222 try {
12091223 node.chainman = std::make_unique<ChainstateManager>(*Assert (node.shutdown_signal ), chainman_opts, blockman_opts);
1224+ } catch (dbwrapper_error& e) {
1225+ LogError (" %s\n " , e.what ());
1226+ return {ChainstateLoadStatus::FAILURE, _ (" Error opening block database" )};
12101227 } catch (std::exception& e) {
12111228 return {ChainstateLoadStatus::FAILURE_FATAL, Untranslated (strprintf (" Failed to initialize ChainstateManager: %s" , e.what ()))};
12121229 }
12131230 ChainstateManager& chainman = *node.chainman ;
1231+ if (chainman.m_interrupt ) return {ChainstateLoadStatus::INTERRUPTED, {}};
1232+
12141233 // This is defined and set here instead of inline in validation.h to avoid a hard
12151234 // dependency between validation and index/base, since the latter is not in
12161235 // libbitcoinkernel.
@@ -1233,7 +1252,6 @@ static ChainstateLoadResult InitAndLoadChainstate(
12331252 };
12341253 node::ChainstateLoadOptions options;
12351254 options.mempool = Assert (node.mempool .get ());
1236- options.wipe_block_tree_db = do_reindex;
12371255 options.wipe_chainstate_db = do_reindex || do_reindex_chainstate;
12381256 options.prune = chainman.m_blockman .IsPruneMode ();
12391257 options.check_blocks = args.GetIntArg (" -checkblocks" , DEFAULT_CHECKBLOCKS);
0 commit comments