Skip to content

Commit e92062c

Browse files
committed
refactor: use gsl::not_null in CQuorumManager wherever possible
1 parent 343f4e3 commit e92062c

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

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

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

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

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

@@ -924,7 +927,7 @@ void CQuorumManager::StartCachePopulatorThread(CQuorumCPtr pQuorum) const
924927
}
925928

926929
void CQuorumManager::StartQuorumDataRecoveryThread(CConnman& connman, CQuorumCPtr pQuorum,
927-
const CBlockIndex* pIndex, uint16_t nDataMaskIn) const
930+
gsl::not_null<const CBlockIndex*> pIndex, uint16_t nDataMaskIn) const
928931
{
929932
assert(m_mn_activeman);
930933

@@ -1093,7 +1096,7 @@ static void DataCleanupHelper(CDBWrapper& db, std::set<uint256> skip_list, bool
10931096
}
10941097
}
10951098

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

src/llmq/quorums.h

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

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

296296
void UpdatedBlockTip(const CBlockIndex* pindexNew, CConnman& connman, bool fInitialDownload) const
@@ -312,15 +312,16 @@ class CQuorumManager
312312
EXCLUSIVE_LOCKS_REQUIRED(!cs_db, !cs_map_quorums, !cs_scan_quorums);
313313

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

319319
bool IsWatching() const { return m_quorums_watch; }
320320

321321
private:
322322
// all private methods here are cs_main-free
323-
void CheckQuorumConnections(CConnman& connman, const Consensus::LLMQParams& llmqParams, const CBlockIndex* pindexNew) const
323+
void CheckQuorumConnections(CConnman& connman, const Consensus::LLMQParams& llmqParams,
324+
gsl::not_null<const CBlockIndex*> pindexNew) const
324325
EXCLUSIVE_LOCKS_REQUIRED(!cs_db, !cs_scan_quorums, !cs_map_quorums);
325326

326327
CQuorumPtr BuildQuorumFromCommitment(Consensus::LLMQType llmqType,
@@ -333,13 +334,13 @@ class CQuorumManager
333334
/// Returns the start offset for the masternode with the given proTxHash. This offset is applied when picking data recovery members of a quorum's
334335
/// 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
335336
/// should receive the same number of request if all active llmqType members requests data from one llmqType quorum.
336-
size_t GetQuorumRecoveryStartOffset(const CQuorum& quorum, const CBlockIndex* pIndex) const;
337+
size_t GetQuorumRecoveryStartOffset(const CQuorum& quorum, gsl::not_null<const CBlockIndex*> pIndex) const;
337338

338339
void StartCachePopulatorThread(CQuorumCPtr pQuorum) const;
339-
void StartQuorumDataRecoveryThread(CConnman& connman, CQuorumCPtr pQuorum, const CBlockIndex* pIndex,
340+
void StartQuorumDataRecoveryThread(CConnman& connman, CQuorumCPtr pQuorum, gsl::not_null<const CBlockIndex*> pIndex,
340341
uint16_t nDataMask) const;
341342

342-
void StartCleanupOldQuorumDataThread(const CBlockIndex* pIndex) const;
343+
void StartCleanupOldQuorumDataThread(gsl::not_null<const CBlockIndex*> pIndex) const;
343344
void MigrateOldQuorumDB(CEvoDB& evoDb) const EXCLUSIVE_LOCKS_REQUIRED(!cs_db);
344345
};
345346

0 commit comments

Comments
 (0)