Skip to content

Commit ff71875

Browse files
committed
refactor: drop Params() use in llmq/utils.cpp
1 parent 8a3d852 commit ff71875

File tree

6 files changed

+37
-41
lines changed

6 files changed

+37
-41
lines changed

src/evo/cbtx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ auto CachedGetQcHashesQcIndexedHashes(const CBlockIndex* pindexPrev, const llmq:
7272
qcHashes_cached.clear();
7373
qcIndexedHashes_cached.clear();
7474
if (qc_hashes_cached.empty()) {
75-
llmq::utils::InitQuorumsCache(qc_hashes_cached);
75+
llmq::utils::InitQuorumsCache(qc_hashes_cached, Params().GetConsensus());
7676
}
7777

7878
for (const auto& [llmqType, vecBlockIndexes] : quorums) {

src/llmq/blockprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ CQuorumBlockProcessor::CQuorumBlockProcessor(CChainState& chainstate, CDetermini
5252
m_evoDb{evoDb},
5353
m_qsnapman{qsnapman}
5454
{
55-
utils::InitQuorumsCache(mapHasMinedCommitmentCache);
55+
utils::InitQuorumsCache(mapHasMinedCommitmentCache, m_chainstate.m_chainman.GetConsensus());
5656
LogPrintf("BLS verification uses %d additional threads\n", bls_threads);
5757
m_bls_queue.StartWorkerThreads(bls_threads);
5858
}

src/llmq/dkgsessionmgr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ MessageProcessingResult CDKGSessionManager::ProcessMessage(CNode& pfrom, bool is
144144
{
145145
LOCK(cs_indexedQuorumsCache);
146146
if (indexedQuorumsCache.empty()) {
147-
utils::InitQuorumsCache(indexedQuorumsCache);
147+
utils::InitQuorumsCache(indexedQuorumsCache, m_chainman.GetConsensus());
148148
}
149149
indexedQuorumsCache[llmqType].get(quorumHash, quorumIndex);
150150
}

src/llmq/quorums.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ CQuorumManager::CQuorumManager(CBLSWorker& _blsWorker, CDeterministicMNManager&
226226
m_quorums_watch{quorums_watch},
227227
db{util::MakeDbWrapper({db_params.path / "llmq" / "quorumdb", db_params.memory, db_params.wipe, /*cache_size=*/1 << 20})}
228228
{
229-
utils::InitQuorumsCache(mapQuorumsCache, false);
229+
utils::InitQuorumsCache(mapQuorumsCache, m_chainman.GetConsensus(), /*limit_by_connections=*/false);
230230
quorumThreadInterrupt.reset();
231231
MigrateOldQuorumDB(_evoDb);
232232
}
@@ -1114,7 +1114,7 @@ void CQuorumManager::StartCleanupOldQuorumDataThread(gsl::not_null<const CBlockI
11141114
std::set<uint256> dbKeysToSkip;
11151115

11161116
if (LOCK(cs_cleanup); cleanupQuorumsCache.empty()) {
1117-
utils::InitQuorumsCache(cleanupQuorumsCache, false);
1117+
utils::InitQuorumsCache(cleanupQuorumsCache, m_chainman.GetConsensus(), /*limit_by_connections=*/false);
11181118
}
11191119
for (const auto& params : Params().GetConsensus().llmqs) {
11201120
if (quorumThreadInterrupt) {

src/llmq/utils.cpp

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ arith_uint256 calculateQuorumScore(const CDeterministicMNCPtr& dmn, const uint25
8282
return UintToArith256(h);
8383
}
8484

85-
uint256 GetHashModifier(const Consensus::LLMQParams& llmqParams, gsl::not_null<const CBlockIndex*> pCycleQuorumBaseBlockIndex)
85+
uint256 GetHashModifier(const Consensus::LLMQParams& llmqParams, const Consensus::Params& consensus_params,
86+
gsl::not_null<const CBlockIndex*> pCycleQuorumBaseBlockIndex)
8687
{
8788
ASSERT_IF_DEBUG(pCycleQuorumBaseBlockIndex->nHeight % llmqParams.dkgInterval == 0);
8889
const CBlockIndex* pWorkBlockIndex = pCycleQuorumBaseBlockIndex->GetAncestor(pCycleQuorumBaseBlockIndex->nHeight - llmq::WORK_DIFF_DEPTH);
8990

90-
if (DeploymentActiveAfter(pWorkBlockIndex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20)) {
91+
if (DeploymentActiveAfter(pWorkBlockIndex, consensus_params, Consensus::DEPLOYMENT_V20)) {
9192
// v20 is active: calculate modifier using the new way.
9293
auto cbcl = GetNonNullCoinbaseChainlock(pWorkBlockIndex);
9394
if (cbcl.has_value()) {
@@ -178,7 +179,7 @@ QuorumMembers CalculateQuorum(List&& mn_list, const uint256& modifier, size_t ma
178179
}
179180

180181
std::vector<QuorumMembers> GetQuorumQuarterMembersBySnapshot(
181-
const Consensus::LLMQParams& llmqParams, CDeterministicMNManager& dmnman,
182+
const Consensus::LLMQParams& llmqParams, CDeterministicMNManager& dmnman, const Consensus::Params& consensus_params,
182183
const CBlockIndex* pCycleQuorumBaseBlockIndex, const llmq::CQuorumSnapshot& snapshot, int nHeight)
183184
{
184185
if (!llmqParams.useRotation || pCycleQuorumBaseBlockIndex->nHeight % llmqParams.dkgInterval != 0) {
@@ -191,7 +192,7 @@ std::vector<QuorumMembers> GetQuorumQuarterMembersBySnapshot(
191192
const CBlockIndex* pWorkBlockIndex = pCycleQuorumBaseBlockIndex->GetAncestor(
192193
pCycleQuorumBaseBlockIndex->nHeight - llmq::WORK_DIFF_DEPTH);
193194
auto mn_list = dmnman.GetListForBlock(pWorkBlockIndex);
194-
const auto modifier = GetHashModifier(llmqParams, pCycleQuorumBaseBlockIndex);
195+
const auto modifier = GetHashModifier(llmqParams, consensus_params, pCycleQuorumBaseBlockIndex);
195196
auto sortedAllMns = CalculateQuorum(mn_list, modifier);
196197

197198
std::vector<CDeterministicMNCPtr> usedMNs;
@@ -278,32 +279,32 @@ std::vector<QuorumMembers> GetQuorumQuarterMembersBySnapshot(
278279
}
279280
}
280281

281-
QuorumMembers ComputeQuorumMembers(Consensus::LLMQType llmqType, const CDeterministicMNList& mn_list, const CBlockIndex* pQuorumBaseBlockIndex)
282+
QuorumMembers ComputeQuorumMembers(Consensus::LLMQType llmqType, const CChainParams& chainparams,
283+
const CDeterministicMNList& mn_list, const CBlockIndex* pQuorumBaseBlockIndex)
282284
{
283-
bool EvoOnly = (Params().GetConsensus().llmqTypePlatform == llmqType) && DeploymentActiveAfter(pQuorumBaseBlockIndex, Params().GetConsensus(), Consensus::DEPLOYMENT_V19);
284-
const auto& llmq_params_opt = Params().GetLLMQ(llmqType);
285+
bool EvoOnly = (chainparams.GetConsensus().llmqTypePlatform == llmqType) && DeploymentActiveAfter(pQuorumBaseBlockIndex, chainparams.GetConsensus(), Consensus::DEPLOYMENT_V19);
286+
const auto& llmq_params_opt = chainparams.GetLLMQ(llmqType);
285287
assert(llmq_params_opt.has_value());
286288
if (llmq_params_opt->useRotation || pQuorumBaseBlockIndex->nHeight % llmq_params_opt->dkgInterval != 0) {
287289
ASSERT_IF_DEBUG(false);
288290
return {};
289291
}
290292

291-
const auto modifier = GetHashModifier(llmq_params_opt.value(), pQuorumBaseBlockIndex);
293+
const auto modifier = GetHashModifier(llmq_params_opt.value(), chainparams.GetConsensus(), pQuorumBaseBlockIndex);
292294
return CalculateQuorum(mn_list, modifier, llmq_params_opt->size, EvoOnly);
293295
}
294296

295-
void BuildQuorumSnapshot(const Consensus::LLMQParams& llmqParams, const CDeterministicMNList& allMns,
297+
void BuildQuorumSnapshot(const Consensus::LLMQParams& llmqParams, const Consensus::Params& consensus_params, const CDeterministicMNList& allMns,
296298
const CDeterministicMNList& mnUsedAtH, std::vector<CDeterministicMNCPtr>& sortedCombinedMns,
297-
llmq::CQuorumSnapshot& quorumSnapshot, int nHeight, std::vector<int>& skipList,
298-
const CBlockIndex* pCycleQuorumBaseBlockIndex)
299+
llmq::CQuorumSnapshot& quorumSnapshot, std::vector<int>& skipList, const CBlockIndex* pCycleQuorumBaseBlockIndex)
299300
{
300301
if (!llmqParams.useRotation || pCycleQuorumBaseBlockIndex->nHeight % llmqParams.dkgInterval != 0) {
301302
ASSERT_IF_DEBUG(false);
302303
return;
303304
}
304305

305306
quorumSnapshot.activeQuorumMembers.resize(allMns.GetAllMNsCount());
306-
const auto modifier = GetHashModifier(llmqParams, pCycleQuorumBaseBlockIndex);
307+
const auto modifier = GetHashModifier(llmqParams, consensus_params, pCycleQuorumBaseBlockIndex);
307308
auto sortedAllMns = CalculateQuorum(allMns, modifier);
308309

309310
LogPrint(BCLog::LLMQ, "BuildQuorumSnapshot h[%d] numMns[%d]\n", pCycleQuorumBaseBlockIndex->nHeight, allMns.GetAllMNsCount());
@@ -328,11 +329,10 @@ void BuildQuorumSnapshot(const Consensus::LLMQParams& llmqParams, const CDetermi
328329
}
329330
}
330331

331-
std::vector<QuorumMembers> BuildNewQuorumQuarterMembers(
332-
const Consensus::LLMQParams& llmqParams, llmq::CQuorumSnapshotManager& qsnapman, const CDeterministicMNList& allMns,
333-
const CBlockIndex* pCycleQuorumBaseBlockIndex, const PreviousQuorumQuarters& previousQuarters)
332+
std::vector<QuorumMembers> BuildNewQuorumQuarterMembers(const Consensus::LLMQParams& llmqParams, const llmq::utils::UtilParameters& util_params,
333+
const CDeterministicMNList& allMns, const PreviousQuorumQuarters& previousQuarters)
334334
{
335-
if (!llmqParams.useRotation || pCycleQuorumBaseBlockIndex->nHeight % llmqParams.dkgInterval != 0) {
335+
if (!llmqParams.useRotation || util_params.m_base_index->nHeight % llmqParams.dkgInterval != 0) {
336336
ASSERT_IF_DEBUG(false);
337337
return {};
338338
}
@@ -342,8 +342,7 @@ std::vector<QuorumMembers> BuildNewQuorumQuarterMembers(
342342

343343
size_t quorumSize = static_cast<size_t>(llmqParams.size);
344344
auto quarterSize{quorumSize / 4};
345-
const auto modifier = GetHashModifier(llmqParams, pCycleQuorumBaseBlockIndex);
346-
345+
const auto modifier = GetHashModifier(llmqParams, util_params.m_chainman.GetConsensus(), util_params.m_base_index);
347346

348347
if (allMns.GetValidMNsCount() < quarterSize) {
349348
return quarterQuorumMembers;
@@ -352,7 +351,7 @@ std::vector<QuorumMembers> BuildNewQuorumQuarterMembers(
352351
auto MnsUsedAtH = CDeterministicMNList();
353352
std::vector<CDeterministicMNList> MnsUsedAtHIndexed{nQuorums};
354353

355-
bool skipRemovedMNs = DeploymentActiveAfter(pCycleQuorumBaseBlockIndex, Params().GetConsensus(), Consensus::DEPLOYMENT_V19) || (Params().NetworkIDString() == CBaseChainParams::TESTNET);
354+
bool skipRemovedMNs = DeploymentActiveAfter(util_params.m_base_index, util_params.m_chainman.GetConsensus(), Consensus::DEPLOYMENT_V19) || (util_params.m_chainman.GetParams().NetworkIDString() == CBaseChainParams::TESTNET);
356355

357356
for (const size_t idx : irange::range(nQuorums)) {
358357
for (auto* prev_cycle : previousQuarters.GetCycles()) {
@@ -391,7 +390,7 @@ std::vector<QuorumMembers> BuildNewQuorumQuarterMembers(
391390
}
392391

393392
if (LogAcceptDebug(BCLog::LLMQ)) {
394-
LogPrint(BCLog::LLMQ, "%s h[%d] sortedCombinedMns[%s]\n", __func__, pCycleQuorumBaseBlockIndex->nHeight, ToString(sortedCombinedMnsList));
393+
LogPrint(BCLog::LLMQ, "%s h[%d] sortedCombinedMns[%s]\n", __func__, util_params.m_base_index->nHeight, ToString(sortedCombinedMnsList));
395394
}
396395

397396
std::vector<int> skipList;
@@ -436,11 +435,9 @@ std::vector<QuorumMembers> BuildNewQuorumQuarterMembers(
436435
}
437436
}
438437

439-
llmq::CQuorumSnapshot quorumSnapshot = {};
440-
441-
BuildQuorumSnapshot(llmqParams, allMns, MnsUsedAtH, sortedCombinedMnsList, quorumSnapshot, pCycleQuorumBaseBlockIndex->nHeight, skipList, pCycleQuorumBaseBlockIndex);
442-
443-
qsnapman.StoreSnapshotForBlock(llmqParams.type, pCycleQuorumBaseBlockIndex, quorumSnapshot);
438+
llmq::CQuorumSnapshot quorumSnapshot{};
439+
BuildQuorumSnapshot(llmqParams, util_params.m_chainman.GetConsensus(), allMns, MnsUsedAtH, sortedCombinedMnsList, quorumSnapshot, skipList, util_params.m_base_index);
440+
util_params.m_qsnapman.StoreSnapshotForBlock(llmqParams.type, util_params.m_base_index, quorumSnapshot);
444441

445442
return quarterQuorumMembers;
446443
}
@@ -470,11 +467,11 @@ std::vector<QuorumMembers> ComputeQuorumMembersByQuarterRotation(const Consensus
470467
// assert(false);
471468
break;
472469
}
473-
prev_cycles[idx]->m_members = GetQuorumQuarterMembersBySnapshot(llmqParams, util_params.m_dmnman, prev_cycles[idx]->m_cycle_index,
474-
prev_cycles[idx]->m_snap, util_params.m_base_index->nHeight);
470+
prev_cycles[idx]->m_members = GetQuorumQuarterMembersBySnapshot(llmqParams, util_params.m_dmnman, util_params.m_chainman.GetConsensus(),
471+
prev_cycles[idx]->m_cycle_index, prev_cycles[idx]->m_snap, util_params.m_base_index->nHeight);
475472
}
476473

477-
auto newQuarterMembers = BuildNewQuorumQuarterMembers(llmqParams, util_params.m_qsnapman, allMns, util_params.m_base_index, previousQuarters);
474+
auto newQuarterMembers = BuildNewQuorumQuarterMembers(llmqParams, util_params, allMns, previousQuarters);
478475
// TODO: Check if it is triggered from outside (P2P, block validation) and maybe throw an exception
479476
// assert (!newQuarterMembers.empty());
480477

@@ -562,7 +559,7 @@ QuorumMembers GetAllQuorumMembers(Consensus::LLMQType llmqType, const UtilParame
562559
{
563560
LOCK(cs_members);
564561
if (mapQuorumMembers.empty()) {
565-
InitQuorumsCache(mapQuorumMembers);
562+
InitQuorumsCache(mapQuorumMembers, util_params.m_chainman.GetConsensus());
566563
}
567564
if (reset_cache) {
568565
mapQuorumMembers[llmqType].clear();
@@ -571,13 +568,13 @@ QuorumMembers GetAllQuorumMembers(Consensus::LLMQType llmqType, const UtilParame
571568
}
572569
}
573570

574-
const auto& llmq_params_opt = Params().GetLLMQ(llmqType);
571+
const auto& llmq_params_opt = util_params.m_chainman.GetParams().GetLLMQ(llmqType);
575572
assert(llmq_params_opt.has_value());
576573
const auto& llmq_params = llmq_params_opt.value();
577574

578575
if (IsQuorumRotationEnabled(llmq_params, util_params.m_base_index)) {
579576
if (LOCK(cs_indexed_members); mapIndexedQuorumMembers.empty()) {
580-
InitQuorumsCache(mapIndexedQuorumMembers);
577+
InitQuorumsCache(mapIndexedQuorumMembers, util_params.m_chainman.GetConsensus());
581578
}
582579
/*
583580
* Quorums created with rotation are now created in a different way. All signingActiveQuorumCount are created during the period of dkgInterval.
@@ -617,11 +614,11 @@ QuorumMembers GetAllQuorumMembers(Consensus::LLMQType llmqType, const UtilParame
617614
std::move(q[i]));
618615
}
619616
} else {
620-
const CBlockIndex* pWorkBlockIndex = DeploymentActiveAfter(util_params.m_base_index, Params().GetConsensus(), Consensus::DEPLOYMENT_V20)
617+
const CBlockIndex* pWorkBlockIndex = DeploymentActiveAfter(util_params.m_base_index, util_params.m_chainman.GetConsensus(), Consensus::DEPLOYMENT_V20)
621618
? util_params.m_base_index->GetAncestor(util_params.m_base_index->nHeight - WORK_DIFF_DEPTH)
622619
: util_params.m_base_index.get();
623620
CDeterministicMNList mn_list = util_params.m_dmnman.GetListForBlock(pWorkBlockIndex);
624-
quorumMembers = ComputeQuorumMembers(llmqType, mn_list, util_params.m_base_index);
621+
quorumMembers = ComputeQuorumMembers(llmqType, util_params.m_chainman.GetParams(), mn_list, util_params.m_base_index);
625622
}
626623

627624
LOCK(cs_members);

src/llmq/utils.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
class CBlockIndex;
2323
class CConnman;
24-
class CDeterministicMN;
2524
class CDeterministicMNList;
2625
class CDeterministicMNManager;
2726
class ChainstateManager;
@@ -83,9 +82,9 @@ void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, CConnman
8382
const CDeterministicMNList& tip_mn_list, const uint256& myProTxHash);
8483

8584
template <typename CacheType>
86-
inline void InitQuorumsCache(CacheType& cache, bool limit_by_connections = true)
85+
inline void InitQuorumsCache(CacheType& cache, const Consensus::Params& consensus_params, bool limit_by_connections = true)
8786
{
88-
for (const auto& llmq : Params().GetConsensus().llmqs) {
87+
for (const auto& llmq : consensus_params.llmqs) {
8988
cache.emplace(std::piecewise_construct, std::forward_as_tuple(llmq.type),
9089
std::forward_as_tuple(limit_by_connections ? llmq.keepOldConnections : llmq.keepOldKeys));
9190
}

0 commit comments

Comments
 (0)