mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
refactor: move CConnman
out of CQuorumManager
ctor
This commit is contained in:
parent
c07b522baa
commit
7ebc61e375
@ -93,7 +93,7 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con
|
||||
m_llmq_ctx->isman->UpdatedBlockTip(pindexNew);
|
||||
m_llmq_ctx->clhandler->UpdatedBlockTip();
|
||||
|
||||
m_llmq_ctx->qman->UpdatedBlockTip(pindexNew, fInitialDownload);
|
||||
m_llmq_ctx->qman->UpdatedBlockTip(pindexNew, m_connman, fInitialDownload);
|
||||
m_llmq_ctx->qdkgsman->UpdatedBlockTip(pindexNew, fInitialDownload);
|
||||
m_llmq_ctx->ehfSignalsHandler->UpdatedBlockTip(pindexNew, /* is_masternode = */ m_mn_activeman != nullptr);
|
||||
|
||||
|
@ -30,9 +30,9 @@ LLMQContext::LLMQContext(ChainstateManager& chainman, CConnman& connman, CDeterm
|
||||
qdkgsman{std::make_unique<llmq::CDKGSessionManager>(*bls_worker, chainman.ActiveChainstate(), dmnman, *dkg_debugman,
|
||||
mn_metaman, *quorum_block_processor, mn_activeman, sporkman,
|
||||
unit_tests, wipe)},
|
||||
qman{std::make_unique<llmq::CQuorumManager>(*bls_worker, chainman.ActiveChainstate(), connman, dmnman, *qdkgsman,
|
||||
evo_db, *quorum_block_processor, mn_activeman, mn_sync, sporkman,
|
||||
unit_tests, wipe)},
|
||||
qman{std::make_unique<llmq::CQuorumManager>(*bls_worker, chainman.ActiveChainstate(), dmnman, *qdkgsman, evo_db,
|
||||
*quorum_block_processor, mn_activeman, mn_sync, sporkman, unit_tests,
|
||||
wipe)},
|
||||
sigman{std::make_unique<llmq::CSigningManager>(mn_activeman, chainman.ActiveChainstate(), *qman, peerman,
|
||||
unit_tests, wipe)},
|
||||
shareman{std::make_unique<llmq::CSigSharesManager>(connman, *sigman, mn_activeman, *qman, sporkman, peerman)},
|
||||
|
@ -210,8 +210,8 @@ bool CQuorum::ReadContributions(const CDBWrapper& db)
|
||||
return true;
|
||||
}
|
||||
|
||||
CQuorumManager::CQuorumManager(CBLSWorker& _blsWorker, CChainState& chainstate, CConnman& _connman,
|
||||
CDeterministicMNManager& dmnman, CDKGSessionManager& _dkgManager, CEvoDB& _evoDb,
|
||||
CQuorumManager::CQuorumManager(CBLSWorker& _blsWorker, CChainState& chainstate, CDeterministicMNManager& dmnman,
|
||||
CDKGSessionManager& _dkgManager, CEvoDB& _evoDb,
|
||||
CQuorumBlockProcessor& _quorumBlockProcessor,
|
||||
const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync,
|
||||
const CSporkManager& sporkman, bool unit_tests, bool wipe) :
|
||||
@ -219,7 +219,6 @@ CQuorumManager::CQuorumManager(CBLSWorker& _blsWorker, CChainState& chainstate,
|
||||
unit_tests, wipe)),
|
||||
blsWorker(_blsWorker),
|
||||
m_chainstate(chainstate),
|
||||
connman(_connman),
|
||||
m_dmnman(dmnman),
|
||||
dkgManager(_dkgManager),
|
||||
quorumBlockProcessor(_quorumBlockProcessor),
|
||||
@ -249,7 +248,7 @@ void CQuorumManager::Stop()
|
||||
workerPool.stop(true);
|
||||
}
|
||||
|
||||
void CQuorumManager::TriggerQuorumDataRecoveryThreads(const CBlockIndex* pIndex) const
|
||||
void CQuorumManager::TriggerQuorumDataRecoveryThreads(CConnman& connman, const CBlockIndex* pIndex) const
|
||||
{
|
||||
if ((m_mn_activeman == nullptr && !IsWatchQuorumsEnabled()) || !QuorumDataRecoveryEnabled() || pIndex == nullptr) {
|
||||
return;
|
||||
@ -296,17 +295,17 @@ void CQuorumManager::TriggerQuorumDataRecoveryThreads(const CBlockIndex* pIndex)
|
||||
}
|
||||
|
||||
// Finally start the thread which triggers the requests for this quorum
|
||||
StartQuorumDataRecoveryThread(pQuorum, pIndex, nDataMask);
|
||||
StartQuorumDataRecoveryThread(connman, pQuorum, pIndex, nDataMask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fInitialDownload) const
|
||||
void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, CConnman& connman, bool fInitialDownload) const
|
||||
{
|
||||
if (!m_mn_sync.IsBlockchainSynced()) return;
|
||||
|
||||
for (const auto& params : Params().GetConsensus().llmqs) {
|
||||
CheckQuorumConnections(params, pindexNew);
|
||||
CheckQuorumConnections(connman, params, pindexNew);
|
||||
}
|
||||
|
||||
if (m_mn_activeman != nullptr || IsWatchQuorumsEnabled()) {
|
||||
@ -322,11 +321,12 @@ void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fInitial
|
||||
}
|
||||
}
|
||||
|
||||
TriggerQuorumDataRecoveryThreads(pindexNew);
|
||||
TriggerQuorumDataRecoveryThreads(connman, pindexNew);
|
||||
StartCleanupOldQuorumDataThread(pindexNew);
|
||||
}
|
||||
|
||||
void CQuorumManager::CheckQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pindexNew) const
|
||||
void CQuorumManager::CheckQuorumConnections(CConnman& connman, const Consensus::LLMQParams& llmqParams,
|
||||
const CBlockIndex* pindexNew) const
|
||||
{
|
||||
if (m_mn_activeman == nullptr && !IsWatchQuorumsEnabled()) return;
|
||||
|
||||
@ -469,7 +469,9 @@ bool CQuorumManager::HasQuorum(Consensus::LLMQType llmqType, const CQuorumBlockP
|
||||
return quorum_block_processor.HasMinedCommitment(llmqType, quorumHash);
|
||||
}
|
||||
|
||||
bool CQuorumManager::RequestQuorumData(CNode* pfrom, Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, uint16_t nDataMask, const uint256& proTxHash) const
|
||||
bool CQuorumManager::RequestQuorumData(CNode* pfrom, CConnman& connman, Consensus::LLMQType llmqType,
|
||||
const CBlockIndex* pQuorumBaseBlockIndex, uint16_t nDataMask,
|
||||
const uint256& proTxHash) const
|
||||
{
|
||||
if (pfrom == nullptr) {
|
||||
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Invalid pfrom: nullptr\n", __func__);
|
||||
@ -697,7 +699,7 @@ size_t CQuorumManager::GetQuorumRecoveryStartOffset(const CQuorumCPtr pQuorum, c
|
||||
return nIndex % pQuorum->qc->validMembers.size();
|
||||
}
|
||||
|
||||
PeerMsgRet CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv)
|
||||
PeerMsgRet CQuorumManager::ProcessMessage(CNode& pfrom, CConnman& connman, const std::string& msg_type, CDataStream& vRecv)
|
||||
{
|
||||
auto strFunc = __func__;
|
||||
auto errorHandler = [&](const std::string& strError, int nScore = 10) -> PeerMsgRet {
|
||||
@ -709,7 +711,6 @@ PeerMsgRet CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_t
|
||||
};
|
||||
|
||||
if (msg_type == NetMsgType::QGETDATA) {
|
||||
|
||||
if (m_mn_activeman == nullptr || (pfrom.GetVerifiedProRegTxHash().IsNull() && !pfrom.qwatch)) {
|
||||
return errorHandler("Not a verified masternode or a qwatch connection");
|
||||
}
|
||||
@ -912,7 +913,8 @@ void CQuorumManager::StartCachePopulatorThread(const CQuorumCPtr pQuorum) const
|
||||
});
|
||||
}
|
||||
|
||||
void CQuorumManager::StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, const CBlockIndex* pIndex, uint16_t nDataMaskIn) const
|
||||
void CQuorumManager::StartQuorumDataRecoveryThread(CConnman& connman, const CQuorumCPtr pQuorum,
|
||||
const CBlockIndex* pIndex, uint16_t nDataMaskIn) const
|
||||
{
|
||||
assert(m_mn_activeman);
|
||||
|
||||
@ -922,7 +924,7 @@ void CQuorumManager::StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, co
|
||||
}
|
||||
pQuorum->fQuorumDataRecoveryThreadRunning = true;
|
||||
|
||||
workerPool.push([pQuorum, pIndex, nDataMaskIn, this](int threadId) {
|
||||
workerPool.push([&connman, pQuorum, pIndex, nDataMaskIn, this](int threadId) {
|
||||
size_t nTries{0};
|
||||
uint16_t nDataMask{nDataMaskIn};
|
||||
int64_t nTimeLastSuccess{0};
|
||||
@ -958,7 +960,6 @@ void CQuorumManager::StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, co
|
||||
printLog("Try to request");
|
||||
|
||||
while (nDataMask > 0 && !quorumThreadInterrupt) {
|
||||
|
||||
if (nDataMask & llmq::CQuorumDataRequest::QUORUM_VERIFICATION_VECTOR &&
|
||||
pQuorum->HasVerificationVector()) {
|
||||
nDataMask &= ~llmq::CQuorumDataRequest::QUORUM_VERIFICATION_VECTOR;
|
||||
@ -1005,7 +1006,8 @@ void CQuorumManager::StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, co
|
||||
return;
|
||||
}
|
||||
|
||||
if (RequestQuorumData(pNode, pQuorum->qc->llmqType, pQuorum->m_quorum_base_block_index, nDataMask, proTxHash)) {
|
||||
if (RequestQuorumData(pNode, connman, pQuorum->qc->llmqType, pQuorum->m_quorum_base_block_index,
|
||||
nDataMask, proTxHash)) {
|
||||
nTimeLastSuccess = GetTime<std::chrono::seconds>().count();
|
||||
printLog("Requested");
|
||||
} else {
|
||||
|
@ -238,7 +238,6 @@ private:
|
||||
|
||||
CBLSWorker& blsWorker;
|
||||
CChainState& m_chainstate;
|
||||
CConnman& connman;
|
||||
CDeterministicMNManager& m_dmnman;
|
||||
CDKGSessionManager& dkgManager;
|
||||
CQuorumBlockProcessor& quorumBlockProcessor;
|
||||
@ -261,7 +260,7 @@ private:
|
||||
mutable CThreadInterrupt quorumThreadInterrupt;
|
||||
|
||||
public:
|
||||
CQuorumManager(CBLSWorker& _blsWorker, CChainState& chainstate, CConnman& _connman, CDeterministicMNManager& dmnman,
|
||||
CQuorumManager(CBLSWorker& _blsWorker, CChainState& chainstate, CDeterministicMNManager& dmnman,
|
||||
CDKGSessionManager& _dkgManager, CEvoDB& _evoDb, CQuorumBlockProcessor& _quorumBlockProcessor,
|
||||
const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync,
|
||||
const CSporkManager& sporkman, bool unit_tests, bool wipe);
|
||||
@ -270,15 +269,17 @@ public:
|
||||
void Start();
|
||||
void Stop();
|
||||
|
||||
void TriggerQuorumDataRecoveryThreads(const CBlockIndex* pIndex) const;
|
||||
void TriggerQuorumDataRecoveryThreads(CConnman& connman, const CBlockIndex* pIndex) const;
|
||||
|
||||
void UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload) const;
|
||||
void UpdatedBlockTip(const CBlockIndex* pindexNew, CConnman& connman, bool fInitialDownload) const;
|
||||
|
||||
PeerMsgRet ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv);
|
||||
PeerMsgRet ProcessMessage(CNode& pfrom, CConnman& connman, const std::string& msg_type, CDataStream& vRecv);
|
||||
|
||||
static bool HasQuorum(Consensus::LLMQType llmqType, const CQuorumBlockProcessor& quorum_block_processor, const uint256& quorumHash);
|
||||
|
||||
bool RequestQuorumData(CNode* pfrom, Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, uint16_t nDataMask, const uint256& proTxHash = uint256()) const;
|
||||
bool RequestQuorumData(CNode* pfrom, CConnman& connman, Consensus::LLMQType llmqType,
|
||||
const CBlockIndex* pQuorumBaseBlockIndex, uint16_t nDataMask,
|
||||
const uint256& proTxHash = uint256()) const;
|
||||
|
||||
// all these methods will lock cs_main for a short period of time
|
||||
CQuorumCPtr GetQuorum(Consensus::LLMQType llmqType, const uint256& quorumHash) const;
|
||||
@ -289,7 +290,8 @@ public:
|
||||
|
||||
private:
|
||||
// all private methods here are cs_main-free
|
||||
void CheckQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex *pindexNew) const;
|
||||
void CheckQuorumConnections(CConnman& connman, const Consensus::LLMQParams& llmqParams,
|
||||
const CBlockIndex* pindexNew) const;
|
||||
|
||||
CQuorumPtr BuildQuorumFromCommitment(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, bool populate_cache) const;
|
||||
bool BuildQuorumContributions(const CFinalCommitmentPtr& fqc, const std::shared_ptr<CQuorum>& quorum) const;
|
||||
@ -301,7 +303,8 @@ private:
|
||||
size_t GetQuorumRecoveryStartOffset(const CQuorumCPtr pQuorum, const CBlockIndex* pIndex) const;
|
||||
|
||||
void StartCachePopulatorThread(const CQuorumCPtr pQuorum) const;
|
||||
void StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, const CBlockIndex* pIndex, uint16_t nDataMask) const;
|
||||
void StartQuorumDataRecoveryThread(CConnman& connman, const CQuorumCPtr pQuorum, const CBlockIndex* pIndex,
|
||||
uint16_t nDataMask) const;
|
||||
|
||||
void StartCleanupOldQuorumDataThread(const CBlockIndex* pIndex) const;
|
||||
void MigrateOldQuorumDB(CEvoDB& evoDb) const;
|
||||
|
@ -5263,7 +5263,7 @@ void PeerManagerImpl::ProcessMessage(
|
||||
ProcessPeerMsgRet(CMNAuth::ProcessMessage(pfrom, peer->m_their_services, m_connman, m_mn_metaman, m_mn_activeman, m_chainman.ActiveChain(), m_mn_sync, m_dmnman->GetListAtChainTip(), msg_type, vRecv), pfrom);
|
||||
PostProcessMessage(m_llmq_ctx->quorum_block_processor->ProcessMessage(pfrom, msg_type, vRecv), pfrom.GetId());
|
||||
ProcessPeerMsgRet(m_llmq_ctx->qdkgsman->ProcessMessage(pfrom, *this, is_masternode, msg_type, vRecv), pfrom);
|
||||
ProcessPeerMsgRet(m_llmq_ctx->qman->ProcessMessage(pfrom, msg_type, vRecv), pfrom);
|
||||
ProcessPeerMsgRet(m_llmq_ctx->qman->ProcessMessage(pfrom, m_connman, msg_type, vRecv), pfrom);
|
||||
m_llmq_ctx->shareman->ProcessMessage(pfrom, m_sporkman, msg_type, vRecv);
|
||||
ProcessPeerMsgRet(m_llmq_ctx->sigman->ProcessMessage(pfrom, msg_type, vRecv), pfrom);
|
||||
|
||||
|
@ -818,7 +818,7 @@ static RPCHelpMan quorum_getdata()
|
||||
const CBlockIndex* pQuorumBaseBlockIndex = WITH_LOCK(cs_main, return chainman.m_blockman.LookupBlockIndex(quorumHash));
|
||||
|
||||
return connman.ForNode(nodeId, [&](CNode* pNode) {
|
||||
return llmq_ctx.qman->RequestQuorumData(pNode, llmqType, pQuorumBaseBlockIndex, nDataMask, proTxHash);
|
||||
return llmq_ctx.qman->RequestQuorumData(pNode, connman, llmqType, pQuorumBaseBlockIndex, nDataMask, proTxHash);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user