Skip to content

Commit a2d909b

Browse files
committed
refactor: pull deletable quorums routine to dedicated function
Needed to split logic based on watch-only or masternode-mode in next commit.
1 parent eaee1a8 commit a2d909b

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/active/quorums.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,9 @@ void QuorumParticipant::UpdatedBlockTip(const CBlockIndex* pindexNew, CConnman&
8484
StartCleanupOldQuorumDataThread(pindexNew);
8585
}
8686

87-
void QuorumParticipant::CheckQuorumConnections(CConnman& connman, const Consensus::LLMQParams& llmqParams,
88-
gsl::not_null<const CBlockIndex*> pindexNew) const
87+
Uint256HashSet QuorumParticipant::GetQuorumsToDelete(CConnman& connman, const Consensus::LLMQParams& llmqParams,
88+
gsl::not_null<const CBlockIndex*> pindexNew) const
8989
{
90-
if (m_mn_activeman == nullptr && !m_quorums_watch) return;
91-
92-
auto lastQuorums = m_qman.ScanQuorums(llmqParams.type, pindexNew, (size_t)llmqParams.keepOldConnections);
93-
9490
auto connmanQuorumsToDelete = connman.GetMasternodeQuorums(llmqParams.type);
9591

9692
// don't remove connections for the currently in-progress DKG round
@@ -114,6 +110,17 @@ void QuorumParticipant::CheckQuorumConnections(CConnman& connman, const Consensu
114110
LogPrint(BCLog::LLMQ, "QuorumParticipant::%s -- llmqType[%d] h[%d] keeping mn quorum connections for quorum: [%d:%s]\n", __func__, ToUnderlying(llmqParams.type), pindexNew->nHeight, curDkgHeight, curDkgBlock.ToString());
115111
}
116112

113+
return connmanQuorumsToDelete;
114+
}
115+
116+
void QuorumParticipant::CheckQuorumConnections(CConnman& connman, const Consensus::LLMQParams& llmqParams,
117+
gsl::not_null<const CBlockIndex*> pindexNew) const
118+
{
119+
if (m_mn_activeman == nullptr && !m_quorums_watch) return;
120+
121+
auto lastQuorums = m_qman.ScanQuorums(llmqParams.type, pindexNew, (size_t)llmqParams.keepOldConnections);
122+
auto deletableQuorums = GetQuorumsToDelete(connman, llmqParams, pindexNew);
123+
117124
const uint256 myProTxHash = m_mn_activeman != nullptr ? m_mn_activeman->GetProTxHash() : uint256();
118125

119126
bool isISType = llmqParams.type == Params().GetConsensus().llmqTypeDIP0024InstantSend;
@@ -126,7 +133,7 @@ void QuorumParticipant::CheckQuorumConnections(CConnman& connman, const Consensu
126133
for (const auto& quorum : lastQuorums) {
127134
if (utils::EnsureQuorumConnections(llmqParams, connman, m_sporkman, {m_dmnman, m_qsnapman, m_chainman, quorum->m_quorum_base_block_index},
128135
m_dmnman.GetListAtChainTip(), myProTxHash, /*is_masternode=*/m_mn_activeman != nullptr, m_quorums_watch)) {
129-
if (connmanQuorumsToDelete.erase(quorum->qc->quorumHash) > 0) {
136+
if (deletableQuorums.erase(quorum->qc->quorumHash) > 0) {
130137
LogPrint(BCLog::LLMQ, "QuorumParticipant::%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());
131138
}
132139
} else if (watchOtherISQuorums && !quorum->IsMember(myProTxHash)) {
@@ -141,13 +148,14 @@ void QuorumParticipant::CheckQuorumConnections(CConnman& connman, const Consensu
141148
connman.SetMasternodeQuorumNodes(llmqParams.type, quorum->m_quorum_base_block_index->GetBlockHash(), connections);
142149
connman.SetMasternodeQuorumRelayMembers(llmqParams.type, quorum->m_quorum_base_block_index->GetBlockHash(), connections);
143150
}
144-
if (connmanQuorumsToDelete.erase(quorum->qc->quorumHash) > 0) {
151+
if (deletableQuorums.erase(quorum->qc->quorumHash) > 0) {
145152
LogPrint(BCLog::LLMQ, "QuorumParticipant::%s -- llmqType[%d] h[%d] keeping mn inter-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());
146153
}
147154
}
148155
}
149156
}
150-
for (const auto& quorumHash : connmanQuorumsToDelete) {
157+
158+
for (const auto& quorumHash : deletableQuorums) {
151159
LogPrint(BCLog::LLMQ, "QuorumParticipant::%s -- removing masternodes quorum connections for quorum %s:\n", __func__, quorumHash.ToString());
152160
connman.RemoveMasternodeQuorumNodes(llmqParams.type, quorumHash);
153161
}

src/active/quorums.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,15 @@ class QuorumParticipant
8181
/// llmqType members requests data from one llmqType quorum.
8282
size_t GetQuorumRecoveryStartOffset(const CQuorum& quorum, gsl::not_null<const CBlockIndex*> pIndex) const;
8383

84-
void CheckQuorumConnections(CConnman& connman, const Consensus::LLMQParams& llmqParams,
85-
gsl::not_null<const CBlockIndex*> pindexNew) const;
8684
void StartCleanupOldQuorumDataThread(gsl::not_null<const CBlockIndex*> pIndex) const;
8785
void TriggerQuorumDataRecoveryThreads(CConnman& connman, gsl::not_null<const CBlockIndex*> pIndex) const;
8886

87+
//! Connection
88+
Uint256HashSet GetQuorumsToDelete(CConnman& connman, const Consensus::LLMQParams& llmqParams,
89+
gsl::not_null<const CBlockIndex*> pindexNew) const;
90+
void CheckQuorumConnections(CConnman& connman, const Consensus::LLMQParams& llmqParams,
91+
gsl::not_null<const CBlockIndex*> pindexNew) const;
92+
8993
//! Data recovery
9094
void DataRecoveryThread(CConnman& connman, gsl::not_null<const CBlockIndex*> block_index, CQuorumCPtr quorum,
9195
uint16_t data_mask, const uint256& protx_hash, size_t start_offset) const;

0 commit comments

Comments
 (0)