diff --git a/src/deploymentstatus.h b/src/deploymentstatus.h index 84c5e54698c9..84ce46375ebf 100644 --- a/src/deploymentstatus.h +++ b/src/deploymentstatus.h @@ -52,4 +52,10 @@ inline bool DeploymentEnabled(const Consensus::Params& params, Consensus::Deploy return params.vDeployments[dep].nTimeout != 0; } +/** this function is convenient helper for DIP0003 because 'active' and 'enforced' are different statuses for DIP0003 */ +constexpr bool DeploymentDIP0003Enforced(const int nHeight, const Consensus::Params& params) +{ + return nHeight >= params.DIP0003EnforcementHeight; +} + #endif // BITCOIN_DEPLOYMENTSTATUS_H diff --git a/src/evo/cbtx.cpp b/src/evo/cbtx.cpp index 66ff72683ff9..8bfe14ab500a 100644 --- a/src/evo/cbtx.cpp +++ b/src/evo/cbtx.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include bool CheckCbTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state) @@ -42,12 +43,12 @@ bool CheckCbTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidati return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-cbtx-height"); } - bool fDIP0008Active = pindexPrev->nHeight >= Params().GetConsensus().DIP0008Height; + const bool fDIP0008Active{DeploymentActiveAt(*pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0008)}; if (fDIP0008Active && cbTx.nVersion < CCbTx::Version::MERKLE_ROOT_QUORUMS) { return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-cbtx-version"); } - bool isV20 = llmq::utils::IsV20Active(pindexPrev); + const bool isV20{DeploymentActiveAfter(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_V20)}; if ((isV20 && cbTx.nVersion < CCbTx::Version::CLSIG_AND_BALANCE) || (!isV20 && cbTx.nVersion >= CCbTx::Version::CLSIG_AND_BALANCE)) { return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-cbtx-version"); } diff --git a/src/evo/creditpool.cpp b/src/evo/creditpool.cpp index 517adf5f9b0e..d0fc39881356 100644 --- a/src/evo/creditpool.cpp +++ b/src/evo/creditpool.cpp @@ -9,8 +9,9 @@ #include #include +#include #include -#include +#include #include #include #include @@ -80,11 +81,11 @@ std::string CCreditPool::ToString() const locked, currentLimit); } -std::optional CCreditPoolManager::GetFromCache(const CBlockIndex* const block_index) +std::optional CCreditPoolManager::GetFromCache(const CBlockIndex& block_index) { - if (!llmq::utils::IsV20Active(block_index)) return CCreditPool{}; + if (!DeploymentActiveAt(block_index, Params().GetConsensus(), Consensus::DEPLOYMENT_V20)) return CCreditPool{}; - const uint256 block_hash = block_index->GetBlockHash(); + const uint256 block_hash = block_index.GetBlockHash(); CCreditPool pool; { LOCK(cache_mutex); @@ -92,7 +93,7 @@ std::optional CCreditPoolManager::GetFromCache(const CBlockIndex* c return pool; } } - if (block_index->nHeight % DISK_SNAPSHOT_PERIOD == 0) { + if (block_index.nHeight % DISK_SNAPSHOT_PERIOD == 0) { if (evoDb.Read(std::make_pair(DB_CREDITPOOL_SNAPSHOT, block_hash), pool)) { LOCK(cache_mutex); creditPoolCache.insert(block_hash, pool); @@ -202,10 +203,11 @@ CCreditPool CCreditPoolManager::GetCreditPool(const CBlockIndex* block_index, co std::stack to_calculate; std::optional poolTmp; - while (!(poolTmp = GetFromCache(block_index)).has_value()) { + while (block_index != nullptr && !(poolTmp = GetFromCache(*block_index)).has_value()) { to_calculate.push(block_index); block_index = block_index->pprev; } + if (block_index == nullptr) poolTmp = CCreditPool{}; while (!to_calculate.empty()) { poolTmp = ConstructCreditPool(to_calculate.top(), *poolTmp, consensusParams); to_calculate.pop(); @@ -218,16 +220,16 @@ CCreditPoolManager::CCreditPoolManager(CEvoDB& _evoDb) { } -CCreditPoolDiff::CCreditPoolDiff(CCreditPool starter, const CBlockIndex *pindex, const Consensus::Params& consensusParams, const CAmount blockSubsidy) : +CCreditPoolDiff::CCreditPoolDiff(CCreditPool starter, const CBlockIndex *pindexPrev, const Consensus::Params& consensusParams, const CAmount blockSubsidy) : pool(std::move(starter)), - pindex(pindex), + pindexPrev(pindexPrev), params(consensusParams) { - assert(pindex); + assert(pindexPrev); - if (llmq::utils::IsMNRewardReallocationActive(pindex)) { + if (DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_MN_RR)) { // We consider V20 active if mn_rr is active - platformReward = MasternodePayments::PlatformShare(GetMasternodePayment(pindex->nHeight, blockSubsidy, /*fV20Active=*/ true)); + platformReward = MasternodePayments::PlatformShare(GetMasternodePayment(pindexPrev->nHeight + 1, blockSubsidy, /*fV20Active=*/ true)); } } @@ -274,7 +276,7 @@ bool CCreditPoolDiff::ProcessLockUnlockTransaction(const CTransaction& tx, TxVal if (tx.nVersion != 3) return true; if (tx.nType != TRANSACTION_ASSET_LOCK && tx.nType != TRANSACTION_ASSET_UNLOCK) return true; - if (!CheckAssetLockUnlockTx(tx, pindex, pool.indexes, state)) { + if (!CheckAssetLockUnlockTx(tx, pindexPrev, pool.indexes, state)) { // pass the state returned by the function above return false; } diff --git a/src/evo/creditpool.h b/src/evo/creditpool.h index 0b3b5f31b6f2..1c6993e5c270 100644 --- a/src/evo/creditpool.h +++ b/src/evo/creditpool.h @@ -70,10 +70,10 @@ class CCreditPoolDiff { CAmount sessionUnlocked{0}; CAmount platformReward{0}; - const CBlockIndex *pindex{nullptr}; + const CBlockIndex *pindexPrev{nullptr}; const Consensus::Params& params; public: - explicit CCreditPoolDiff(CCreditPool starter, const CBlockIndex *pindex, + explicit CCreditPoolDiff(CCreditPool starter, const CBlockIndex *pindexPrev, const Consensus::Params& consensusParams, const CAmount blockSubsidy); @@ -128,7 +128,7 @@ class CCreditPoolManager CCreditPool GetCreditPool(const CBlockIndex* block, const Consensus::Params& consensusParams); private: - std::optional GetFromCache(const CBlockIndex* const block_index); + std::optional GetFromCache(const CBlockIndex& block_index); void AddToCache(const uint256& block_hash, int height, const CCreditPool& pool); CCreditPool ConstructCreditPool(const CBlockIndex* block_index, CCreditPool prev, const Consensus::Params& consensusParams); diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index 2a0bc7c9ef58..73d72b2be639 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include