diff --git a/src/init.cpp b/src/init.cpp index 8d8186200b..23632d288d 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -335,15 +335,8 @@ void PrepareShutdown(NodeContext& node) chainstate->ResetCoinsViews(); } } - node.chain_helper.reset(); - if (node.mnhf_manager) { - node.mnhf_manager->DisconnectManagers(); - } - node.llmq_ctx.reset(); - llmq::quorumSnapshotManager.reset(); - node.mempool->DisconnectManagers(); - node.dmnman.reset(); - node.cpoolman.reset(); + DashChainstateSetupClose(node.chain_helper, node.cpoolman, node.dmnman, node.mnhf_manager, + llmq::quorumSnapshotManager, node.llmq_ctx, Assert(node.mempool.get())); node.mnhf_manager.reset(); node.evodb.reset(); } diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp index 9835c8960d..f831d11eb5 100644 --- a/src/node/chainstate.cpp +++ b/src/node/chainstate.cpp @@ -77,30 +77,9 @@ std::optional LoadChainstate(bool fReset, pblocktree.reset(); pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, block_tree_db_in_memory, fReset)); - // Same logic as above with pblocktree - dmnman.reset(); - dmnman = std::make_unique(chainman.ActiveChainstate(), *evodb); - mempool->ConnectManagers(dmnman.get()); - - cpoolman.reset(); - cpoolman = std::make_unique(*evodb); - - qsnapman.reset(); - qsnapman.reset(new llmq::CQuorumSnapshotManager(*evodb)); - - if (llmq_ctx) { - llmq_ctx->Interrupt(); - llmq_ctx->Stop(); - } - llmq_ctx.reset(); - llmq_ctx = std::make_unique(chainman, *dmnman, *evodb, mn_metaman, *mnhf_manager, sporkman, - *mempool, mn_activeman.get(), mn_sync, /*unit_tests=*/false, /*wipe=*/fReset || fReindexChainState); - // Enable CMNHFManager::{Process, Undo}Block - mnhf_manager->ConnectManagers(&chainman, llmq_ctx->qman.get()); - - chain_helper.reset(); - chain_helper = std::make_unique(*cpoolman, *dmnman, *mnhf_manager, govman, *(llmq_ctx->quorum_block_processor), chainman, - consensus_params, mn_sync, sporkman, *(llmq_ctx->clhandler), *(llmq_ctx->qman)); + DashChainstateSetup(chainman, govman, mn_metaman, mn_sync, sporkman, mn_activeman, chain_helper, cpoolman, + dmnman, evodb, mnhf_manager, qsnapman, llmq_ctx, mempool, fReset, fReindexChainState, + consensus_params); if (fReset) { pblocktree->WriteReindexing(true); @@ -229,6 +208,70 @@ std::optional LoadChainstate(bool fReset, return std::nullopt; } +void DashChainstateSetup(ChainstateManager& chainman, + CGovernanceManager& govman, + CMasternodeMetaMan& mn_metaman, + CMasternodeSync& mn_sync, + CSporkManager& sporkman, + std::unique_ptr& mn_activeman, + std::unique_ptr& chain_helper, + std::unique_ptr& cpoolman, + std::unique_ptr& dmnman, + std::unique_ptr& evodb, + std::unique_ptr& mnhf_manager, + std::unique_ptr& qsnapman, + std::unique_ptr& llmq_ctx, + CTxMemPool* mempool, + bool fReset, + bool fReindexChainState, + const Consensus::Params& consensus_params) +{ + // Same logic as pblocktree + dmnman.reset(); + dmnman = std::make_unique(chainman.ActiveChainstate(), *evodb); + mempool->ConnectManagers(dmnman.get()); + + cpoolman.reset(); + cpoolman = std::make_unique(*evodb); + + qsnapman.reset(); + qsnapman.reset(new llmq::CQuorumSnapshotManager(*evodb)); + + if (llmq_ctx) { + llmq_ctx->Interrupt(); + llmq_ctx->Stop(); + } + llmq_ctx.reset(); + llmq_ctx = std::make_unique(chainman, *dmnman, *evodb, mn_metaman, *mnhf_manager, sporkman, + *mempool, mn_activeman.get(), mn_sync, /*unit_tests=*/false, /*wipe=*/fReset || fReindexChainState); + // Enable CMNHFManager::{Process, Undo}Block + mnhf_manager->ConnectManagers(&chainman, llmq_ctx->qman.get()); + + chain_helper.reset(); + chain_helper = std::make_unique(*cpoolman, *dmnman, *mnhf_manager, govman, *(llmq_ctx->quorum_block_processor), chainman, + consensus_params, mn_sync, sporkman, *(llmq_ctx->clhandler), *(llmq_ctx->qman)); +} + +void DashChainstateSetupClose(std::unique_ptr& chain_helper, + std::unique_ptr& cpoolman, + std::unique_ptr& dmnman, + std::unique_ptr& mnhf_manager, + std::unique_ptr& qsnapman, + std::unique_ptr& llmq_ctx, + CTxMemPool* mempool) + +{ + chain_helper.reset(); + if (mnhf_manager) { + mnhf_manager->DisconnectManagers(); + } + llmq_ctx.reset(); + qsnapman.reset(); + cpoolman.reset(); + mempool->DisconnectManagers(); + dmnman.reset(); +} + std::optional VerifyLoadedChainstate(ChainstateManager& chainman, CEvoDB& evodb, bool fReset, diff --git a/src/node/chainstate.h b/src/node/chainstate.h index b7f2942869..e85c4a7a76 100644 --- a/src/node/chainstate.h +++ b/src/node/chainstate.h @@ -115,6 +115,33 @@ std::optional LoadChainstate(bool fReset, std::function shutdown_requested = nullptr, std::function coins_error_cb = nullptr); +/** Initialize Dash-specific components during chainstate initialization */ +void DashChainstateSetup(ChainstateManager& chainman, + CGovernanceManager& govman, + CMasternodeMetaMan& mn_metaman, + CMasternodeSync& mn_sync, + CSporkManager& sporkman, + std::unique_ptr& mn_activeman, + std::unique_ptr& chain_helper, + std::unique_ptr& cpoolman, + std::unique_ptr& dmnman, + std::unique_ptr& evodb, + std::unique_ptr& mnhf_manager, + std::unique_ptr& qsnapman, + std::unique_ptr& llmq_ctx, + CTxMemPool* mempool, + bool fReset, + bool fReindexChainState, + const Consensus::Params& consensus_params); + +void DashChainstateSetupClose(std::unique_ptr& chain_helper, + std::unique_ptr& cpoolman, + std::unique_ptr& dmnman, + std::unique_ptr& mnhf_manager, + std::unique_ptr& qsnapman, + std::unique_ptr& llmq_ctx, + CTxMemPool* mempool); + enum class ChainstateLoadVerifyError { ERROR_BLOCK_FROM_FUTURE, ERROR_CORRUPTED_BLOCK_DB,