From bacaa805ea33829ded4f380fe41bd6936d9d7cd3 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Mon, 4 Dec 2023 16:52:09 +0700 Subject: [PATCH] fix: use proper pindex/pindex->pprev in credit pool code during v20/mn_rr activations --- src/evo/creditpool.cpp | 12 ++++++------ src/evo/creditpool.h | 4 ++-- src/evo/specialtxman.cpp | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/evo/creditpool.cpp b/src/evo/creditpool.cpp index 517adf5f9b..7731b1e418 100644 --- a/src/evo/creditpool.cpp +++ b/src/evo/creditpool.cpp @@ -218,16 +218,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 (llmq::utils::IsMNRewardReallocationActive(pindexPrev)) { // 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 +274,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 0b3b5f31b6..eb122e4ebe 100644 --- a/src/evo/creditpool.h +++ b/src/evo/creditpool.h @@ -70,10 +70,10 @@ private: 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); diff --git a/src/evo/specialtxman.cpp b/src/evo/specialtxman.cpp index 0108cc131b..ca93542204 100644 --- a/src/evo/specialtxman.cpp +++ b/src/evo/specialtxman.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -276,7 +277,7 @@ bool CheckCreditPoolDiffForBlock(const CBlock& block, const CBlockIndex* pindex, const CAmount blockSubsidy, BlockValidationState& state) { try { - if (!llmq::utils::IsV20Active(pindex)) return true; + if (!DeploymentActiveAt(*pindex, consensusParams, Consensus::DEPLOYMENT_V20)) return true; auto creditPoolDiff = GetCreditPoolDiffForBlock(block, pindex->pprev, consensusParams, blockSubsidy, state); if (!creditPoolDiff.has_value()) return false;