Skip to content

Commit

Permalink
refactor: remove llmq::quorumSnapshotManager global, move to `LLMQC…
Browse files Browse the repository at this point in the history
…ontext`
  • Loading branch information
kwvg committed Jan 6, 2025
1 parent 7125330 commit b5a8240
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 49 deletions.
6 changes: 2 additions & 4 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
#include <llmq/dkgsessionmgr.h>
#include <llmq/options.h>
#include <llmq/signing.h>
#include <llmq/snapshot.h>
#include <llmq/signing_shares.h>

#include <stats/client.h>
Expand Down Expand Up @@ -333,8 +332,8 @@ void PrepareShutdown(NodeContext& node)
chainstate->ResetCoinsViews();
}
}
DashChainstateSetupClose(node.chain_helper, node.cpoolman, node.dmnman, node.mnhf_manager,
llmq::quorumSnapshotManager, node.llmq_ctx, Assert(node.mempool.get()));
DashChainstateSetupClose(node.chain_helper, node.cpoolman, node.dmnman, node.mnhf_manager, node.llmq_ctx,
Assert(node.mempool.get()));
node.mnhf_manager.reset();
node.evodb.reset();
}
Expand Down Expand Up @@ -1856,7 +1855,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
node.dmnman,
node.evodb,
node.mnhf_manager,
llmq::quorumSnapshotManager,
node.llmq_ctx,
Assert(node.mempool.get()),
fPruneMode,
Expand Down
13 changes: 7 additions & 6 deletions src/llmq/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ LLMQContext::LLMQContext(ChainstateManager& chainman, CDeterministicMNManager& d
is_masternode{mn_activeman != nullptr},
bls_worker{std::make_shared<CBLSWorker>()},
dkg_debugman{std::make_unique<llmq::CDKGDebugManager>()},
quorum_block_processor{std::make_unique<llmq::CQuorumBlockProcessor>(chainman.ActiveChainstate(), dmnman, evo_db,
*llmq::quorumSnapshotManager)},
qsnapman{std::make_unique<llmq::CQuorumSnapshotManager>(evo_db)},
quorum_block_processor{
std::make_unique<llmq::CQuorumBlockProcessor>(chainman.ActiveChainstate(), dmnman, evo_db, *qsnapman)},
qdkgsman{std::make_unique<llmq::CDKGSessionManager>(*bls_worker, chainman.ActiveChainstate(), dmnman, *dkg_debugman,
mn_metaman, *quorum_block_processor, *llmq::quorumSnapshotManager,
mn_activeman, sporkman, unit_tests, wipe)},
mn_metaman, *quorum_block_processor, *qsnapman, mn_activeman,
sporkman, unit_tests, wipe)},
qman{std::make_unique<llmq::CQuorumManager>(*bls_worker, chainman.ActiveChainstate(), dmnman, *qdkgsman, evo_db,
*quorum_block_processor, *llmq::quorumSnapshotManager, mn_activeman,
mn_sync, sporkman, unit_tests, wipe)},
*quorum_block_processor, *qsnapman, mn_activeman, mn_sync, sporkman,
unit_tests, wipe)},
sigman{std::make_unique<llmq::CSigningManager>(mn_activeman, chainman.ActiveChainstate(), *qman, unit_tests, wipe)},
shareman{std::make_unique<llmq::CSigSharesManager>(*sigman, mn_activeman, *qman, sporkman)},
clhandler{std::make_unique<llmq::CChainLocksHandler>(chainman.ActiveChainstate(), *qman, *sigman, *shareman,
Expand Down
2 changes: 2 additions & 0 deletions src/llmq/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CEHFSignalsHandler;
class CInstantSendManager;
class CQuorumBlockProcessor;
class CQuorumManager;
class CQuorumSnapshotManager;
class CSigSharesManager;
class CSigningManager;
}
Expand Down Expand Up @@ -61,6 +62,7 @@ struct LLMQContext {
*/
const std::shared_ptr<CBLSWorker> bls_worker;
const std::unique_ptr<llmq::CDKGDebugManager> dkg_debugman;
const std::unique_ptr<llmq::CQuorumSnapshotManager> qsnapman;
const std::unique_ptr<llmq::CQuorumBlockProcessor> quorum_block_processor;
const std::unique_ptr<llmq::CDKGSessionManager> qdkgsman;
const std::unique_ptr<llmq::CQuorumManager> qman;
Expand Down
2 changes: 0 additions & 2 deletions src/llmq/snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ namespace llmq {

static const std::string DB_QUORUM_SNAPSHOT = "llmq_S";

std::unique_ptr<CQuorumSnapshotManager> quorumSnapshotManager;

UniValue CQuorumSnapshot::ToJson() const
{
UniValue obj;
Expand Down
3 changes: 0 additions & 3 deletions src/llmq/snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,6 @@ class CQuorumSnapshotManager
std::optional<CQuorumSnapshot> GetSnapshotForBlock(Consensus::LLMQType llmqType, const CBlockIndex* pindex);
void StoreSnapshotForBlock(Consensus::LLMQType llmqType, const CBlockIndex* pindex, const CQuorumSnapshot& snapshot);
};

extern std::unique_ptr<CQuorumSnapshotManager> quorumSnapshotManager;

} // namespace llmq

#endif // BITCOIN_LLMQ_SNAPSHOT_H
2 changes: 1 addition & 1 deletion src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5205,7 +5205,7 @@ void PeerManagerImpl::ProcessMessage(

llmq::CQuorumRotationInfo quorumRotationInfoRet;
std::string strError;
if (BuildQuorumRotationInfo(*m_dmnman, *llmq::quorumSnapshotManager, m_chainman, *m_llmq_ctx->qman, *m_llmq_ctx->quorum_block_processor, cmd, quorumRotationInfoRet, strError)) {
if (BuildQuorumRotationInfo(*m_dmnman, *m_llmq_ctx->qsnapman, m_chainman, *m_llmq_ctx->qman, *m_llmq_ctx->quorum_block_processor, cmd, quorumRotationInfoRet, strError)) {
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::QUORUMROTATIONINFO, quorumRotationInfoRet));
} else {
strError = strprintf("getquorumrotationinfo failed for size(baseBlockHashes)=%d, blockRequestHash=%s. error=%s", cmd.baseBlockHashes.size(), cmd.blockRequestHash.ToString(), strError);
Expand Down
12 changes: 2 additions & 10 deletions src/node/chainstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <evo/evodb.h>
#include <evo/mnhftx.h>
#include <llmq/context.h>
#include <llmq/snapshot.h>

std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
ChainstateManager& chainman,
Expand All @@ -30,7 +29,6 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
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 fPruneMode,
Expand Down Expand Up @@ -74,7 +72,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, block_tree_db_in_memory, fReset));

DashChainstateSetup(chainman, govman, mn_metaman, mn_sync, sporkman, mn_activeman, chain_helper, cpoolman,
dmnman, evodb, mnhf_manager, qsnapman, llmq_ctx, mempool, fReset, fReindexChainState,
dmnman, evodb, mnhf_manager, llmq_ctx, mempool, fReset, fReindexChainState,
consensus_params);

if (fReset) {
Expand Down Expand Up @@ -210,7 +208,6 @@ void DashChainstateSetup(ChainstateManager& chainman,
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,
Expand All @@ -224,9 +221,6 @@ void DashChainstateSetup(ChainstateManager& chainman,
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();
Expand All @@ -240,15 +234,14 @@ void DashChainstateSetup(ChainstateManager& chainman,

chain_helper.reset();
chain_helper = std::make_unique<CChainstateHelper>(*cpoolman, *dmnman, *mnhf_manager, govman, *(llmq_ctx->isman), *(llmq_ctx->quorum_block_processor),
*llmq::quorumSnapshotManager, chainman, consensus_params, mn_sync, sporkman, *(llmq_ctx->clhandler),
*(llmq_ctx->qsnapman), 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)

Expand All @@ -258,7 +251,6 @@ void DashChainstateSetupClose(std::unique_ptr<CChainstateHelper>& chain_helper,
mnhf_manager->DisconnectManagers();
}
llmq_ctx.reset();
qsnapman.reset();
cpoolman.reset();
mempool->DisconnectManagers();
dmnman.reset();
Expand Down
7 changes: 0 additions & 7 deletions src/node/chainstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ class CSporkManager;
class CTxMemPool;
struct LLMQContext;

namespace llmq {
class CQuorumSnapshotManager;
}

namespace Consensus {
struct Params;
}
Expand Down Expand Up @@ -91,7 +87,6 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
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 fPruneMode,
Expand Down Expand Up @@ -123,7 +118,6 @@ void DashChainstateSetup(ChainstateManager& chainman,
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,
Expand All @@ -134,7 +128,6 @@ 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);

Expand Down
2 changes: 1 addition & 1 deletion src/node/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ BlockAssembler::BlockAssembler(CChainState& chainstate, const NodeContext& node,
m_mnhfman(*Assert(node.mnhf_manager)),
m_clhandler(*Assert(Assert(node.llmq_ctx)->clhandler)),
m_isman(*Assert(Assert(node.llmq_ctx)->isman)),
m_qsnapman(*llmq::quorumSnapshotManager),
m_qsnapman(*Assert(Assert(node.llmq_ctx)->qsnapman)),
chainparams(params),
m_mempool(mempool),
m_quorum_block_processor(*Assert(Assert(node.llmq_ctx)->quorum_block_processor)),
Expand Down
11 changes: 5 additions & 6 deletions src/rpc/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ static RPCHelpMan quorum_dkgstatus()
llmq::CDKGDebugStatus status;
llmq_ctx.dkg_debugman->GetLocalDebugStatus(status);

auto ret = status.ToJson(*CHECK_NONFATAL(node.dmnman), *llmq::quorumSnapshotManager, chainman, detailLevel);
auto ret = status.ToJson(*CHECK_NONFATAL(node.dmnman), *llmq_ctx.qsnapman, chainman, detailLevel);

CBlockIndex* pindexTip = WITH_LOCK(cs_main, return chainman.ActiveChain().Tip());
int tipHeight = pindexTip->nHeight;
Expand Down Expand Up @@ -325,12 +325,11 @@ static RPCHelpMan quorum_dkgstatus()
obj.pushKV("pindexTip", pindexTip->nHeight);

auto allConnections = llmq::utils::GetQuorumConnections(llmq_params, *node.dmnman,
*llmq::quorumSnapshotManager, *node.sporkman,
*llmq_ctx.qsnapman, *node.sporkman,
pQuorumBaseBlockIndex, proTxHash, false);
auto outboundConnections = llmq::utils::GetQuorumConnections(llmq_params, *node.dmnman,
*llmq::quorumSnapshotManager,
*node.sporkman, pQuorumBaseBlockIndex,
proTxHash, true);
*llmq_ctx.qsnapman, *node.sporkman,
pQuorumBaseBlockIndex, proTxHash, true);
std::map<uint256, CAddress> foundConnections;
connman.ForEachNode([&](const CNode* pnode) {
auto verifiedProRegTxHash = pnode->GetVerifiedProRegTxHash();
Expand Down Expand Up @@ -864,7 +863,7 @@ static RPCHelpMan quorum_rotationinfo()

LOCK(cs_main);

if (!BuildQuorumRotationInfo(*CHECK_NONFATAL(node.dmnman), *llmq::quorumSnapshotManager, chainman, *llmq_ctx.qman,
if (!BuildQuorumRotationInfo(*CHECK_NONFATAL(node.dmnman), *llmq_ctx.qsnapman, chainman, *llmq_ctx.qman,
*llmq_ctx.quorum_block_processor, cmd, quorumRotationInfoRet, strError)) {
throw JSONRPCError(RPC_INVALID_REQUEST, strError);
}
Expand Down
14 changes: 5 additions & 9 deletions src/test/util/setup_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <llmq/quorums.h>
#include <llmq/signing.h>
#include <llmq/signing_shares.h>
#include <llmq/snapshot.h>
#include <masternode/meta.h>
#include <masternode/sync.h>
#include <net.h>
Expand Down Expand Up @@ -112,14 +111,14 @@ void DashChainstateSetup(ChainstateManager& chainman,
{
DashChainstateSetup(chainman, *Assert(node.govman.get()), *Assert(node.mn_metaman.get()), *Assert(node.mn_sync.get()),
*Assert(node.sporkman.get()), node.mn_activeman, node.chain_helper, node.cpoolman, node.dmnman,
node.evodb, node.mnhf_manager, llmq::quorumSnapshotManager, node.llmq_ctx,
Assert(node.mempool.get()), fReset, fReindexChainState, consensus_params);
node.evodb, node.mnhf_manager, node.llmq_ctx, Assert(node.mempool.get()), fReset, fReindexChainState,
consensus_params);
}

void DashChainstateSetupClose(NodeContext& node)
{
DashChainstateSetupClose(node.chain_helper, node.cpoolman, node.dmnman, node.mnhf_manager,
llmq::quorumSnapshotManager, node.llmq_ctx, Assert(node.mempool.get()));
DashChainstateSetupClose(node.chain_helper, node.cpoolman, node.dmnman, node.mnhf_manager, node.llmq_ctx,
Assert(node.mempool.get()));
}

void DashPostChainstateSetup(NodeContext& node)
Expand Down Expand Up @@ -203,7 +202,6 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve
fCheckBlockIndex = true;
m_node.evodb = std::make_unique<CEvoDB>(1 << 20, true, true);
m_node.mnhf_manager = std::make_unique<CMNHFManager>(*m_node.evodb);
llmq::quorumSnapshotManager.reset(new llmq::CQuorumSnapshotManager(*m_node.evodb));
m_node.cpoolman = std::make_unique<CCreditPoolManager>(*m_node.evodb);
static bool noui_connected = false;
if (!noui_connected) {
Expand All @@ -217,7 +215,6 @@ BasicTestingSetup::~BasicTestingSetup()
{
SetMockTime(0s); // Reset mocktime for following tests
m_node.cpoolman.reset();
llmq::quorumSnapshotManager.reset();
m_node.mnhf_manager.reset();
m_node.evodb.reset();
m_node.connman.reset();
Expand Down Expand Up @@ -297,7 +294,6 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
m_node.dmnman,
m_node.evodb,
m_node.mnhf_manager,
llmq::quorumSnapshotManager,
m_node.llmq_ctx,
Assert(m_node.mempool.get()),
fPruneMode,
Expand Down Expand Up @@ -479,7 +475,7 @@ CBlock TestChainSetup::CreateBlock(
auto cbTx = GetTxPayload<CCbTx>(*block.vtx[0]);
Assert(cbTx.has_value());
BlockValidationState state;
if (!CalcCbTxMerkleRootMNList(block, chainstate.m_chain.Tip(), cbTx->merkleRootMNList, state, *m_node.dmnman, *llmq::quorumSnapshotManager, chainstate.CoinsTip())) {
if (!CalcCbTxMerkleRootMNList(block, chainstate.m_chain.Tip(), cbTx->merkleRootMNList, state, *m_node.dmnman, *m_node.llmq_ctx->qsnapman, chainstate.CoinsTip())) {
Assert(false);
}
if (!CalcCbTxMerkleRootQuorums(block, chainstate.m_chain.Tip(), *m_node.llmq_ctx->quorum_block_processor, cbTx->merkleRootQuorums, state)) {
Expand Down

0 comments on commit b5a8240

Please sign in to comment.