Skip to content

Commit 7fd5745

Browse files
committed
refactor: migrate remaining DeploymentActive{At,After} use
1 parent 86ff8f7 commit 7fd5745

File tree

12 files changed

+56
-52
lines changed

12 files changed

+56
-52
lines changed

src/evo/cbtx.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,20 @@ std::string CCbTx::ToString() const
219219
creditPoolBalance / COIN, creditPoolBalance % COIN);
220220
}
221221

222-
std::optional<std::pair<CBLSSignature, uint32_t>> GetNonNullCoinbaseChainlock(const CBlockIndex* pindex)
222+
std::optional<std::pair<CBLSSignature, uint32_t>> GetNonNullCoinbaseChainlock(const ChainstateManager& chainman,
223+
const CBlockIndex* pindex)
223224
{
224225
if (pindex == nullptr) {
225226
return std::nullopt;
226227
}
227228

228229
// There's no CL in CbTx before v20 activation
229-
if (!DeploymentActiveAt(*pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20)) {
230+
if (!DeploymentActiveAt(*pindex, chainman, Consensus::DEPLOYMENT_V20)) {
230231
return std::nullopt;
231232
}
232233

233234
CBlock block;
234-
if (!ReadBlockFromDisk(block, pindex, Params().GetConsensus())) {
235+
if (!ReadBlockFromDisk(block, pindex, chainman.GetConsensus())) {
235236
return std::nullopt;
236237
}
237238

src/evo/cbtx.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ bool CalcCbTxMerkleRootQuorums(const ChainstateManager& chainman, const llmq::CQ
7676
const CBlock& block, const CBlockIndex* pindexPrev, uint256& merkleRootRet,
7777
BlockValidationState& state);
7878

79-
std::optional<std::pair<CBLSSignature, uint32_t>> GetNonNullCoinbaseChainlock(const CBlockIndex* pindex);
79+
std::optional<std::pair<CBLSSignature, uint32_t>> GetNonNullCoinbaseChainlock(const ChainstateManager& chainman,
80+
const CBlockIndex* pindex);
8081

8182
#endif // BITCOIN_EVO_CBTX_H

src/evo/mnhftx.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ CMNHFManager::~CMNHFManager()
6060

6161
CMNHFManager::Signals CMNHFManager::GetSignalsStage(const CBlockIndex* const pindexPrev)
6262
{
63-
if (!DeploymentActiveAfter(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_V20)) return {};
63+
if (!DeploymentActiveAfter(pindexPrev, m_chainman, Consensus::DEPLOYMENT_V20)) return {};
6464

65+
if (pindexPrev == nullptr) return {};
6566
Signals signals_tmp = GetForBlock(pindexPrev);
6667

67-
if (pindexPrev == nullptr) return {};
6868
const int height = pindexPrev->nHeight + 1;
6969

7070
Signals signals_ret;
@@ -330,7 +330,7 @@ std::optional<CMNHFManager::Signals> CMNHFManager::GetFromCache(const CBlockInde
330330
}
331331
{
332332
LOCK(cs_cache);
333-
if (!DeploymentActiveAt(*pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20)) {
333+
if (!DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_V20)) {
334334
mnhfCache.insert(blockHash, signals);
335335
return signals;
336336
}
@@ -340,7 +340,7 @@ std::optional<CMNHFManager::Signals> CMNHFManager::GetFromCache(const CBlockInde
340340
mnhfCache.insert(blockHash, signals);
341341
return signals;
342342
}
343-
if (!DeploymentActiveAt(*pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_MN_RR)) {
343+
if (!DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_MN_RR)) {
344344
// before mn_rr activation we are safe
345345
if (m_evoDb.Read(std::make_pair(DB_SIGNALS, blockHash), signals)) {
346346
LOCK(cs_cache);
@@ -359,7 +359,7 @@ void CMNHFManager::AddToCache(const Signals& signals, const CBlockIndex* const p
359359
LOCK(cs_cache);
360360
mnhfCache.insert(blockHash, signals);
361361
}
362-
if (!DeploymentActiveAt(*pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20)) return;
362+
if (!DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_V20)) return;
363363

364364
m_evoDb.Write(std::make_pair(DB_SIGNALS_v2, blockHash), signals);
365365
}

src/evo/smldiff.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
using node::ReadBlockFromDisk;
2424

2525
// Forward declaration
26-
std::optional<std::pair<CBLSSignature, uint32_t>> GetNonNullCoinbaseChainlock(const CBlockIndex* pindex);
26+
std::optional<std::pair<CBLSSignature, uint32_t>> GetNonNullCoinbaseChainlock(const ChainstateManager& chainman,
27+
const CBlockIndex* pindex);
2728

2829
CSimplifiedMNListDiff::CSimplifiedMNListDiff() = default;
2930

@@ -67,7 +68,8 @@ bool CSimplifiedMNListDiff::BuildQuorumsDiff(const CBlockIndex* baseBlockIndex,
6768
return true;
6869
}
6970

70-
bool CSimplifiedMNListDiff::BuildQuorumChainlockInfo(const llmq::CQuorumManager& qman, const CBlockIndex* blockIndex)
71+
bool CSimplifiedMNListDiff::BuildQuorumChainlockInfo(const ChainstateManager& chainman,
72+
const llmq::CQuorumManager& qman, const CBlockIndex* blockIndex)
7173
{
7274
// Group quorums (indexes corresponding to entries of newQuorums) per CBlockIndex containing the expected CL
7375
// signature in CbTx. We want to avoid to load CbTx now, as more than one quorum will target the same block: hence
@@ -96,7 +98,7 @@ bool CSimplifiedMNListDiff::BuildQuorumChainlockInfo(const llmq::CQuorumManager&
9698
for (auto it = workBaseBlockIndexMap.begin(); it != workBaseBlockIndexMap.end();) {
9799
// Process each key (CBlockIndex containing the expected CL signature in CbTx) of the std::multimap once
98100
const CBlockIndex* pWorkBaseBlockIndex = it->first;
99-
const auto cbcl = GetNonNullCoinbaseChainlock(pWorkBaseBlockIndex);
101+
const auto cbcl = GetNonNullCoinbaseChainlock(chainman, pWorkBaseBlockIndex);
100102
CBLSSignature sig;
101103
if (cbcl.has_value()) {
102104
sig = cbcl.value().first;
@@ -196,8 +198,8 @@ bool BuildSimplifiedMNListDiff(CDeterministicMNManager& dmnman, const Chainstate
196198
return false;
197199
}
198200

199-
if (DeploymentActiveAfter(blockIndex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20)) {
200-
if (!mnListDiffRet.BuildQuorumChainlockInfo(qman, blockIndex)) {
201+
if (DeploymentActiveAfter(blockIndex, chainman, Consensus::DEPLOYMENT_V20)) {
202+
if (!mnListDiffRet.BuildQuorumChainlockInfo(chainman, qman, blockIndex)) {
201203
errorRet = strprintf("failed to build quorum chainlock info");
202204
return false;
203205
}

src/evo/smldiff.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ class CSimplifiedMNListDiff
8484

8585
bool BuildQuorumsDiff(const CBlockIndex* baseBlockIndex, const CBlockIndex* blockIndex,
8686
const llmq::CQuorumBlockProcessor& quorum_block_processor);
87-
bool BuildQuorumChainlockInfo(const llmq::CQuorumManager& qman, const CBlockIndex* blockIndex);
87+
bool BuildQuorumChainlockInfo(const ChainstateManager& chainman, const llmq::CQuorumManager& qman,
88+
const CBlockIndex* blockIndex);
8889

8990
[[nodiscard]] static RPCResult GetJsonHelp(const std::string& key, bool optional);
9091
[[nodiscard]] UniValue ToJson(bool extended = false) const;

src/evo/specialtxman.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
#include <llmq/quorums.h>
2727
#include <llmq/utils.h>
2828

29-
static bool CheckCbTxBestChainlock(const CCbTx& cbTx, const CBlockIndex* pindex,
30-
const llmq::CChainLocksHandler& chainlock_handler, BlockValidationState& state)
29+
static bool CheckCbTxBestChainlock(const ChainstateManager& chainman, const llmq::CChainLocksHandler& clhandler,
30+
const CCbTx& cbTx, const CBlockIndex* pindex, BlockValidationState& state)
3131
{
3232
if (cbTx.nVersion < CCbTx::Version::CLSIG_AND_BALANCE) {
3333
return true;
@@ -37,7 +37,7 @@ static bool CheckCbTxBestChainlock(const CCbTx& cbTx, const CBlockIndex* pindex,
3737
static const CBlockIndex* cached_pindex GUARDED_BY(cached_mutex){nullptr};
3838
static std::optional<std::pair<CBLSSignature, uint32_t>> cached_chainlock GUARDED_BY(cached_mutex){std::nullopt};
3939

40-
auto best_clsig = chainlock_handler.GetBestChainLock();
40+
auto best_clsig = clhandler.GetBestChainLock();
4141
if (best_clsig.getHeight() == pindex->nHeight - 1 && cbTx.bestCLHeightDiff == 0 &&
4242
cbTx.bestCLSignature == best_clsig.getSig()) {
4343
// matches our best clsig which still hold values for the previous block
@@ -52,7 +52,7 @@ static bool CheckCbTxBestChainlock(const CCbTx& cbTx, const CBlockIndex* pindex,
5252
prevBlockCoinbaseChainlock = cached_chainlock;
5353
}
5454
if (!prevBlockCoinbaseChainlock.has_value()) {
55-
prevBlockCoinbaseChainlock = GetNonNullCoinbaseChainlock(pindex->pprev);
55+
prevBlockCoinbaseChainlock = GetNonNullCoinbaseChainlock(chainman, pindex->pprev);
5656
}
5757
// If std::optional prevBlockCoinbaseChainlock is empty, then up to the previous block, coinbase Chainlock is null.
5858
if (prevBlockCoinbaseChainlock.has_value()) {
@@ -77,9 +77,8 @@ static bool CheckCbTxBestChainlock(const CCbTx& cbTx, const CBlockIndex* pindex,
7777
return true;
7878
}
7979
uint256 curBlockCoinbaseCLBlockHash = pindex->GetAncestor(curBlockCoinbaseCLHeight)->GetBlockHash();
80-
if (chainlock_handler.VerifyChainLock(
81-
chainlock::ChainLockSig(curBlockCoinbaseCLHeight, curBlockCoinbaseCLBlockHash, cbTx.bestCLSignature)) !=
82-
llmq::VerifyRecSigStatus::Valid) {
80+
if (clhandler.VerifyChainLock(chainlock::ChainLockSig(curBlockCoinbaseCLHeight, curBlockCoinbaseCLBlockHash,
81+
cbTx.bestCLSignature)) != llmq::VerifyRecSigStatus::Valid) {
8382
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-invalid-clsig");
8483
}
8584
LOCK(cached_mutex);
@@ -104,8 +103,7 @@ static bool CheckSpecialTxInner(CDeterministicMNManager& dmnman, llmq::CQuorumSn
104103
if (!tx.HasExtraPayloadField())
105104
return true;
106105

107-
const auto& consensusParams = Params().GetConsensus();
108-
if (!DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_DIP0003)) {
106+
if (!DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_DIP0003)) {
109107
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-tx-type");
110108
}
111109

@@ -205,8 +203,8 @@ bool CSpecialTxProcessor::BuildNewListFromBlock(const CBlock& block, gsl::not_nu
205203

206204
newList.DecreaseScores();
207205

208-
const bool isMNRewardReallocation{DeploymentActiveAfter(pindexPrev, m_consensus_params, Consensus::DEPLOYMENT_MN_RR)};
209-
const bool is_v24_deployed{DeploymentActiveAfter(pindexPrev, m_consensus_params, Consensus::DEPLOYMENT_V24)};
206+
const bool isMNRewardReallocation{DeploymentActiveAfter(pindexPrev, m_chainman, Consensus::DEPLOYMENT_MN_RR)};
207+
const bool is_v24_deployed{DeploymentActiveAfter(pindexPrev, m_chainman, Consensus::DEPLOYMENT_V24)};
210208

211209
// we skip the coinbase
212210
for (int i = 1; i < (int)block.vtx.size(); i++) {
@@ -529,7 +527,7 @@ bool CSpecialTxProcessor::ProcessSpecialTxsInBlock(const CBlock& block, const CB
529527
}
530528
if (fCheckCbTxMerkleRoots) {
531529
// To ensure that opt_cbTx is not missing when it's supposed to be
532-
if (DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_DIP0003) && !opt_cbTx.has_value()) {
530+
if (DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_DIP0003) && !opt_cbTx.has_value()) {
533531
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-version");
534532
}
535533
}
@@ -540,7 +538,7 @@ bool CSpecialTxProcessor::ProcessSpecialTxsInBlock(const CBlock& block, const CB
540538
nTimePayload * 0.000001);
541539

542540
CRangesSet indexes;
543-
if (DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_V20)) {
541+
if (DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_V20)) {
544542
CCreditPool creditPool{m_cpoolman.GetCreditPool(pindex->pprev)};
545543
LogPrint(BCLog::CREDITPOOL, "CSpecialTxProcessor::%s -- CCreditPool is %s\n", __func__, creditPool.ToString());
546544
indexes = std::move(creditPool.indexes);
@@ -589,7 +587,7 @@ bool CSpecialTxProcessor::ProcessSpecialTxsInBlock(const CBlock& block, const CB
589587
nTimeQuorum * 0.000001);
590588

591589
CDeterministicMNList mn_list;
592-
if (DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_DIP0003)) {
590+
if (DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_DIP0003)) {
593591
if (!BuildNewListFromBlock(block, pindex->pprev, view, true, state, mn_list)) {
594592
// pass the state returned by the function above
595593
return false;
@@ -640,7 +638,7 @@ bool CSpecialTxProcessor::ProcessSpecialTxsInBlock(const CBlock& block, const CB
640638
LogPrint(BCLog::BENCHMARK, " - CalcCbTxMerkleRootQuorums: %.2fms [%.2fs]\n",
641639
0.001 * (nTime6_2 - nTime6_1), nTimeMerkleQuorums * 0.000001);
642640

643-
if (!CheckCbTxBestChainlock(*opt_cbTx, pindex, m_clhandler, state)) {
641+
if (!CheckCbTxBestChainlock(m_chainman, m_clhandler, *opt_cbTx, pindex, state)) {
644642
// pass the state returned by the function above
645643
return false;
646644
}
@@ -663,7 +661,7 @@ bool CSpecialTxProcessor::ProcessSpecialTxsInBlock(const CBlock& block, const CB
663661
LogPrint(BCLog::BENCHMARK, " - m_mnhfman.ProcessBlock: %.2fms [%.2fs]\n", 0.001 * (nTime8 - nTime7),
664662
nTimeMnehf * 0.000001);
665663

666-
if (DeploymentActiveAfter(pindex, m_consensus_params, Consensus::DEPLOYMENT_V19) && bls::bls_legacy_scheme.load()) {
664+
if (DeploymentActiveAfter(pindex, m_chainman, Consensus::DEPLOYMENT_V19) && bls::bls_legacy_scheme.load()) {
667665
// NOTE: The block next to the activation is the one that is using new rules.
668666
// V19 activated just activated, so we must switch to the new rules here.
669667
bls::bls_legacy_scheme.store(false);
@@ -684,7 +682,7 @@ bool CSpecialTxProcessor::UndoSpecialTxsInBlock(const CBlock& block, const CBloc
684682
auto bls_legacy_scheme = bls::bls_legacy_scheme.load();
685683

686684
try {
687-
if (!DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_V19) && !bls_legacy_scheme) {
685+
if (!DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_V19) && !bls_legacy_scheme) {
688686
// NOTE: The block next to the activation is the one that is using new rules.
689687
// Removing the activation block here, so we must switch back to the old rules.
690688
bls::bls_legacy_scheme.store(true);
@@ -716,8 +714,8 @@ bool CSpecialTxProcessor::CheckCreditPoolDiffForBlock(const CBlock& block, const
716714
{
717715
AssertLockHeld(::cs_main);
718716

719-
if (!DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_DIP0008)) return true;
720-
if (!DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_V20)) return true;
717+
if (!DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_DIP0008)) return true;
718+
if (!DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_V20)) return true;
721719

722720
try {
723721
const CAmount blockSubsidy = GetBlockSubsidy(pindex, m_chainman);

src/llmq/blockprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, gsl::not_null<cons
177177

178178
const auto blockHash = pindex->GetBlockHash();
179179

180-
if (!DeploymentActiveAt(*pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0003)) {
180+
if (!DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_DIP0003)) {
181181
m_evoDb.Write(DB_BEST_BLOCK_UPGRADE, blockHash);
182182
return true;
183183
}

src/llmq/utils.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class CBLSSignature;
2929
/**
3030
* Forward declarations
3131
*/
32-
std::optional<std::pair<CBLSSignature, uint32_t>> GetNonNullCoinbaseChainlock(const CBlockIndex* pindex);
32+
std::optional<std::pair<CBLSSignature, uint32_t>> GetNonNullCoinbaseChainlock(const ChainstateManager& chainman,
33+
const CBlockIndex* pindex);
3334

3435
static bool IsV19Active(const ChainstateManager& chainman, gsl::not_null<const CBlockIndex*> pindexPrev)
3536
{
@@ -87,7 +88,7 @@ static uint256 GetHashModifier(const Consensus::LLMQParams& llmqParams, const Ch
8788

8889
if (IsV20Active(chainman, pWorkBlockIndex)) {
8990
// v20 is active: calculate modifier using the new way.
90-
auto cbcl = GetNonNullCoinbaseChainlock(pWorkBlockIndex);
91+
auto cbcl = GetNonNullCoinbaseChainlock(chainman, pWorkBlockIndex);
9192
if (cbcl.has_value()) {
9293
// We have a non-null CL signature: calculate modifier using this CL signature
9394
auto& [bestCLSignature, bestCLHeightDiff] = cbcl.value();

src/masternode/payments.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ CAmount PlatformShare(const CAmount reward)
3737

3838
const int nBlockHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1;
3939

40-
bool fV20Active = DeploymentActiveAfter(pindexPrev, m_consensus_params, Consensus::DEPLOYMENT_V20);
40+
bool fV20Active = DeploymentActiveAfter(pindexPrev, m_chainman, Consensus::DEPLOYMENT_V20);
4141
CAmount masternodeReward = GetMasternodePayment(nBlockHeight, blockSubsidy + feeReward, fV20Active);
4242

4343
// Credit Pool doesn't exist before V20. If any part of reward will re-allocated to credit pool before v20
4444
// activation these fund will be just permanently lost. Applicable for devnets, regtest, testnet
45-
if (fV20Active && DeploymentActiveAfter(pindexPrev, m_consensus_params, Consensus::DEPLOYMENT_MN_RR)) {
45+
if (fV20Active && DeploymentActiveAfter(pindexPrev, m_chainman, Consensus::DEPLOYMENT_MN_RR)) {
4646
CAmount masternodeSubsidyReward = GetMasternodePayment(nBlockHeight, blockSubsidy, fV20Active);
4747
const CAmount platformReward = PlatformShare(masternodeSubsidyReward);
4848
masternodeReward -= platformReward;

src/node/chainstate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
281281
if (tip && tip->nTime > get_unix_time_seconds() + MAX_FUTURE_BLOCK_TIME) {
282282
return ChainstateLoadVerifyError::ERROR_BLOCK_FROM_FUTURE;
283283
}
284-
const bool v19active{DeploymentActiveAfter(tip, consensus_params, Consensus::DEPLOYMENT_V19)};
284+
const bool v19active{DeploymentActiveAfter(tip, chainman, Consensus::DEPLOYMENT_V19)};
285285
if (v19active) {
286286
bls::bls_legacy_scheme.store(false);
287287
if (notify_bls_state) notify_bls_state(bls::bls_legacy_scheme.load());

0 commit comments

Comments
 (0)