Skip to content

Commit 2c6cbc9

Browse files
committed
refactor: use gsl::not_null in CQuorumManager wherever possible
1 parent 8f8078f commit 2c6cbc9

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/llmq/quorums.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ void CQuorumManager::Stop()
251251
workerPool.stop(true);
252252
}
253253

254-
void CQuorumManager::TriggerQuorumDataRecoveryThreads(CConnman& connman, const CBlockIndex* pIndex) const
254+
void CQuorumManager::TriggerQuorumDataRecoveryThreads(CConnman& connman, gsl::not_null<const CBlockIndex*> pIndex) const
255255
{
256-
if ((m_mn_activeman == nullptr && !m_quorums_watch) || !m_quorums_recovery || pIndex == nullptr) {
256+
if ((m_mn_activeman == nullptr && !m_quorums_watch) || !m_quorums_recovery) {
257257
return;
258258
}
259259

@@ -304,6 +304,7 @@ void CQuorumManager::TriggerQuorumDataRecoveryThreads(CConnman& connman, const C
304304

305305
void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, CConnman& connman, bool fInitialDownload) const
306306
{
307+
if (!pindexNew) return;
307308
if (!m_mn_sync.IsBlockchainSynced()) return;
308309

309310
for (const auto& params : Params().GetConsensus().llmqs) {
@@ -328,7 +329,7 @@ void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, CConnman& con
328329
}
329330

330331
void CQuorumManager::CheckQuorumConnections(CConnman& connman, const Consensus::LLMQParams& llmqParams,
331-
const CBlockIndex* pindexNew) const
332+
gsl::not_null<const CBlockIndex*> pindexNew) const
332333
{
333334
if (m_mn_activeman == nullptr && !m_quorums_watch) return;
334335

@@ -530,9 +531,11 @@ std::vector<CQuorumCPtr> CQuorumManager::ScanQuorums(Consensus::LLMQType llmqTyp
530531
return ScanQuorums(llmqType, pindex, nCountRequested);
531532
}
532533

533-
std::vector<CQuorumCPtr> CQuorumManager::ScanQuorums(Consensus::LLMQType llmqType, const CBlockIndex* pindexStart, size_t nCountRequested) const
534+
std::vector<CQuorumCPtr> CQuorumManager::ScanQuorums(Consensus::LLMQType llmqType,
535+
gsl::not_null<const CBlockIndex*> pindexStart,
536+
size_t nCountRequested) const
534537
{
535-
if (pindexStart == nullptr || nCountRequested == 0 || !m_chainman.IsQuorumTypeEnabled(llmqType, pindexStart)) {
538+
if (nCountRequested == 0 || !m_chainman.IsQuorumTypeEnabled(llmqType, pindexStart)) {
536539
return {};
537540
}
538541

@@ -679,7 +682,7 @@ CQuorumCPtr CQuorumManager::GetQuorum(Consensus::LLMQType llmqType, gsl::not_nul
679682
return BuildQuorumFromCommitment(llmqType, pQuorumBaseBlockIndex, populate_cache);
680683
}
681684

682-
size_t CQuorumManager::GetQuorumRecoveryStartOffset(const CQuorum& quorum, const CBlockIndex* pIndex) const
685+
size_t CQuorumManager::GetQuorumRecoveryStartOffset(const CQuorum& quorum, gsl::not_null<const CBlockIndex*> pIndex) const
683686
{
684687
assert(m_mn_activeman);
685688

@@ -922,7 +925,7 @@ void CQuorumManager::StartCachePopulatorThread(CQuorumCPtr pQuorum) const
922925
}
923926

924927
void CQuorumManager::StartQuorumDataRecoveryThread(CConnman& connman, CQuorumCPtr pQuorum,
925-
const CBlockIndex* pIndex, uint16_t nDataMaskIn) const
928+
gsl::not_null<const CBlockIndex*> pIndex, uint16_t nDataMaskIn) const
926929
{
927930
assert(m_mn_activeman);
928931

@@ -1091,7 +1094,7 @@ static void DataCleanupHelper(CDBWrapper& db, std::set<uint256> skip_list, bool
10911094
}
10921095
}
10931096

1094-
void CQuorumManager::StartCleanupOldQuorumDataThread(const CBlockIndex* pIndex) const
1097+
void CQuorumManager::StartCleanupOldQuorumDataThread(gsl::not_null<const CBlockIndex*> pIndex) const
10951098
{
10961099
// Note: this function is CPU heavy and we don't want it to be running during DKGs.
10971100
// The largest dkgMiningWindowStart for a related quorum type is 42 (LLMQ_60_75).
@@ -1100,7 +1103,7 @@ void CQuorumManager::StartCleanupOldQuorumDataThread(const CBlockIndex* pIndex)
11001103
// window and it's better to have more room so we pick next cycle.
11011104
// dkgMiningWindowStart for small quorums is 10 i.e. a safe block to start
11021105
// these calculations is at height 576 + 24 * 2 + 10 = 576 + 58.
1103-
if ((m_mn_activeman == nullptr && !m_quorums_watch) || pIndex == nullptr || (pIndex->nHeight % 576 != 58)) {
1106+
if ((m_mn_activeman == nullptr && !m_quorums_watch) || (pIndex->nHeight % 576 != 58)) {
11041107
return;
11051108
}
11061109

src/llmq/quorums.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class CQuorumManager
292292
void Start();
293293
void Stop();
294294

295-
void TriggerQuorumDataRecoveryThreads(CConnman& connman, const CBlockIndex* pIndex) const
295+
void TriggerQuorumDataRecoveryThreads(CConnman& connman, gsl::not_null<const CBlockIndex*> pIndex) const
296296
EXCLUSIVE_LOCKS_REQUIRED(!cs_db, !cs_scan_quorums, !cs_map_quorums);
297297

298298
void UpdatedBlockTip(const CBlockIndex* pindexNew, CConnman& connman, bool fInitialDownload) const
@@ -314,15 +314,16 @@ class CQuorumManager
314314
EXCLUSIVE_LOCKS_REQUIRED(!cs_db, !cs_map_quorums, !cs_scan_quorums);
315315

316316
// this one is cs_main-free
317-
std::vector<CQuorumCPtr> ScanQuorums(Consensus::LLMQType llmqType, const CBlockIndex* pindexStart,
317+
std::vector<CQuorumCPtr> ScanQuorums(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pindexStart,
318318
size_t nCountRequested) const
319319
EXCLUSIVE_LOCKS_REQUIRED(!cs_db, !cs_map_quorums, !cs_scan_quorums);
320320

321321
bool IsWatching() const { return m_quorums_watch; }
322322

323323
private:
324324
// all private methods here are cs_main-free
325-
void CheckQuorumConnections(CConnman& connman, const Consensus::LLMQParams& llmqParams, const CBlockIndex* pindexNew) const
325+
void CheckQuorumConnections(CConnman& connman, const Consensus::LLMQParams& llmqParams,
326+
gsl::not_null<const CBlockIndex*> pindexNew) const
326327
EXCLUSIVE_LOCKS_REQUIRED(!cs_db, !cs_scan_quorums, !cs_map_quorums);
327328

328329
CQuorumPtr BuildQuorumFromCommitment(Consensus::LLMQType llmqType,
@@ -335,13 +336,13 @@ class CQuorumManager
335336
/// Returns the start offset for the masternode with the given proTxHash. This offset is applied when picking data recovery members of a quorum's
336337
/// memberlist and is calculated based on a list of all member of all active quorums for the given llmqType in a way that each member
337338
/// should receive the same number of request if all active llmqType members requests data from one llmqType quorum.
338-
size_t GetQuorumRecoveryStartOffset(const CQuorum& quorum, const CBlockIndex* pIndex) const;
339+
size_t GetQuorumRecoveryStartOffset(const CQuorum& quorum, gsl::not_null<const CBlockIndex*> pIndex) const;
339340

340341
void StartCachePopulatorThread(CQuorumCPtr pQuorum) const;
341-
void StartQuorumDataRecoveryThread(CConnman& connman, CQuorumCPtr pQuorum, const CBlockIndex* pIndex,
342+
void StartQuorumDataRecoveryThread(CConnman& connman, CQuorumCPtr pQuorum, gsl::not_null<const CBlockIndex*> pIndex,
342343
uint16_t nDataMask) const;
343344

344-
void StartCleanupOldQuorumDataThread(const CBlockIndex* pIndex) const;
345+
void StartCleanupOldQuorumDataThread(gsl::not_null<const CBlockIndex*> pIndex) const;
345346
void MigrateOldQuorumDB(CEvoDB& evoDb) const EXCLUSIVE_LOCKS_REQUIRED(!cs_db);
346347
};
347348

0 commit comments

Comments
 (0)