mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
node/chainstate: Decouple from concept of NodeContext
This commit is contained in:
parent
ee9d3dd5fc
commit
7071282a2d
16
src/init.cpp
16
src/init.cpp
@ -1867,7 +1867,21 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
|||||||
const auto load_block_index_start_time{SteadyClock::now()};
|
const auto load_block_index_start_time{SteadyClock::now()};
|
||||||
auto rv = LoadChainstate(fReset,
|
auto rv = LoadChainstate(fReset,
|
||||||
chainman,
|
chainman,
|
||||||
node,
|
*node.govman,
|
||||||
|
*node.mn_metaman,
|
||||||
|
*node.mn_sync,
|
||||||
|
*node.sporkman,
|
||||||
|
node.mn_activeman,
|
||||||
|
node.chain_helper,
|
||||||
|
node.cpoolman,
|
||||||
|
node.dmnman,
|
||||||
|
node.evodb,
|
||||||
|
node.mnhf_manager,
|
||||||
|
llmq::chainLocksHandler,
|
||||||
|
llmq::quorumInstantSendManager,
|
||||||
|
llmq::quorumSnapshotManager,
|
||||||
|
node.llmq_ctx,
|
||||||
|
node.mempool.get(),
|
||||||
fPruneMode,
|
fPruneMode,
|
||||||
args.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX),
|
args.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX),
|
||||||
is_governance_enabled,
|
is_governance_enabled,
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include <rpc/blockchain.h> // for RPCNotifyBlockChange
|
#include <rpc/blockchain.h> // for RPCNotifyBlockChange
|
||||||
#include <util/time.h> // for GetTime
|
#include <util/time.h> // for GetTime
|
||||||
#include <node/blockstorage.h> // for CleanupBlockRevFiles, fHavePruned, fReindex
|
#include <node/blockstorage.h> // for CleanupBlockRevFiles, fHavePruned, fReindex
|
||||||
#include <node/context.h> // for NodeContext
|
|
||||||
#include <node/ui_interface.h> // for InitError, uiInterface, and CClientUIInterface member access
|
#include <node/ui_interface.h> // for InitError, uiInterface, and CClientUIInterface member access
|
||||||
#include <shutdown.h> // for ShutdownRequested
|
#include <shutdown.h> // for ShutdownRequested
|
||||||
#include <validation.h> // for a lot of things
|
#include <validation.h> // for a lot of things
|
||||||
@ -26,7 +25,21 @@
|
|||||||
|
|
||||||
std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
||||||
ChainstateManager& chainman,
|
ChainstateManager& chainman,
|
||||||
NodeContext& node,
|
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::CChainLocksHandler>& clhandler,
|
||||||
|
std::unique_ptr<llmq::CInstantSendManager>& isman,
|
||||||
|
std::unique_ptr<llmq::CQuorumSnapshotManager>& qsnapman,
|
||||||
|
std::unique_ptr<LLMQContext>& llmq_ctx,
|
||||||
|
CTxMemPool* mempool,
|
||||||
bool fPruneMode,
|
bool fPruneMode,
|
||||||
bool is_addrindex_enabled,
|
bool is_addrindex_enabled,
|
||||||
bool is_governance_enabled,
|
bool is_governance_enabled,
|
||||||
@ -50,13 +63,13 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
|||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
||||||
int64_t nEvoDbCache{64 * 1024 * 1024}; // TODO
|
int64_t nEvoDbCache{64 * 1024 * 1024}; // TODO
|
||||||
node.evodb.reset();
|
evodb.reset();
|
||||||
node.evodb = std::make_unique<CEvoDB>(nEvoDbCache, false, fReset || fReindexChainState);
|
evodb = std::make_unique<CEvoDB>(nEvoDbCache, false, fReset || fReindexChainState);
|
||||||
|
|
||||||
node.mnhf_manager.reset();
|
mnhf_manager.reset();
|
||||||
node.mnhf_manager = std::make_unique<CMNHFManager>(*node.evodb);
|
mnhf_manager = std::make_unique<CMNHFManager>(*evodb);
|
||||||
|
|
||||||
chainman.InitializeChainstate(Assert(node.mempool.get()), *node.evodb, node.chain_helper, llmq::chainLocksHandler, llmq::quorumInstantSendManager);
|
chainman.InitializeChainstate(Assert(mempool), *evodb, chain_helper, clhandler, isman);
|
||||||
chainman.m_total_coinstip_cache = nCoinCacheUsage;
|
chainman.m_total_coinstip_cache = nCoinCacheUsage;
|
||||||
chainman.m_total_coinsdb_cache = nCoinDBCache;
|
chainman.m_total_coinsdb_cache = nCoinDBCache;
|
||||||
|
|
||||||
@ -67,29 +80,29 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
|||||||
pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, false, fReset));
|
pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, false, fReset));
|
||||||
|
|
||||||
// Same logic as above with pblocktree
|
// Same logic as above with pblocktree
|
||||||
node.dmnman.reset();
|
dmnman.reset();
|
||||||
node.dmnman = std::make_unique<CDeterministicMNManager>(chainman.ActiveChainstate(), *node.evodb);
|
dmnman = std::make_unique<CDeterministicMNManager>(chainman.ActiveChainstate(), *evodb);
|
||||||
node.mempool->ConnectManagers(node.dmnman.get());
|
mempool->ConnectManagers(dmnman.get());
|
||||||
|
|
||||||
node.cpoolman.reset();
|
cpoolman.reset();
|
||||||
node.cpoolman = std::make_unique<CCreditPoolManager>(*node.evodb);
|
cpoolman = std::make_unique<CCreditPoolManager>(*evodb);
|
||||||
|
|
||||||
llmq::quorumSnapshotManager.reset();
|
qsnapman.reset();
|
||||||
llmq::quorumSnapshotManager.reset(new llmq::CQuorumSnapshotManager(*node.evodb));
|
qsnapman.reset(new llmq::CQuorumSnapshotManager(*evodb));
|
||||||
|
|
||||||
if (node.llmq_ctx) {
|
if (llmq_ctx) {
|
||||||
node.llmq_ctx->Interrupt();
|
llmq_ctx->Interrupt();
|
||||||
node.llmq_ctx->Stop();
|
llmq_ctx->Stop();
|
||||||
}
|
}
|
||||||
node.llmq_ctx.reset();
|
llmq_ctx.reset();
|
||||||
node.llmq_ctx = std::make_unique<LLMQContext>(chainman, *node.dmnman, *node.evodb, *node.mn_metaman, *node.mnhf_manager, *node.sporkman,
|
llmq_ctx = std::make_unique<LLMQContext>(chainman, *dmnman, *evodb, mn_metaman, *mnhf_manager, sporkman,
|
||||||
*node.mempool, node.mn_activeman.get(), *node.mn_sync, /*unit_tests=*/false, /*wipe=*/fReset || fReindexChainState);
|
*mempool, mn_activeman.get(), mn_sync, /*unit_tests=*/false, /*wipe=*/fReset || fReindexChainState);
|
||||||
// Enable CMNHFManager::{Process, Undo}Block
|
// Enable CMNHFManager::{Process, Undo}Block
|
||||||
node.mnhf_manager->ConnectManagers(node.chainman.get(), node.llmq_ctx->qman.get());
|
mnhf_manager->ConnectManagers(&chainman, llmq_ctx->qman.get());
|
||||||
|
|
||||||
node.chain_helper.reset();
|
chain_helper.reset();
|
||||||
node.chain_helper = std::make_unique<CChainstateHelper>(*node.cpoolman, *node.dmnman, *node.mnhf_manager, *node.govman, *(node.llmq_ctx->quorum_block_processor), *node.chainman,
|
chain_helper = std::make_unique<CChainstateHelper>(*cpoolman, *dmnman, *mnhf_manager, govman, *(llmq_ctx->quorum_block_processor), chainman,
|
||||||
chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler), *(node.llmq_ctx->qman));
|
chainparams.GetConsensus(), mn_sync, sporkman, *(llmq_ctx->clhandler), *(llmq_ctx->qman));
|
||||||
|
|
||||||
if (fReset) {
|
if (fReset) {
|
||||||
pblocktree->WriteReindexing(true);
|
pblocktree->WriteReindexing(true);
|
||||||
@ -198,7 +211,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
|||||||
// TODO: CEvoDB instance should probably be a part of CChainState
|
// TODO: CEvoDB instance should probably be a part of CChainState
|
||||||
// (for multiple chainstates to actually work in parallel)
|
// (for multiple chainstates to actually work in parallel)
|
||||||
// and not a global
|
// and not a global
|
||||||
if (&chainman.ActiveChainstate() == chainstate && !node.evodb->CommitRootTransaction()) {
|
if (&chainman.ActiveChainstate() == chainstate && !evodb->CommitRootTransaction()) {
|
||||||
return ChainstateLoadingError::ERROR_COMMITING_EVO_DB;
|
return ChainstateLoadingError::ERROR_COMMITING_EVO_DB;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,10 +224,10 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!node.dmnman->MigrateDBIfNeeded() || !node.dmnman->MigrateDBIfNeeded2()) {
|
if (!dmnman->MigrateDBIfNeeded() || !dmnman->MigrateDBIfNeeded2()) {
|
||||||
return ChainstateLoadingError::ERROR_UPGRADING_EVO_DB;
|
return ChainstateLoadingError::ERROR_UPGRADING_EVO_DB;
|
||||||
}
|
}
|
||||||
if (!node.mnhf_manager->ForceSignalDBUpdate()) {
|
if (!mnhf_manager->ForceSignalDBUpdate()) {
|
||||||
return ChainstateLoadingError::ERROR_UPGRADING_SIGNALS_DB;
|
return ChainstateLoadingError::ERROR_UPGRADING_SIGNALS_DB;
|
||||||
}
|
}
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
@ -246,7 +259,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
|||||||
|
|
||||||
if (!CVerifyDB().VerifyDB(
|
if (!CVerifyDB().VerifyDB(
|
||||||
*chainstate, chainparams, chainstate->CoinsDB(),
|
*chainstate, chainparams, chainstate->CoinsDB(),
|
||||||
*node.evodb,
|
*evodb,
|
||||||
check_level,
|
check_level,
|
||||||
check_blocks)) {
|
check_blocks)) {
|
||||||
return ChainstateLoadingError::ERROR_CORRUPTED_BLOCK_DB;
|
return ChainstateLoadingError::ERROR_CORRUPTED_BLOCK_DB;
|
||||||
@ -267,7 +280,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
|||||||
// TODO: CEvoDB instance should probably be a part of CChainState
|
// TODO: CEvoDB instance should probably be a part of CChainState
|
||||||
// (for multiple chainstates to actually work in parallel)
|
// (for multiple chainstates to actually work in parallel)
|
||||||
// and not a global
|
// and not a global
|
||||||
if (&chainman.ActiveChainstate() == chainstate && !node.evodb->IsEmpty()) {
|
if (&chainman.ActiveChainstate() == chainstate && !evodb->IsEmpty()) {
|
||||||
// EvoDB processed some blocks earlier but we have no blocks anymore, something is wrong
|
// EvoDB processed some blocks earlier but we have no blocks anymore, something is wrong
|
||||||
return ChainstateLoadingError::ERROR_EVO_DB_SANITY_FAILED;
|
return ChainstateLoadingError::ERROR_EVO_DB_SANITY_FAILED;
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,29 @@
|
|||||||
#define BITCOIN_NODE_CHAINSTATE_H
|
#define BITCOIN_NODE_CHAINSTATE_H
|
||||||
|
|
||||||
#include <cstdint> // for int64_t
|
#include <cstdint> // for int64_t
|
||||||
|
#include <memory> // for std::unique_ptr
|
||||||
#include <optional> // for std::optional
|
#include <optional> // for std::optional
|
||||||
|
|
||||||
|
class CActiveMasternodeManager;
|
||||||
class CChainParams;
|
class CChainParams;
|
||||||
|
class CChainstateHelper;
|
||||||
|
class CCreditPoolManager;
|
||||||
|
class CDeterministicMNManager;
|
||||||
|
class CEvoDB;
|
||||||
|
class CGovernanceManager;
|
||||||
class ChainstateManager;
|
class ChainstateManager;
|
||||||
struct NodeContext;
|
class CMasternodeMetaMan;
|
||||||
|
class CMasternodeSync;
|
||||||
|
class CMNHFManager;
|
||||||
|
class CSporkManager;
|
||||||
|
class CTxMemPool;
|
||||||
|
struct LLMQContext;
|
||||||
|
|
||||||
|
namespace llmq {
|
||||||
|
class CChainLocksHandler;
|
||||||
|
class CInstantSendManager;
|
||||||
|
class CQuorumSnapshotManager;
|
||||||
|
}
|
||||||
|
|
||||||
enum class ChainstateLoadingError {
|
enum class ChainstateLoadingError {
|
||||||
ERROR_LOADING_BLOCK_DB,
|
ERROR_LOADING_BLOCK_DB,
|
||||||
@ -63,7 +81,21 @@ enum class ChainstateLoadingError {
|
|||||||
*/
|
*/
|
||||||
std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
||||||
ChainstateManager& chainman,
|
ChainstateManager& chainman,
|
||||||
NodeContext& node,
|
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::CChainLocksHandler>& clhandler,
|
||||||
|
std::unique_ptr<llmq::CInstantSendManager>& isman,
|
||||||
|
std::unique_ptr<llmq::CQuorumSnapshotManager>& qsnapman,
|
||||||
|
std::unique_ptr<LLMQContext>& llmq_ctx,
|
||||||
|
CTxMemPool* mempool,
|
||||||
bool fPruneMode,
|
bool fPruneMode,
|
||||||
bool is_addrindex_enabled,
|
bool is_addrindex_enabled,
|
||||||
bool is_governance_enabled,
|
bool is_governance_enabled,
|
||||||
|
Loading…
Reference in New Issue
Block a user