Skip to content

Commit 652a72d

Browse files
committed
refactor: remove llmq::quorumSnapshotManager global, move to LLMQContext
1 parent 9dd7800 commit 652a72d

File tree

11 files changed

+24
-47
lines changed

11 files changed

+24
-47
lines changed

src/init.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
#include <llmq/dkgsessionmgr.h>
105105
#include <llmq/options.h>
106106
#include <llmq/signing.h>
107-
#include <llmq/snapshot.h>
108107
#include <llmq/signing_shares.h>
109108

110109
#include <stats/client.h>
@@ -333,8 +332,8 @@ void PrepareShutdown(NodeContext& node)
333332
chainstate->ResetCoinsViews();
334333
}
335334
}
336-
DashChainstateSetupClose(node.chain_helper, node.cpoolman, node.dmnman, node.mnhf_manager,
337-
llmq::quorumSnapshotManager, node.llmq_ctx, Assert(node.mempool.get()));
335+
DashChainstateSetupClose(node.chain_helper, node.cpoolman, node.dmnman, node.mnhf_manager, node.llmq_ctx,
336+
Assert(node.mempool.get()));
338337
node.mnhf_manager.reset();
339338
node.evodb.reset();
340339
}
@@ -1856,7 +1855,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
18561855
node.dmnman,
18571856
node.evodb,
18581857
node.mnhf_manager,
1859-
llmq::quorumSnapshotManager,
18601858
node.llmq_ctx,
18611859
Assert(node.mempool.get()),
18621860
fPruneMode,

