Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove llmq::chainLocksHandler, llmq::quorum{InstantSend,Snapshot}Manager, move to LLMQContext #6504

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
32 changes: 7 additions & 25 deletions src/llmq/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,8 @@ LLMQContext::LLMQContext(ChainstateManager& chainman, CDeterministicMNManager& d
shareman{std::make_unique<llmq::CSigSharesManager>(*sigman, mn_activeman, *qman, sporkman)},
clhandler{std::make_unique<llmq::CChainLocksHandler>(chainman.ActiveChainstate(), *qman, *sigman, *shareman,
sporkman, mempool, mn_sync, is_masternode)},
isman{[&]() -> llmq::CInstantSendManager* const {
assert(llmq::quorumInstantSendManager == nullptr);
llmq::quorumInstantSendManager = std::make_unique<llmq::CInstantSendManager>(*clhandler,
chainman.ActiveChainstate(), *qman,
*sigman, *shareman, sporkman,
mempool, mn_sync, is_masternode,
unit_tests, wipe);
return llmq::quorumInstantSendManager.get();
}()},
isman{std::make_unique<llmq::CInstantSendManager>(*clhandler, chainman.ActiveChainstate(), *qman, *sigman, *shareman,
sporkman, mempool, mn_sync, is_masternode, unit_tests, wipe)},
kwvg marked this conversation as resolved.
Show resolved Hide resolved
ehfSignalsHandler{std::make_unique<llmq::CEHFSignalsHandler>(chainman, mnhfman, *sigman, *shareman, *qman)}
{
// Have to start it early to let VerifyDB check ChainLock signatures in coinbase
Expand All @@ -53,44 +46,33 @@ LLMQContext::LLMQContext(ChainstateManager& chainman, CDeterministicMNManager& d

LLMQContext::~LLMQContext() {
bls_worker->Stop();

// LLMQContext doesn't own these objects, but still need to care of them for consistency:
llmq::quorumInstantSendManager.reset();
}

void LLMQContext::Interrupt() {
sigman->InterruptWorkerThread();
shareman->InterruptWorkerThread();

assert(isman == llmq::quorumInstantSendManager.get());
llmq::quorumInstantSendManager->InterruptWorkerThread();
sigman->InterruptWorkerThread();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sigman thread starts before isman. It means to be stopped in "reversed" order. Firstly, isman, after that - sigman. Same for shareman - if the thread started the first (before sigman and isman) - it means to be stopped last.

This place requires either clarification why order is inversed, or fixing inerruption order.

isman->InterruptWorkerThread();
sigman->InterruptWorkerThread();
shareman->InterruptWorkerThread();

isman->InterruptWorkerThread();
}

void LLMQContext::Start(CConnman& connman, PeerManager& peerman)
{
assert(isman == llmq::quorumInstantSendManager.get());

if (is_masternode) {
qdkgsman->StartThreads(connman, peerman);
}
qman->Start();
shareman->RegisterAsRecoveredSigsListener();
shareman->StartWorkerThread(connman, peerman);
sigman->StartWorkerThread(peerman);

clhandler->Start(*isman);
llmq::quorumInstantSendManager->Start(peerman);
isman->Start(peerman);
}

void LLMQContext::Stop() {
assert(isman == llmq::quorumInstantSendManager.get());

llmq::quorumInstantSendManager->Stop();
isman->Stop();
clhandler->Stop();

sigman->StopWorkerThread();
shareman->StopWorkerThread();
shareman->UnregisterAsRecoveredSigsListener();
sigman->StopWorkerThread();
qman->Stop();
if (is_masternode) {
qdkgsman->StopThreads();
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct LLMQContext {
const std::unique_ptr<llmq::CSigningManager> sigman;
const std::unique_ptr<llmq::CSigSharesManager> shareman;
const std::unique_ptr<llmq::CChainLocksHandler> clhandler;
llmq::CInstantSendManager* const isman;
const std::unique_ptr<llmq::CInstantSendManager> isman; // TODO: split CInstantSendManager and CInstantSendLock to 2 files
const std::unique_ptr<llmq::CEHFSignalsHandler> ehfSignalsHandler;
};

Expand Down
2 changes: 0 additions & 2 deletions src/llmq/instantsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ static const std::string_view DB_ARCHIVED_BY_HASH = "is_a2";

static const std::string_view DB_VERSION = "is_v";

std::unique_ptr<CInstantSendManager> quorumInstantSendManager;

uint256 CInstantSendLock::GetRequestId() const
{
CHashWriter hw(SER_GETHASH, 0);
Expand Down
3 changes: 0 additions & 3 deletions src/llmq/instantsend.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,6 @@ class CInstantSendManager : public CRecoveredSigsListener
bool IsInstantSendMempoolSigningEnabled() const;
bool RejectConflictingBlocks() const;
};
// TODO: split CInstantSendManager and CInstantSendLock to 2 files
extern std::unique_ptr<CInstantSendManager> quorumInstantSendManager;

} // namespace llmq

#endif // BITCOIN_LLMQ_INSTANTSEND_H
2 changes: 1 addition & 1 deletion src/node/chainstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ void DashChainstateSetup(ChainstateManager& chainman,
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);
mempool->ConnectManagers(dmnman.get(), llmq_ctx->isman);
mempool->ConnectManagers(dmnman.get(), llmq_ctx->isman.get());
// Enable CMNHFManager::{Process, Undo}Block
mnhf_manager->ConnectManagers(&chainman, llmq_ctx->qman.get());

Expand Down
2 changes: 1 addition & 1 deletion src/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ static bool rest_mempool_contents(const CoreContext& context, HTTPRequest* req,
const LLMQContext* llmq_ctx = GetLLMQContext(context, req);
if (!llmq_ctx) return false;

UniValue mempoolObject = MempoolToJSON(*mempool, llmq_ctx->isman, true);
UniValue mempoolObject = MempoolToJSON(*mempool, llmq_ctx->isman.get(), true);

std::string strJSON = mempoolObject.write() + "\n";
req->WriteHeader("Content-Type", "application/json");
Expand Down
8 changes: 4 additions & 4 deletions src/rpc/mempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ RPCHelpMan getrawmempool()
const CTxMemPool& mempool = EnsureMemPool(node);
const LLMQContext& llmq_ctx = EnsureLLMQContext(node);

return MempoolToJSON(mempool, llmq_ctx.isman, fVerbose, include_mempool_sequence);
return MempoolToJSON(mempool, llmq_ctx.isman.get(), fVerbose, include_mempool_sequence);
},
};
}
Expand Down Expand Up @@ -264,7 +264,7 @@ RPCHelpMan getmempoolancestors()
const CTxMemPoolEntry &e = *ancestorIt;
const uint256& _hash = e.GetTx().GetHash();
UniValue info(UniValue::VOBJ);
entryToJSON(mempool, info, e, llmq_ctx.isman);
entryToJSON(mempool, info, e, llmq_ctx.isman.get());
o.pushKV(_hash.ToString(), info);
}
return o;
Expand Down Expand Up @@ -332,7 +332,7 @@ RPCHelpMan getmempooldescendants()
const CTxMemPoolEntry &e = *descendantIt;
const uint256& _hash = e.GetTx().GetHash();
UniValue info(UniValue::VOBJ);
entryToJSON(mempool, info, e, llmq_ctx.isman);
entryToJSON(mempool, info, e, llmq_ctx.isman.get());
o.pushKV(_hash.ToString(), info);
}
return o;
Expand Down Expand Up @@ -372,7 +372,7 @@ RPCHelpMan getmempoolentry()
const CTxMemPoolEntry &e = *it;
UniValue info(UniValue::VOBJ);
const LLMQContext& llmq_ctx = EnsureLLMQContext(node);
entryToJSON(mempool, info, e, llmq_ctx.isman);
entryToJSON(mempool, info, e, llmq_ctx.isman.get());
return info;
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/test/evo_deterministicmns_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ void FuncTestMempoolReorg(TestChainSetup& setup)

CTxMemPool testPool;
if (setup.m_node.dmnman) {
testPool.ConnectManagers(setup.m_node.dmnman.get(), setup.m_node.llmq_ctx->isman);
testPool.ConnectManagers(setup.m_node.dmnman.get(), setup.m_node.llmq_ctx->isman.get());
}
TestMemPoolEntryHelper entry;
LOCK2(cs_main, testPool.cs);
Expand Down Expand Up @@ -729,7 +729,7 @@ void FuncTestMempoolDualProregtx(TestChainSetup& setup)

CTxMemPool testPool;
if (setup.m_node.dmnman) {
testPool.ConnectManagers(setup.m_node.dmnman.get(), setup.m_node.llmq_ctx->isman);
testPool.ConnectManagers(setup.m_node.dmnman.get(), setup.m_node.llmq_ctx->isman.get());
}
TestMemPoolEntryHelper entry;
LOCK2(cs_main, testPool.cs);
Expand Down