mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
node/chainstate: extract Dash post-InitializeChainstate
logic
This commit is contained in:
parent
c06e07461e
commit
459f33983b
11
src/init.cpp
11
src/init.cpp
@ -335,15 +335,8 @@ void PrepareShutdown(NodeContext& node)
|
|||||||
chainstate->ResetCoinsViews();
|
chainstate->ResetCoinsViews();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node.chain_helper.reset();
|
DashChainstateSetupClose(node.chain_helper, node.cpoolman, node.dmnman, node.mnhf_manager,
|
||||||
if (node.mnhf_manager) {
|
llmq::quorumSnapshotManager, node.llmq_ctx, Assert(node.mempool.get()));
|
||||||
node.mnhf_manager->DisconnectManagers();
|
|
||||||
}
|
|
||||||
node.llmq_ctx.reset();
|
|
||||||
llmq::quorumSnapshotManager.reset();
|
|
||||||
node.mempool->DisconnectManagers();
|
|
||||||
node.dmnman.reset();
|
|
||||||
node.cpoolman.reset();
|
|
||||||
node.mnhf_manager.reset();
|
node.mnhf_manager.reset();
|
||||||
node.evodb.reset();
|
node.evodb.reset();
|
||||||
}
|
}
|
||||||
|
@ -77,30 +77,9 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
|||||||
pblocktree.reset();
|
pblocktree.reset();
|
||||||
pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, block_tree_db_in_memory, fReset));
|
pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, block_tree_db_in_memory, fReset));
|
||||||
|
|
||||||
// Same logic as above with pblocktree
|
DashChainstateSetup(chainman, govman, mn_metaman, mn_sync, sporkman, mn_activeman, chain_helper, cpoolman,
|
||||||
dmnman.reset();
|
dmnman, evodb, mnhf_manager, qsnapman, llmq_ctx, mempool, fReset, fReindexChainState,
|
||||||
dmnman = std::make_unique<CDeterministicMNManager>(chainman.ActiveChainstate(), *evodb);
|
consensus_params);
|
||||||
mempool->ConnectManagers(dmnman.get());
|
|
||||||
|
|
||||||
cpoolman.reset();
|
|
||||||
cpoolman = std::make_unique<CCreditPoolManager>(*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<LLMQContext>(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<CChainstateHelper>(*cpoolman, *dmnman, *mnhf_manager, govman, *(llmq_ctx->quorum_block_processor), chainman,
|
|
||||||
consensus_params, mn_sync, sporkman, *(llmq_ctx->clhandler), *(llmq_ctx->qman));
|
|
||||||
|
|
||||||
if (fReset) {
|
if (fReset) {
|
||||||
pblocktree->WriteReindexing(true);
|
pblocktree->WriteReindexing(true);
|
||||||
@ -229,6 +208,70 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
|||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DashChainstateSetup(ChainstateManager& chainman,
|
||||||
|
CGovernanceManager& govman,
|
||||||
|
CMasternodeMetaMan& mn_metaman,
|
||||||
|
CMasternodeSync& mn_sync,
|
||||||
|
CSporkManager& sporkman,
|
||||||
|
std::unique_ptr<CActiveMasternodeManager>& mn_activeman,
|
||||||
|
std::unique_ptr<CChainstateHelper>& chain_helper,
|
||||||
|
std::unique_ptr<CCreditPoolManager>& cpoolman,
|
||||||
|
std::unique_ptr<CDeterministicMNManager>& dmnman,
|
||||||
|
std::unique_ptr<CEvoDB>& evodb,
|
||||||
|
std::unique_ptr<CMNHFManager>& mnhf_manager,
|
||||||
|
std::unique_ptr<llmq::CQuorumSnapshotManager>& qsnapman,
|
||||||
|
std::unique_ptr<LLMQContext>& llmq_ctx,
|
||||||
|
CTxMemPool* mempool,
|
||||||
|
bool fReset,
|
||||||
|
bool fReindexChainState,
|
||||||
|
const Consensus::Params& consensus_params)
|
||||||
|
{
|
||||||
|
// Same logic as pblocktree
|
||||||
|
dmnman.reset();
|
||||||
|
dmnman = std::make_unique<CDeterministicMNManager>(chainman.ActiveChainstate(), *evodb);
|
||||||
|
mempool->ConnectManagers(dmnman.get());
|
||||||
|
|
||||||
|
cpoolman.reset();
|
||||||
|
cpoolman = std::make_unique<CCreditPoolManager>(*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<LLMQContext>(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<CChainstateHelper>(*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<CChainstateHelper>& chain_helper,
|
||||||
|
std::unique_ptr<CCreditPoolManager>& cpoolman,
|
||||||
|
std::unique_ptr<CDeterministicMNManager>& dmnman,
|
||||||
|
std::unique_ptr<CMNHFManager>& mnhf_manager,
|
||||||
|
std::unique_ptr<llmq::CQuorumSnapshotManager>& qsnapman,
|
||||||
|
std::unique_ptr<LLMQContext>& 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<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManager& chainman,
|
std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManager& chainman,
|
||||||
CEvoDB& evodb,
|
CEvoDB& evodb,
|
||||||
bool fReset,
|
bool fReset,
|
||||||
|
@ -115,6 +115,33 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
|||||||
std::function<bool()> shutdown_requested = nullptr,
|
std::function<bool()> shutdown_requested = nullptr,
|
||||||
std::function<void()> coins_error_cb = nullptr);
|
std::function<void()> 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<CActiveMasternodeManager>& mn_activeman,
|
||||||
|
std::unique_ptr<CChainstateHelper>& chain_helper,
|
||||||
|
std::unique_ptr<CCreditPoolManager>& cpoolman,
|
||||||
|
std::unique_ptr<CDeterministicMNManager>& dmnman,
|
||||||
|
std::unique_ptr<CEvoDB>& evodb,
|
||||||
|
std::unique_ptr<CMNHFManager>& mnhf_manager,
|
||||||
|
std::unique_ptr<llmq::CQuorumSnapshotManager>& qsnapman,
|
||||||
|
std::unique_ptr<LLMQContext>& llmq_ctx,
|
||||||
|
CTxMemPool* mempool,
|
||||||
|
bool fReset,
|
||||||
|
bool fReindexChainState,
|
||||||
|
const Consensus::Params& consensus_params);
|
||||||
|
|
||||||
|
void DashChainstateSetupClose(std::unique_ptr<CChainstateHelper>& chain_helper,
|
||||||
|
std::unique_ptr<CCreditPoolManager>& cpoolman,
|
||||||
|
std::unique_ptr<CDeterministicMNManager>& dmnman,
|
||||||
|
std::unique_ptr<CMNHFManager>& mnhf_manager,
|
||||||
|
std::unique_ptr<llmq::CQuorumSnapshotManager>& qsnapman,
|
||||||
|
std::unique_ptr<LLMQContext>& llmq_ctx,
|
||||||
|
CTxMemPool* mempool);
|
||||||
|
|
||||||
enum class ChainstateLoadVerifyError {
|
enum class ChainstateLoadVerifyError {
|
||||||
ERROR_BLOCK_FROM_FUTURE,
|
ERROR_BLOCK_FROM_FUTURE,
|
||||||
ERROR_CORRUPTED_BLOCK_DB,
|
ERROR_CORRUPTED_BLOCK_DB,
|
||||||
|
Loading…
Reference in New Issue
Block a user