src/llmq/context.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ LLMQContext::LLMQContext(ChainstateManager& chainman, CDeterministicMNManager& d
2626
is_masternode{mn_activeman != nullptr},
2727
bls_worker{std::make_shared<CBLSWorker>()},
2828
dkg_debugman{std::make_unique<llmq::CDKGDebugManager>()},
29-
quorum_block_processor{std::make_unique<llmq::CQuorumBlockProcessor>(chainman.ActiveChainstate(), dmnman, evo_db,
30-
*llmq::quorumSnapshotManager)},
29+
qsnapman{std::make_unique<llmq::CQuorumSnapshotManager>(evo_db)},
30+
quorum_block_processor{
31+
std::make_unique<llmq::CQuorumBlockProcessor>(chainman.ActiveChainstate(), dmnman, evo_db, *qsnapman)},
3132
qdkgsman{std::make_unique<llmq::CDKGSessionManager>(*bls_worker, chainman.ActiveChainstate(), dmnman, *dkg_debugman,
32-
mn_metaman, *quorum_block_processor, *llmq::quorumSnapshotManager,
33-
mn_activeman, sporkman, unit_tests, wipe)},
33+
mn_metaman, *quorum_block_processor, *qsnapman, mn_activeman,
34+
sporkman, unit_tests, wipe)},
3435
qman{std::make_unique<llmq::CQuorumManager>(*bls_worker, chainman.ActiveChainstate(), dmnman, *qdkgsman, evo_db,
35-
*quorum_block_processor, *llmq::quorumSnapshotManager, mn_activeman,
36-
mn_sync, sporkman, unit_tests, wipe)},
36+
*quorum_block_processor, *qsnapman, mn_activeman, mn_sync, sporkman,
37+
unit_tests, wipe)},
3738
sigman{std::make_unique<llmq::CSigningManager>(mn_activeman, chainman.ActiveChainstate(), *qman, unit_tests, wipe)},
3839
shareman{std::make_unique<llmq::CSigSharesManager>(*sigman, mn_activeman, *qman, sporkman)},
3940
clhandler{std::make_unique<llmq::CChainLocksHandler>(chainman.ActiveChainstate(), *qman, *sigman, *shareman,

src/llmq/context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class CEHFSignalsHandler;
2828
class CInstantSendManager;
2929
class CQuorumBlockProcessor;
3030
class CQuorumManager;
31+
class CQuorumSnapshotManager;
3132
class CSigSharesManager;
3233
class CSigningManager;
3334
}
@@ -61,6 +62,7 @@ struct LLMQContext {
6162
*/
6263
const std::shared_ptr<CBLSWorker> bls_worker;
6364
const std::unique_ptr<llmq::CDKGDebugManager> dkg_debugman;
65+
const std::unique_ptr<llmq::CQuorumSnapshotManager> qsnapman;
6466
const std::unique_ptr<llmq::CQuorumBlockProcessor> quorum_block_processor;
6567
const std::unique_ptr<llmq::CDKGSessionManager> qdkgsman;
6668
const std::unique_ptr<llmq::CQuorumManager> qman;

src/llmq/snapshot.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ namespace llmq {
2121

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

24-
std::unique_ptr<CQuorumSnapshotManager> quorumSnapshotManager;
25-
2624
UniValue CQuorumSnapshot::ToJson() const
2725
{
2826
UniValue obj;

src/llmq/snapshot.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,6 @@ class CQuorumSnapshotManager
228228
std::optional<CQuorumSnapshot> GetSnapshotForBlock(Consensus::LLMQType llmqType, const CBlockIndex* pindex);
229229
void StoreSnapshotForBlock(Consensus::LLMQType llmqType, const CBlockIndex* pindex, const CQuorumSnapshot& snapshot);
230230
};
231-
232-
extern std::unique_ptr<CQuorumSnapshotManager> quorumSnapshotManager;
233-
234231
} // namespace llmq
235232

236233
#endif // BITCOIN_LLMQ_SNAPSHOT_H

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5204,7 +5204,7 @@ void PeerManagerImpl::ProcessMessage(
52045204

52055205
llmq::CQuorumRotationInfo quorumRotationInfoRet;
52065206
std::string strError;
5207-
if (BuildQuorumRotationInfo(*m_dmnman, *llmq::quorumSnapshotManager, m_chainman, *m_llmq_ctx->qman, *m_llmq_ctx->quorum_block_processor, cmd, quorumRotationInfoRet, strError)) {
5207+
if (BuildQuorumRotationInfo(*m_dmnman, *m_llmq_ctx->qsnapman, m_chainman, *m_llmq_ctx->qman, *m_llmq_ctx->quorum_block_processor, cmd, quorumRotationInfoRet, strError)) {
52085208
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::QUORUMROTATIONINFO, quorumRotationInfoRet));
52095209
} else {
52105210
strError = strprintf("getquorumrotationinfo failed for size(baseBlockHashes)=%d, blockRequestHash=%s. error=%s", cmd.baseBlockHashes.size(), cmd.blockRequestHash.ToString(), strError);

src/node/chainstate.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <evo/evodb.h>
1717
#include <evo/mnhftx.h>
1818
#include <llmq/context.h>
19-
#include <llmq/snapshot.h>
2019

2120
std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
2221
ChainstateManager& chainman,
@@ -30,7 +29,6 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
3029
std::unique_ptr<CDeterministicMNManager>& dmnman,
3130
std::unique_ptr<CEvoDB>& evodb,
3231
std::unique_ptr<CMNHFManager>& mnhf_manager,
33-
std::unique_ptr<llmq::CQuorumSnapshotManager>& qsnapman,
3432
std::unique_ptr<LLMQContext>& llmq_ctx,
3533
CTxMemPool* mempool,
3634
bool fPruneMode,
@@ -74,7 +72,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
7472
pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, block_tree_db_in_memory, fReset));
7573

7674
DashChainstateSetup(chainman, govman, mn_metaman, mn_sync, sporkman, mn_activeman, chain_helper, cpoolman,
77-
dmnman, evodb, mnhf_manager, qsnapman, llmq_ctx, mempool, fReset, fReindexChainState,
75+
dmnman, evodb, mnhf_manager, llmq_ctx, mempool, fReset, fReindexChainState,
7876
consensus_params);
7977

8078
if (fReset) {
@@ -210,7 +208,6 @@ void DashChainstateSetup(ChainstateManager& chainman,
210208
std::unique_ptr<CDeterministicMNManager>& dmnman,
211209
std::unique_ptr<CEvoDB>& evodb,
212210
std::unique_ptr<CMNHFManager>& mnhf_manager,
213-
std::unique_ptr<llmq::CQuorumSnapshotManager>& qsnapman,
214211
std::unique_ptr<LLMQContext>& llmq_ctx,
215212
CTxMemPool* mempool,
216213
bool fReset,
@@ -224,9 +221,6 @@ void DashChainstateSetup(ChainstateManager& chainman,
224221
cpoolman.reset();
225222
cpoolman = std::make_unique<CCreditPoolManager>(*evodb);
226223

227-
qsnapman.reset();
228-
qsnapman.reset(new llmq::CQuorumSnapshotManager(*evodb));
229-
230224
if (llmq_ctx) {
231225
llmq_ctx->Interrupt();
232226
llmq_ctx->Stop();
@@ -240,15 +234,14 @@ void DashChainstateSetup(ChainstateManager& chainman,
240234

241235
chain_helper.reset();
242236
chain_helper = std::make_unique<CChainstateHelper>(*cpoolman, *dmnman, *mnhf_manager, govman, *(llmq_ctx->isman), *(llmq_ctx->quorum_block_processor),
243-
*llmq::quorumSnapshotManager, chainman, consensus_params, mn_sync, sporkman, *(llmq_ctx->clhandler),
237+
*(llmq_ctx->qsnapman), chainman, consensus_params, mn_sync, sporkman, *(llmq_ctx->clhandler),
244238
*(llmq_ctx->qman));
245239
}
246240

247241
void DashChainstateSetupClose(std::unique_ptr<CChainstateHelper>& chain_helper,
248242
std::unique_ptr<CCreditPoolManager>& cpoolman,
249243
std::unique_ptr<CDeterministicMNManager>& dmnman,
250244
std::unique_ptr<CMNHFManager>& mnhf_manager,
251-
std::unique_ptr<llmq::CQuorumSnapshotManager>& qsnapman,
252245
std::unique_ptr<LLMQContext>& llmq_ctx,
253246
CTxMemPool* mempool)
254247

@@ -258,7 +251,6 @@ void DashChainstateSetupClose(std::unique_ptr<CChainstateHelper>& chain_helper,
258251
mnhf_manager->DisconnectManagers();
259252
}
260253
llmq_ctx.reset();
261-
qsnapman.reset();
262254
cpoolman.reset();
263255
mempool->DisconnectManagers();
264256
dmnman.reset();

src/node/chainstate.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ class CSporkManager;
2525
class CTxMemPool;
2626
struct LLMQContext;
2727

28-
namespace llmq {
29-
class CQuorumSnapshotManager;
30-
}
31-
3228
namespace Consensus {
3329
struct Params;
3430
}
@@ -91,7 +87,6 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
9187
std::unique_ptr<CDeterministicMNManager>& dmnman,
9288
std::unique_ptr<CEvoDB>& evodb,
9389
std::unique_ptr<CMNHFManager>& mnhf_manager,
94-
std::unique_ptr<llmq::CQuorumSnapshotManager>& qsnapman,
9590
std::unique_ptr<LLMQContext>& llmq_ctx,
9691
CTxMemPool* mempool,
9792
bool fPruneMode,
@@ -123,7 +118,6 @@ void DashChainstateSetup(ChainstateManager& chainman,
123118
std::unique_ptr<CDeterministicMNManager>& dmnman,
124119
std::unique_ptr<CEvoDB>& evodb,
125120
std::unique_ptr<CMNHFManager>& mnhf_manager,
126-
std::unique_ptr<llmq::CQuorumSnapshotManager>& qsnapman,
127121
std::unique_ptr<LLMQContext>& llmq_ctx,
128122
CTxMemPool* mempool,
129123
bool fReset,
@@ -134,7 +128,6 @@ void DashChainstateSetupClose(std::unique_ptr<CChainstateHelper>& chain_helper,
134128
std::unique_ptr<CCreditPoolManager>& cpoolman,
135129
std::unique_ptr<CDeterministicMNManager>& dmnman,
136130
std::unique_ptr<CMNHFManager>& mnhf_manager,
137-
std::unique_ptr<llmq::CQuorumSnapshotManager>& qsnapman,
138131
std::unique_ptr<LLMQContext>& llmq_ctx,
139132
CTxMemPool* mempool);
140133

src/node/miner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ BlockAssembler::BlockAssembler(CChainState& chainstate, const NodeContext& node,
7676
m_mnhfman(*Assert(node.mnhf_manager)),
7777
m_clhandler(*Assert(Assert(node.llmq_ctx)->clhandler)),
7878
m_isman(*Assert(Assert(node.llmq_ctx)->isman)),
79-
m_qsnapman(*llmq::quorumSnapshotManager),
79+
m_qsnapman(*Assert(Assert(node.llmq_ctx)->qsnapman)),
8080
chainparams(params),
8181
m_mempool(mempool),
8282
m_quorum_block_processor(*Assert(Assert(node.llmq_ctx)->quorum_block_processor)),

src/rpc/quorums.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ static RPCHelpMan quorum_dkgstatus()
296296
llmq::CDKGDebugStatus status;
297297
llmq_ctx.dkg_debugman->GetLocalDebugStatus(status);
298298

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

301301
CBlockIndex* pindexTip = WITH_LOCK(cs_main, return chainman.ActiveChain().Tip());
302302
int tipHeight = pindexTip->nHeight;
@@ -324,8 +324,8 @@ static RPCHelpMan quorum_dkgstatus()
324324
obj.pushKV("quorumHash", pQuorumBaseBlockIndex->GetBlockHash().ToString());
325325
obj.pushKV("pindexTip", pindexTip->nHeight);
326326

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

860860
LOCK(cs_main);
861861

862-
if (!BuildQuorumRotationInfo(*CHECK_NONFATAL(node.dmnman), *llmq::quorumSnapshotManager, chainman, *llmq_ctx.qman,
862+
if (!BuildQuorumRotationInfo(*CHECK_NONFATAL(node.dmnman), *llmq_ctx.qsnapman, chainman, *llmq_ctx.qman,
863863
*llmq_ctx.quorum_block_processor, cmd, quorumRotationInfoRet, strError)) {
864864
throw JSONRPCError(RPC_INVALID_REQUEST, strError);
865865
}

src/test/util/setup_common.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <llmq/quorums.h>
2323
#include <llmq/signing.h>
2424
#include <llmq/signing_shares.h>
25-
#include <llmq/snapshot.h>
2625
#include <masternode/meta.h>
2726
#include <masternode/sync.h>
2827
#include <net.h>
@@ -112,14 +111,14 @@ void DashChainstateSetup(ChainstateManager& chainman,
112111
{
113112
DashChainstateSetup(chainman, *Assert(node.govman.get()), *Assert(node.mn_metaman.get()), *Assert(node.mn_sync.get()),
114113
*Assert(node.sporkman.get()), node.mn_activeman, node.chain_helper, node.cpoolman, node.dmnman,
115-
node.evodb, node.mnhf_manager, llmq::quorumSnapshotManager, node.llmq_ctx,
116-
Assert(node.mempool.get()), fReset, fReindexChainState, consensus_params);
114+
node.evodb, node.mnhf_manager, node.llmq_ctx, Assert(node.mempool.get()), fReset, fReindexChainState,
115+
consensus_params);
117116
}
118117

119118
void DashChainstateSetupClose(NodeContext& node)
120119
{
121-
DashChainstateSetupClose(node.chain_helper, node.cpoolman, node.dmnman, node.mnhf_manager,
122-
llmq::quorumSnapshotManager, node.llmq_ctx, Assert(node.mempool.get()));
120+
DashChainstateSetupClose(node.chain_helper, node.cpoolman, node.dmnman, node.mnhf_manager, node.llmq_ctx,
121+
Assert(node.mempool.get()));
123122
}
124123

125124
void DashPostChainstateSetup(NodeContext& node)
@@ -203,7 +202,6 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve
203202
fCheckBlockIndex = true;
204203
m_node.evodb = std::make_unique<CEvoDB>(1 << 20, true, true);
205204
m_node.mnhf_manager = std::make_unique<CMNHFManager>(*m_node.evodb);
206-
llmq::quorumSnapshotManager.reset(new llmq::CQuorumSnapshotManager(*m_node.evodb));
207205
m_node.cpoolman = std::make_unique<CCreditPoolManager>(*m_node.evodb);
208206
static bool noui_connected = false;
209207
if (!noui_connected) {
@@ -217,7 +215,6 @@ BasicTestingSetup::~BasicTestingSetup()
217215
{
218216
SetMockTime(0s); // Reset mocktime for following tests
219217
m_node.cpoolman.reset();
220-
llmq::quorumSnapshotManager.reset();
221218
m_node.mnhf_manager.reset();
222219
m_node.evodb.reset();
223220
m_node.connman.reset();
@@ -297,7 +294,6 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
297294
m_node.dmnman,
298295
m_node.evodb,
299296
m_node.mnhf_manager,
300-
llmq::quorumSnapshotManager,
301297
m_node.llmq_ctx,
302298
Assert(m_node.mempool.get()),
303299
fPruneMode,
@@ -479,7 +475,7 @@ CBlock TestChainSetup::CreateBlock(
479475
auto cbTx = GetTxPayload<CCbTx>(*block.vtx[0]);
480476
Assert(cbTx.has_value());
481477
BlockValidationState state;
482-
if (!CalcCbTxMerkleRootMNList(block, chainstate.m_chain.Tip(), cbTx->merkleRootMNList, state, *m_node.dmnman, *llmq::quorumSnapshotManager, chainstate.CoinsTip())) {
478+
if (!CalcCbTxMerkleRootMNList(block, chainstate.m_chain.Tip(), cbTx->merkleRootMNList, state, *m_node.dmnman, *m_node.llmq_ctx->qsnapman, chainstate.CoinsTip())) {
483479
Assert(false);
484480
}
485481
if (!CalcCbTxMerkleRootQuorums(block, chainstate.m_chain.Tip(), *m_node.llmq_ctx->quorum_block_processor, cbTx->merkleRootQuorums, state)) {

0 commit comments

Comments
 (0)