Skip to content

Commit 055dbba

Browse files
committed
refactor: move GetListAtChainTip() calls out of llmq::utils::*, misc changes
1 parent da39b73 commit 055dbba

File tree

6 files changed

+24
-21
lines changed

6 files changed

+24
-21
lines changed

src/coinjoin/client.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ PeerMsgRet CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataS
4949
return tl::unexpected{100};
5050
}
5151

52+
const auto tip_mn_list = deterministicMNManager->GetListAtChainTip();
5253
if (dsq.masternodeOutpoint.IsNull()) {
53-
auto mnList = deterministicMNManager->GetListAtChainTip();
54-
if (auto dmn = mnList.GetValidMN(dsq.m_protxHash)) {
54+
if (auto dmn = tip_mn_list.GetValidMN(dsq.m_protxHash)) {
5555
dsq.masternodeOutpoint = dmn->collateralOutpoint;
5656
} else {
5757
return tl::unexpected{10};
@@ -82,8 +82,7 @@ PeerMsgRet CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataS
8282

8383
if (dsq.IsTimeOutOfBounds()) return {};
8484

85-
auto mnList = deterministicMNManager->GetListAtChainTip();
86-
auto dmn = mnList.GetValidMNByCollateral(dsq.masternodeOutpoint);
85+
auto dmn = tip_mn_list.GetValidMNByCollateral(dsq.masternodeOutpoint);
8786
if (!dmn) return {};
8887

8988
if (dsq.m_protxHash.IsNull()) {
@@ -105,7 +104,7 @@ PeerMsgRet CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataS
105104
return {};
106105
} else {
107106
int64_t nLastDsq = mmetaman->GetMetaInfo(dmn->proTxHash)->GetLastDsq();
108-
int64_t nDsqThreshold = mmetaman->GetDsqThreshold(dmn->proTxHash, mnList.GetValidMNsCount());
107+
int64_t nDsqThreshold = mmetaman->GetDsqThreshold(dmn->proTxHash, tip_mn_list.GetValidMNsCount());
109108
LogPrint(BCLog::COINJOIN, "DSQUEUE -- nLastDsq: %d nDsqThreshold: %d nDsqCount: %d\n", nLastDsq,
110109
nDsqThreshold, mmetaman->GetDsqCount());
111110
// don't allow a few nodes to dominate the queuing process

src/coinjoin/server.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ PeerMsgRet CCoinJoinServer::ProcessDSQUEUE(const CNode& peer, CDataStream& vRecv
115115
return tl::unexpected{100};
116116
}
117117

118+
const auto tip_mn_list = deterministicMNManager->GetListAtChainTip();
118119
if (dsq.masternodeOutpoint.IsNull()) {
119-
auto mnList = deterministicMNManager->GetListAtChainTip();
120-
if (auto dmn = mnList.GetValidMN(dsq.m_protxHash)) {
120+
if (auto dmn = tip_mn_list.GetValidMN(dsq.m_protxHash)) {
121121
dsq.masternodeOutpoint = dmn->collateralOutpoint;
122122
} else {
123123
return tl::unexpected{10};
@@ -145,8 +145,7 @@ PeerMsgRet CCoinJoinServer::ProcessDSQUEUE(const CNode& peer, CDataStream& vRecv
145145

146146
if (dsq.IsTimeOutOfBounds()) return {};
147147

148-
auto mnList = deterministicMNManager->GetListAtChainTip();
149-
auto dmn = mnList.GetValidMNByCollateral(dsq.masternodeOutpoint);
148+
auto dmn = tip_mn_list.GetValidMNByCollateral(dsq.masternodeOutpoint);
150149
if (!dmn) return {};
151150

152151
if (dsq.m_protxHash.IsNull()) {
@@ -159,7 +158,7 @@ PeerMsgRet CCoinJoinServer::ProcessDSQUEUE(const CNode& peer, CDataStream& vRecv
159158

160159
if (!dsq.fReady) {
161160
int64_t nLastDsq = mmetaman->GetMetaInfo(dmn->proTxHash)->GetLastDsq();
162-
int64_t nDsqThreshold = mmetaman->GetDsqThreshold(dmn->proTxHash, mnList.GetValidMNsCount());
161+
int64_t nDsqThreshold = mmetaman->GetDsqThreshold(dmn->proTxHash, tip_mn_list.GetValidMNsCount());
163162
LogPrint(BCLog::COINJOIN, "DSQUEUE -- nLastDsq: %d nDsqThreshold: %d nDsqCount: %d\n", nLastDsq, nDsqThreshold, mmetaman->GetDsqCount());
164163
//don't allow a few nodes to dominate the queuing process
165164
if (nLastDsq != 0 && nDsqThreshold > mmetaman->GetDsqCount()) {

src/llmq/dkgsessionhandler.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,10 @@ void CDKGSessionHandler::HandleDKGRound()
527527
return changed;
528528
});
529529

530-
utils::EnsureQuorumConnections(params, connman, m_sporkman, pQuorumBaseBlockIndex, curSession->myProTxHash);
530+
const auto tip_mn_list = deterministicMNManager->GetListAtChainTip();
531+
utils::EnsureQuorumConnections(params, connman, m_sporkman, tip_mn_list, pQuorumBaseBlockIndex, curSession->myProTxHash);
531532
if (curSession->AreWeMember()) {
532-
utils::AddQuorumProbeConnections(params, connman, m_sporkman, pQuorumBaseBlockIndex, curSession->myProTxHash);
533+
utils::AddQuorumProbeConnections(params, connman, m_sporkman, tip_mn_list, pQuorumBaseBlockIndex, curSession->myProTxHash);
533534
}
534535

535536
WaitForNextPhase(QuorumPhase::Initialized, QuorumPhase::Contribute, curQuorumHash);

src/llmq/quorums.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ void CQuorumManager::CheckQuorumConnections(const Consensus::LLMQParams& llmqPar
349349
});
350350

351351
for (const auto& quorum : lastQuorums) {
352-
if (utils::EnsureQuorumConnections(llmqParams, connman, m_sporkman, quorum->m_quorum_base_block_index, myProTxHash)) {
352+
if (utils::EnsureQuorumConnections(llmqParams, connman, m_sporkman, deterministicMNManager->GetListAtChainTip(), quorum->m_quorum_base_block_index, myProTxHash)) {
353353
if (connmanQuorumsToDelete.erase(quorum->qc->quorumHash) > 0) {
354354
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- llmqType[%d] h[%d] keeping mn quorum connections for quorum: [%d:%s]\n", __func__, ToUnderlying(llmqParams.type), pindexNew->nHeight, quorum->m_quorum_base_block_index->nHeight, quorum->m_quorum_base_block_index->GetBlockHash().ToString());
355355
}

src/llmq/utils.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,8 @@ std::set<size_t> CalcDeterministicWatchConnections(Consensus::LLMQType llmqType,
750750
}
751751

752752
bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, CConnman& connman, const CSporkManager& sporkman,
753-
gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, const uint256& myProTxHash)
753+
const CDeterministicMNList& tip_mn_list, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex,
754+
const uint256& myProTxHash)
754755
{
755756
if (!fMasternodeMode && !IsWatchQuorumsEnabled()) {
756757
return false;
@@ -784,10 +785,9 @@ bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, CConnman&
784785
}
785786
if (!connections.empty()) {
786787
if (!connman.HasMasternodeQuorumNodes(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash()) && LogAcceptCategory(BCLog::LLMQ)) {
787-
auto mnList = deterministicMNManager->GetListAtChainTip();
788788
std::string debugMsg = strprintf("%s -- adding masternodes quorum connections for quorum %s:\n", __func__, pQuorumBaseBlockIndex->GetBlockHash().ToString());
789789
for (const auto& c : connections) {
790-
auto dmn = mnList.GetValidMN(c);
790+
auto dmn = tip_mn_list.GetValidMN(c);
791791
if (!dmn) {
792792
debugMsg += strprintf(" %s (not in valid MN set anymore)\n", c.ToString());
793793
} else {
@@ -805,7 +805,8 @@ bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, CConnman&
805805
}
806806

807807
void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, CConnman& connman, const CSporkManager& sporkman,
808-
gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, const uint256 &myProTxHash)
808+
const CDeterministicMNList& tip_mn_list, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex,
809+
const uint256 &myProTxHash)
809810
{
810811
if (!IsQuorumPoseEnabled(llmqParams.type, sporkman)) {
811812
return;
@@ -829,10 +830,9 @@ void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, CConnman
829830

830831
if (!probeConnections.empty()) {
831832
if (LogAcceptCategory(BCLog::LLMQ)) {
832-
auto mnList = deterministicMNManager->GetListAtChainTip();
833833
std::string debugMsg = strprintf("%s -- adding masternodes probes for quorum %s:\n", __func__, pQuorumBaseBlockIndex->GetBlockHash().ToString());
834834
for (const auto& c : probeConnections) {
835-
auto dmn = mnList.GetValidMN(c);
835+
auto dmn = tip_mn_list.GetValidMN(c);
836836
if (!dmn) {
837837
debugMsg += strprintf(" %s (not in valid MN set anymore)\n", c.ToString());
838838
} else {

src/llmq/utils.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ std::set<uint256> GetQuorumConnections(const Consensus::LLMQParams& llmqParams,
3535
std::set<uint256> GetQuorumRelayMembers(const Consensus::LLMQParams& llmqParams, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound);
3636
std::set<size_t> CalcDeterministicWatchConnections(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, size_t memberCount, size_t connectionCount);
3737

38-
bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, CConnman& connman, const CSporkManager& sporkman, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, const uint256& myProTxHash);
39-
void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, CConnman& connman, const CSporkManager& sporkman, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, const uint256& myProTxHash);
38+
bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, CConnman& connman, const CSporkManager& sporkman,
39+
const CDeterministicMNList& tip_mn_list, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex,
40+
const uint256& myProTxHash);
41+
void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, CConnman& connman, const CSporkManager& sporkman,
42+
const CDeterministicMNList& tip_mn_list, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex,
43+
const uint256& myProTxHash);
4044

4145
template <typename CacheType>
4246
void InitQuorumsCache(CacheType& cache, bool limit_by_connections = true);

0 commit comments

Comments
 (0)