Repository: bitcoin/bitcoin
File: src/init.cpp (C++)

Code before:

        node.chainman = std::make_unique<ChainstateManager>(*Assert(node.shutdown), chainman_opts, blockman_opts);
        ChainstateManager& chainman = *node.chainman;

        // This is defined and set here instead of inline in validation.h to avoid a hard
        // dependency between validation and index/base, since the latter is not in
        // libbitcoinkernel.
        chainman.restart_indexes = [&node]() {
            LogPrintf("[snapshot] restarting indexes\n");

            // Drain the validation interface queue to ensure that the old indexes
            // don't have any pending work.
            Assert(node.validation_signals)->SyncWithValidationInterfaceQueue();

            for (auto* index : node.indexes) {
                index->Interrupt();
                index->Stop();
                if (!(index->Init() && index->StartBackgroundSync())) {
                    LogPrintf("[snapshot] WARNING failed to restart index %s on snapshot chain\n", index->GetName());
                }
            }
        };

        node::ChainstateLoadOptions options;
        options.mempool = Assert(node.mempool.get());
        options.reindex = blockman_opts.reindex;
        options.reindex_chainstate = fReindexChainState;
        options.prune = chainman.m_blockman.IsPruneMode();
        options.check_blocks = args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS);
        options.check_level = args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL);
        options.require_full_verification = args.IsArgSet("-checkblocks") || args.IsArgSet("-checklevel");
        options.coins_error_cb = [] {
            uiInterface.ThreadSafeMessageBox(
                _("Error reading from database, shutting down."),
                "", CClientUIInterface::MSG_ERROR);
        };

        uiInterface.InitMessage(_("Loading block index…").translated);
        const auto load_block_index_start_time{SteadyClock::now()};
        auto catch_exceptions = [](auto&& f) {
            try {
                return f();
            } catch (const std::exception& e) {
                LogPrintf("%s\n", e.what());
                return std::make_tuple(node::ChainstateLoadStatus::FAILURE, _("Error opening block database"));
            }
        };
        auto [status, error] = catch_exceptions([&]{ return LoadChainstate(chainman, cache_sizes, options); });
        if (status == node::ChainstateLoadStatus::SUCCESS) {
            uiInterface.InitMessage(_("Verifying blocks…").translated);
            if (chainman.m_blockman.m_have_pruned && options.check_blocks > MIN_BLOCKS_TO_KEEP) {

Review comment (suggestion):
nit: How about taking the opportunity to nail down the mutability of `ChainstateLoadOptions` for improved readability?
```suggestion
        const node::ChainstateLoadOptions options{
            .mempool = Assert(node.mempool.get()),
            .reindex = blockman_opts.reindex,
            .reindex_chainstate = fReindexChainState,
            .prune = chainman.m_blockman.IsPruneMode(),
            .require_full_verification = args.IsArgSet("-checkblocks") || args.IsArgSet("-checklevel"),
            .check_blocks = args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS),
            .check_level = args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL),
            .coins_error_cb = [] {
                uiInterface.ThreadSafeMessageBox(
                    _("Error reading from database, shutting down."),
                    "", CClientUIInterface::MSG_ERROR);
            },
        };
```

Code after:
    for (bool fLoaded = false; !fLoaded && !ShutdownRequested(node);) {
        node.mempool = std::make_unique<CTxMemPool>(mempool_opts);

        node.chainman = std::make_unique<ChainstateManager>(*Assert(node.shutdown), chainman_opts, blockman_opts);
        ChainstateManager& chainman = *node.chainman;

        // This is defined and set here instead of inline in validation.h to avoid a hard
        // dependency between validation and index/base, since the latter is not in
        // libbitcoinkernel.
        chainman.restart_indexes = [&node]() {
            LogPrintf("[snapshot] restarting indexes\n");

            // Drain the validation interface queue to ensure that the old indexes
            // don't have any pending work.
            Assert(node.validation_signals)->SyncWithValidationInterfaceQueue();

            for (auto* index : node.indexes) {
                index->Interrupt();
                index->Stop();
                if (!(index->Init() && index->StartBackgroundSync())) {
                    LogPrintf("[snapshot] WARNING failed to restart index %s on snapshot chain\n", index->GetName());
                }
            }
        };

        node::ChainstateLoadOptions options;
        options.mempool = Assert(node.mempool.get());
        options.wipe_block_tree_db = do_reindex;
        options.wipe_chainstate_db = do_reindex || do_reindex_chainstate;
        options.prune = chainman.m_blockman.IsPruneMode();
        options.check_blocks = args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS);
        options.check_level = args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL);
        options.require_full_verification = args.IsArgSet("-checkblocks") || args.IsArgSet("-checklevel");
        options.coins_error_cb = [] {
            uiInterface.ThreadSafeMessageBox(
                _("Error reading from database, shutting down."),
                "", CClientUIInterface::MSG_ERROR);
        };

        uiInterface.InitMessage(_("Loading block index…").translated);
        const auto load_block_index_start_time{SteadyClock::now()};
        auto catch_exceptions = [](auto&& f) {
            try {
                return f();
            } catch (const std::exception& e) {
                LogPrintf("%s\n", e.what());
                return std::make_tuple(node::ChainstateLoadStatus::FAILURE, _("Error opening block database"));
            }
        };
        auto [status, error] = catch_exceptions([&]{ return LoadChainstate(chainman, cache_sizes, options); });
        if (status == node::ChainstateLoadStatus::SUCCESS) {