From 68204d744cc19cbb056f95cf78e56a0e94c3a943 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Mon, 24 Apr 2023 15:43:24 +0700 Subject: [PATCH] feat: changed activation way of MN reward location reallocation, added functional tests --- src/chainparams.cpp | 31 +++++++++++++++++++ src/consensus/params.h | 1 + src/evo/creditpool.cpp | 16 +++------- src/evo/creditpool.h | 5 +-- src/evo/specialtxman.cpp | 2 -- src/llmq/utils.cpp | 8 +++++ src/llmq/utils.h | 1 + src/masternode/payments.cpp | 9 ++++-- src/miner.cpp | 4 +-- src/spork.h | 4 +-- src/test/evo_deterministicmns_tests.cpp | 5 --- src/versionbitsinfo.cpp | 7 ++++- test/functional/feature_asset_locks.py | 23 ++++++++++++-- .../feature_llmq_is_cl_conflicts.py | 3 -- .../test_framework/test_framework.py | 8 +++-- 15 files changed, 88 insertions(+), 39 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 7100d53d0b05bc..105a5c397dd9da 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -253,6 +253,13 @@ class CMainParams : public CChainParams { consensus.vDeployments[Consensus::DEPLOYMENT_V20].nThresholdMin = 2420; // 60% of 4032 consensus.vDeployments[Consensus::DEPLOYMENT_V20].nFalloffCoeff = 5; // this corresponds to 10 periods + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].bit = 10; + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nStartTime = 19999999999; // TODO: To be determined later + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nTimeout = 999999999999ULL; + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nWindowSize = 4032; + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 3226; // 80% of 4032 + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 2420; // 60% of 4032 + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods // The best chain should have at least this much work. consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000082094584a23266cbb5f8"); // 1850400 @@ -502,6 +509,14 @@ class CTestNetParams : public CChainParams { consensus.vDeployments[Consensus::DEPLOYMENT_V20].nThresholdMin = 60; // 60% of 100 consensus.vDeployments[Consensus::DEPLOYMENT_V20].nFalloffCoeff = 5; // this corresponds to 10 periods + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].bit = 10; + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nStartTime = 19999999999; // TODO: To be determined later + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nTimeout = 999999999999ULL; + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nWindowSize = 100; + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 80; // 80% of 100 + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 60; // 60% of 100 + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods + // The best chain should have at least this much work. consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000000002d68cb6c090031f"); // 864000 @@ -723,6 +738,14 @@ class CDevNetParams : public CChainParams { consensus.vDeployments[Consensus::DEPLOYMENT_V20].nThresholdMin = 60; // 60% of 100 consensus.vDeployments[Consensus::DEPLOYMENT_V20].nFalloffCoeff = 5; // this corresponds to 10 periods + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].bit = 10; + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nStartTime = 1661990400; // Sep 1st, 2022 + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nTimeout = 999999999999ULL; + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nWindowSize = 120; + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 80; // 80% of 100 + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 60; // 60% of 100 + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods + // The best chain should have at least this much work. consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000000000000000000000000"); @@ -995,6 +1018,14 @@ class CRegTestParams : public CChainParams { consensus.vDeployments[Consensus::DEPLOYMENT_V20].nThresholdMin = 180; // 60% of 300 consensus.vDeployments[Consensus::DEPLOYMENT_V20].nFalloffCoeff = 5; // this corresponds to 10 periods + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].bit = 10; + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nStartTime = 0; + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nTimeout = 999999999999ULL; + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nWindowSize = 1030; + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 800; // 80% of 1000 + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 600; // 60% of 1000 + consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods + // The best chain should have at least this much work. consensus.nMinimumChainWork = uint256S("0x00"); diff --git a/src/consensus/params.h b/src/consensus/params.h index 92b285b91e486a..fc901b5ea34c15 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -25,6 +25,7 @@ enum DeploymentPos { DEPLOYMENT_DIP0024, // Deployment of DIP0024 (Quorum Rotation) and decreased governance proposal fee DEPLOYMENT_V19, // Deployment of Basic BLS, AssetLocks DEPLOYMENT_V20, // Deployment of EHF, LLMQ Randomness Beacon + DEPLOYMENT_MN_RR, // Deployment of Masternode Reward Location Reallocation // NOTE: Also add new deployments to VersionBitsDeploymentInfo in versionbits.cpp MAX_VERSION_BITS_DEPLOYMENTS }; diff --git a/src/evo/creditpool.cpp b/src/evo/creditpool.cpp index 3536a9c62bb9dc..46047d0ed7ff24 100644 --- a/src/evo/creditpool.cpp +++ b/src/evo/creditpool.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include @@ -246,7 +245,8 @@ CCreditPoolManager::CCreditPoolManager(CEvoDB& _evoDb) CCreditPoolDiff::CCreditPoolDiff(CCreditPool starter, const CBlockIndex *pindex, const Consensus::Params& consensusParams) : pool(std::move(starter)), - pindex(pindex) + pindex(pindex), + params(consensusParams) { assert(pindex); } @@ -267,13 +267,13 @@ bool CCreditPoolDiff::setTarget(const CTransaction& tx, TxValidationState& state targetLocked = cbTx.assetLockedAmount; - if (isIgnoringMNRewardReallocation(*sporkManager)) return true; + if (!llmq::utils::IsMNRewardReallocationActive(pindex)) return true; CAmount blockReward = 0; for (const CTxOut& txout : tx.vout) { blockReward += txout.nValue; } - masternodeReward = GetMasternodePayment(cbTx.nHeight, blockReward, Params().GetConsensus().BRRHeight); + masternodeReward = GetMasternodePayment(cbTx.nHeight, blockReward, params.BRRHeight); LogPrintf("CreditPool: set target to %lld with MN reward %lld\n", *targetLocked, masternodeReward); return true; @@ -348,11 +348,3 @@ bool CCreditPoolDiff::processTransaction(const CTransaction& tx, TxValidationSta return state.Invalid(TxValidationResult::TX_CONSENSUS, "failed-procassetlocksinblock"); } } - -bool isIgnoringMNRewardReallocation(const CSporkManager& spork_manager) { - if (Params().NetworkIDString() != CBaseChainParams::REGTEST) return false; - - bool ret = spork_manager.IsSporkActive(SPORK_24_IGNORE_MN_REWARD_REALLOCED); - LogPrintf("%s: spork IGNORE_MN_REWARD_REALLOCED value: %d\n", __func__, ret); - return ret; -} diff --git a/src/evo/creditpool.h b/src/evo/creditpool.h index e81e8937f9fef6..38df324544ee4d 100644 --- a/src/evo/creditpool.h +++ b/src/evo/creditpool.h @@ -21,7 +21,6 @@ class CBlockIndex; class TxValidationState; -class CSporkManager; namespace Consensus { @@ -110,6 +109,7 @@ class CCreditPoolDiff { std::optional targetLocked; const CBlockIndex *pindex{nullptr}; + const Consensus::Params& params; public: explicit CCreditPoolDiff(CCreditPool starter, const CBlockIndex *pindex, const Consensus::Params& consensusParams); @@ -122,7 +122,6 @@ class CCreditPoolDiff { /** * This function should be called by miner for initalization of MasterNode reward - * */ void addRewardRealloced(const CAmount reward); @@ -178,8 +177,6 @@ class CCreditPoolManager CCreditPool constructCreditPool(const CBlockIndex* block_index, CCreditPool prev, const Consensus::Params& consensusParams); }; -bool isIgnoringMNRewardReallocation(const CSporkManager& spork_manager); - extern std::unique_ptr creditPoolManager; #endif diff --git a/src/evo/specialtxman.cpp b/src/evo/specialtxman.cpp index cd40eddb23a7a1..19bf7ce5faa6f5 100644 --- a/src/evo/specialtxman.cpp +++ b/src/evo/specialtxman.cpp @@ -17,10 +17,8 @@ #include #include #include -#include #include -#include bool CheckSpecialTx(const CTransaction& tx, const CBlockIndex* pindexPrev, const CCoinsViewCache& view, const CCreditPool& creditPool, bool check_sigs, TxValidationState& state) { AssertLockHeld(cs_main); diff --git a/src/llmq/utils.cpp b/src/llmq/utils.cpp index a94d4f4e93fb00..65b26df1d1d9a0 100644 --- a/src/llmq/utils.cpp +++ b/src/llmq/utils.cpp @@ -678,6 +678,14 @@ bool IsV20Active(const CBlockIndex* pindex) return VersionBitsState(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20, llmq_versionbitscache) == ThresholdState::ACTIVE; } +bool IsMNRewardReallocationActive(const CBlockIndex* pindex) +{ + if (!IsV20Active(pindex)) false; + + LOCK(cs_llmq_vbc); + return VersionBitsState(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_MN_RR, llmq_versionbitscache) == ThresholdState::ACTIVE; +} + bool IsInstantSendLLMQTypeShared() { if (Params().GetConsensus().llmqTypeInstantSend == Params().GetConsensus().llmqTypeChainLocks || diff --git a/src/llmq/utils.h b/src/llmq/utils.h index 46ee667a44910c..825ef9f22e3211 100644 --- a/src/llmq/utils.h +++ b/src/llmq/utils.h @@ -86,6 +86,7 @@ bool IsDIP0024Active(const CBlockIndex* pindex); bool IsV19Active(const CBlockIndex* pindex); const CBlockIndex* V19ActivationIndex(const CBlockIndex* pindex); bool IsV20Active(const CBlockIndex* pindex); +bool IsMNRewardReallocationActive(const CBlockIndex* pindex); /// Returns the state of `-llmq-data-recovery` bool QuorumDataRecoveryEnabled(); diff --git a/src/masternode/payments.cpp b/src/masternode/payments.cpp index dedb1385a1f04f..081ccc76cc6ac1 100644 --- a/src/masternode/payments.cpp +++ b/src/masternode/payments.cpp @@ -16,12 +16,12 @@ #include #include #include