diff --git a/src/dfi/consensus/masternodes.cpp b/src/dfi/consensus/masternodes.cpp index 0c08d1db70..2c1b16741d 100644 --- a/src/dfi/consensus/masternodes.cpp +++ b/src/dfi/consensus/masternodes.cpp @@ -42,13 +42,6 @@ Res CMasternodesConsensus::operator()(const CCreateMasterNodeMessage &obj) const } if (height >= static_cast(consensus.DF10EunosPayaHeight)) { - const auto attributes = mnview.GetAttributes(); - CDataStructureV0 unfreezeKey{AttributeTypes::Param, ParamIDs::Feature, DFIPKeys::UnfreezeMasternodes}; - const auto unfreezeHeight = attributes->GetValue(unfreezeKey, std::numeric_limits::max()); - if (static_cast(unfreezeHeight) < height && obj.timelock != 0) { - return Res::Err("Masternode timelock disabled"); - } - switch (obj.timelock) { case CMasternode::ZEROYEAR: case CMasternode::FIVEYEAR: diff --git a/src/dfi/errors.h b/src/dfi/errors.h index 6e3e33bf1a..b9465b420d 100644 --- a/src/dfi/errors.h +++ b/src/dfi/errors.h @@ -323,10 +323,6 @@ class DeFiErrors { static Res GovVarApplyBelowHeight() { return Res::Err("Cannot be set at or below current height"); } - static Res GovVarAfterFreezerActivation() { - return Res::Err("Cannot change masternode unfreeze height after activation"); - } - static Res GovVarApplyAutoNoToken(const uint32_t token) { return Res::Err("Auto lock. No loan token with id (%d)", token); } diff --git a/src/dfi/govvariables/attributes.cpp b/src/dfi/govvariables/attributes.cpp index 88992b7343..3522e9f4cf 100644 --- a/src/dfi/govvariables/attributes.cpp +++ b/src/dfi/govvariables/attributes.cpp @@ -287,7 +287,6 @@ const std::map> &ATTRIBUTES::allowedKeys {"transferdomain", DFIPKeys::TransferDomain}, {"liquidity_calc_sampling_period", DFIPKeys::LiquidityCalcSamplingPeriod}, {"average_liquidity_percentage", DFIPKeys::AverageLiquidityPercentage}, - {"unfreeze_masternodes", DFIPKeys::UnfreezeMasternodes}, {"governance", DFIPKeys::CommunityGovernance}, {"ascending_block_time", DFIPKeys::AscendingBlockTime}, {"govheight_min_blocks", DFIPKeys::GovHeightMinBlocks}, @@ -396,7 +395,6 @@ const std::map> &ATTRIBUTES::displayKeys {DFIPKeys::TransferDomain, "transferdomain"}, {DFIPKeys::LiquidityCalcSamplingPeriod, "liquidity_calc_sampling_period"}, {DFIPKeys::AverageLiquidityPercentage, "average_liquidity_percentage"}, - {DFIPKeys::UnfreezeMasternodes, "unfreeze_masternodes"}, {DFIPKeys::CommunityGovernance, "governance"}, {DFIPKeys::AscendingBlockTime, "ascending_block_time"}, {DFIPKeys::GovHeightMinBlocks, "govheight_min_blocks"}, @@ -831,7 +829,6 @@ const std::map( {DFIPKeys::TransferDomain, VerifyBool}, {DFIPKeys::LiquidityCalcSamplingPeriod, VerifyMoreThenZeroInt64}, {DFIPKeys::AverageLiquidityPercentage, VerifyPctInt64}, - {DFIPKeys::UnfreezeMasternodes, VerifyMoreThenZeroUInt64}, {DFIPKeys::CommunityGovernance, VerifyBool}, {DFIPKeys::AscendingBlockTime, VerifyBool}, {DFIPKeys::GovHeightMinBlocks, VerifyMoreThenZeroUInt64}, @@ -1014,7 +1011,7 @@ static Res CheckValidAttrV0Key(const uint8_t type, const uint32_t typeId, const typeKey != DFIPKeys::CFPPayout && typeKey != DFIPKeys::EmissionUnusedFund && typeKey != DFIPKeys::MintTokens && typeKey != DFIPKeys::EVMEnabled && typeKey != DFIPKeys::ICXEnabled && typeKey != DFIPKeys::TransferDomain && typeKey != DFIPKeys::CommunityGovernance && - typeKey != DFIPKeys::UnfreezeMasternodes && typeKey != DFIPKeys::AscendingBlockTime) { + typeKey != DFIPKeys::AscendingBlockTime) { return DeFiErrors::GovVarVariableUnsupportedFeatureType(typeKey); } } else if (typeId == ParamIDs::Foundation || typeId == ParamIDs::GovernanceParam) { @@ -1530,14 +1527,6 @@ Res ATTRIBUTES::Import(const UniValue &val) { return Res::Ok(); } else if (attrV0->type == AttributeTypes::Token && attrV0->key == TokenKeys::LoanMintingInterest) { interestTokens.insert(attrV0->typeId); - } else if (attrV0->type == AttributeTypes::Param && attrV0->typeId == ParamIDs::Feature && - attrV0->key == DFIPKeys::UnfreezeMasternodes) { - CDataStructureV0 unfreezeKey{ - AttributeTypes::Param, ParamIDs::Feature, DFIPKeys::UnfreezeMasternodes}; - if (CheckKey(unfreezeKey)) { - // Store current unfreeze height for validation later - unfreezeMasternodeHeight = GetValue(unfreezeKey, std::numeric_limits::max()); - } } if (attrV0->type == AttributeTypes::Param) { @@ -2111,20 +2100,6 @@ Res ATTRIBUTES::Validate(const CCustomCSView &view) const { if (view.GetLastHeight() < Params().GetConsensus().DF22MetachainHeight) { return Res::Err("Cannot be set before MetachainHeight"); } - } else if (attrV0->key == DFIPKeys::UnfreezeMasternodes) { - if (view.GetLastHeight() < Params().GetConsensus().DF24Height) { - return DeFiErrors::GovVarValidateDF24Height(); - } - if (unfreezeMasternodeHeight && *unfreezeMasternodeHeight < view.GetLastHeight()) { - return DeFiErrors::GovVarAfterFreezerActivation(); - } - const auto height = std::get_if(&value); - if (!height) { - return DeFiErrors::GovVarUnsupportedValue(); - } - if (*height <= view.GetLastHeight()) { - return DeFiErrors::GovVarApplyBelowHeight(); - } } else if (attrV0->key == DFIPKeys::CommunityGovernance || attrV0->key == DFIPKeys::AscendingBlockTime) { if (view.GetLastHeight() < Params().GetConsensus().DF24Height) { diff --git a/src/dfi/govvariables/attributes.h b/src/dfi/govvariables/attributes.h index 6892acf55f..3d8dea5ec4 100644 --- a/src/dfi/govvariables/attributes.h +++ b/src/dfi/govvariables/attributes.h @@ -128,7 +128,6 @@ enum DFIPKeys : uint8_t { TransferDomain = 'w', LiquidityCalcSamplingPeriod = 'x', AverageLiquidityPercentage = 'y', - UnfreezeMasternodes = 'z', AscendingBlockTime = 'A', GovHeightMinBlocks = 'B', CommunityGovernance = 'C', @@ -544,7 +543,6 @@ class ATTRIBUTES : public GovVariable, public AutoRegistrator unfreezeMasternodeHeight = std::nullopt; std::set tokenSplits{}; std::set interestTokens{}; std::set changed; diff --git a/src/dfi/masternodes.cpp b/src/dfi/masternodes.cpp index 97f0c5f30d..7265365a35 100644 --- a/src/dfi/masternodes.cpp +++ b/src/dfi/masternodes.cpp @@ -102,16 +102,10 @@ CAmount GetProposalCreationFee(int, const CCustomCSView &view, const CCreateProp return -1; } -uint8_t GetTimelockLoops(const uint16_t timelock, const int blockHeight, const CCustomCSView &view) { +uint8_t GetTimelockLoops(const uint16_t timelock, const int blockHeight) { if (blockHeight < Params().GetConsensus().DF10EunosPayaHeight) { return 1; } - const auto attributes = view.GetAttributes(); - CDataStructureV0 unfreezeKey{AttributeTypes::Param, ParamIDs::Feature, DFIPKeys::UnfreezeMasternodes}; - const auto unfreezeHeight = attributes->GetValue(unfreezeKey, std::numeric_limits::max()); - if (static_cast(blockHeight) >= unfreezeHeight) { - return 1; - } return timelock == CMasternode::TENYEAR ? 4 : timelock == CMasternode::FIVEYEAR ? 3 : 2; } @@ -544,7 +538,7 @@ void CMasternodesView::EraseSubNodesLastBlockTime(const uint256 &nodeId, const u std::optional CMasternodesView::GetTimelock(const uint256 &nodeId, const CMasternode &node, const uint64_t height) const { - if (const auto timelock = ReadTimelock(nodeId); timelock) { + if (const auto timelock = ReadBy(nodeId)) { LOCK(cs_main); // Get last height auto lastHeight = height - 1; @@ -581,14 +575,6 @@ std::optional CMasternodesView::GetTimelock(const uint256 &nodeId, return 0; } -void CMasternodesView::EraseTimelock(const uint256 &nodeId) { - EraseBy(nodeId); -} - -std::optional CMasternodesView::ReadTimelock(const uint256 &nodeId) const { - return ReadBy(nodeId); -} - std::vector CMasternodesView::GetBlockTimes(const CKeyID &keyID, const uint32_t blockHeight, const int32_t creationHeight, @@ -613,7 +599,7 @@ std::vector CMasternodesView::GetBlockTimes(const CKeyID &keyID, } // If no values set for pre-fork MN use the fork time - const auto loops = GetTimelockLoops(timelock, blockHeight, *static_cast(this)); + const auto loops = GetTimelockLoops(timelock, blockHeight); for (uint8_t i{0}; i < loops; ++i) { if (!subNodesBlockTime[i]) { subNodesBlockTime[i] = block->GetBlockTime(); diff --git a/src/dfi/masternodes.h b/src/dfi/masternodes.h index c529549afe..788cd50287 100644 --- a/src/dfi/masternodes.h +++ b/src/dfi/masternodes.h @@ -143,7 +143,7 @@ class CMasternode { friend bool operator!=(const CMasternode &a, const CMasternode &b); }; -uint8_t GetTimelockLoops(const uint16_t timelock, const int blockHeight, const CCustomCSView &view); +uint8_t GetTimelockLoops(const uint16_t timelock, const int blockHeight); struct CCreateMasterNodeMessage { char operatorType; @@ -311,8 +311,6 @@ class CMasternodesView : public virtual CStorageView { std::numeric_limits::max()}); std::optional GetTimelock(const uint256 &nodeId, const CMasternode &node, const uint64_t height) const; - std::optional ReadTimelock(const uint256 &nodeId) const; - void EraseTimelock(const uint256 &nodeId); // tags struct ID { diff --git a/src/dfi/rpc_masternodes.cpp b/src/dfi/rpc_masternodes.cpp index 37f7198d6c..f73a3a212e 100644 --- a/src/dfi/rpc_masternodes.cpp +++ b/src/dfi/rpc_masternodes.cpp @@ -58,7 +58,7 @@ UniValue mnToJSON(CCustomCSView &view, view.GetBlockTimes(node.operatorAuthAddress, currentHeight + 1, node.creationHeight, *timelock); if (currentHeight >= Params().GetConsensus().DF10EunosPayaHeight) { - const auto loops = GetTimelockLoops(*timelock, currentHeight, view); + const auto loops = GetTimelockLoops(*timelock, currentHeight); UniValue multipliers(UniValue::VARR); for (uint8_t i{0}; i < loops; ++i) { multipliers.push_back( diff --git a/src/dfi/validation.cpp b/src/dfi/validation.cpp index 99a308c76b..f1bed7ae43 100644 --- a/src/dfi/validation.cpp +++ b/src/dfi/validation.cpp @@ -4016,25 +4016,6 @@ static void ProcessTokenLock(const CBlock &block, LogPrintf(" - locking dToken oversupply took: %dms\n", GetTimeMillis() - time); } -static void ProcessUnfreezeMasternodes(const CBlockIndex *pindex, CCustomCSView &cache, BlockContext &blockCtx) { - const auto &consensus = blockCtx.GetConsensus(); - if (pindex->nHeight < consensus.DF24Height) { - return; - } - const auto attributes = cache.GetAttributes(); - CDataStructureV0 unfreezeKey{AttributeTypes::Param, ParamIDs::Feature, DFIPKeys::UnfreezeMasternodes}; - const auto unfreezeHeight = attributes->GetValue(unfreezeKey, std::numeric_limits::max()); - if (pindex->nHeight != unfreezeHeight) { - return; - } - cache.ForEachMasternode([&](const uint256 &id, CMasternode node) { - if (const auto timelock = cache.ReadTimelock(id)) { - cache.EraseTimelock(id); - } - return true; - }); -} - static void ProcessTokenSplits(const CBlockIndex *pindex, CCustomCSView &cache, const CreationTxs &creationTxs, @@ -4660,9 +4641,6 @@ Res ProcessDeFiEventFallible(const CBlock &block, } } - // Process unfreeze masternodes - ProcessUnfreezeMasternodes(pindex, cache, blockCtx); - // Construct undo FlushCacheCreateUndo(pindex, mnview, cache, uint256S(std::string(64, '1'))); diff --git a/src/miner.cpp b/src/miner.cpp index 5c18b9c025..dc408eba94 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1632,10 +1632,7 @@ namespace pos { const auto subNodesBlockTimes = pcustomcsview->GetBlockTimes(operatorId, blockHeight, creationHeight, *timeLock); - auto loops = GetTimelockLoops(*timeLock, blockHeight, *pcustomcsview); - if (blockHeight < Params().GetConsensus().DF10EunosPayaHeight) { - loops = 1; - } + auto loops = GetTimelockLoops(*timeLock, blockHeight); for (uint8_t i{}; i < loops; ++i) { const auto targetMultiplier = diff --git a/src/pos.cpp b/src/pos.cpp index 8f6c7ee0d9..37783f4d5c 100644 --- a/src/pos.cpp +++ b/src/pos.cpp @@ -92,10 +92,7 @@ bool ContextualCheckProofOfStake(const CBlockHeader& blockHeader, const Consensu } // checking PoS kernel is faster, so check it first - auto loops = GetTimelockLoops(timelock, height, *mnView); - if (height < static_cast(params.DF10EunosPayaHeight)) { - loops = 1; - } + auto loops = GetTimelockLoops(timelock, height); bool kernelFound{}; for (uint8_t i{}; i < loops; ++i) { diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 95bf2802e0..6bdcf342e6 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -336,7 +336,7 @@ static UniValue getmininginfo(const JSONRPCRequest& request) const auto subNodesBlockTime = pcustomcsview->GetBlockTimes(nodePtr->operatorAuthAddress, height, nodePtr->creationHeight, *timelock); if (height >= Params().GetConsensus().DF10EunosPayaHeight) { - const auto loops = GetTimelockLoops(*timelock, height, *pcustomcsview); + const auto loops = GetTimelockLoops(*timelock, height); UniValue multipliers(UniValue::VARR); for (uint8_t i{0}; i < loops; ++i) { multipliers.push_back(pos::CalcCoinDayWeight(Params().GetConsensus(), GetTime(), subNodesBlockTime[i]).getdouble()); diff --git a/test/functional/feature_unfreeze_masternodes.py b/test/functional/feature_unfreeze_masternodes.py deleted file mode 100755 index 34ef85f3dd..0000000000 --- a/test/functional/feature_unfreeze_masternodes.py +++ /dev/null @@ -1,187 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (c) 2014-2019 The Bitcoin Core developers -# Copyright (c) DeFi Blockchain Developers -# Distributed under the MIT software license, see the accompanying -# file LICENSE or http://www.opensource.org/licenses/mit-license.php. -"""Test unfreezing of masternodes""" - -from test_framework.test_framework import DefiTestFramework - -from test_framework.util import assert_equal, assert_raises_rpc_error - - -class UnfreezeMasternodesTest(DefiTestFramework): - def set_test_params(self): - self.num_nodes = 1 - self.setup_clean_chain = True - self.df24height = 200 - self.extra_args = [ - [ - "-txnotokens=0", - "-subsidytest=1", - "-amkheight=1", - "-bayfrontheight=1", - "-bayfrontmarinaheight=1", - "-bayfrontgardensheight=1", - "-clarkequayheight=1", - "-dakotaheight=1", - "-dakotacrescentheight=1", - "-eunosheight=1", - "-eunospayaheight=1", - "-fortcanningheight=1", - "-fortcanningmuseumheight=1", - "-fortcanningparkheight=1", - "-fortcanninghillheight=1", - "-fortcanningroadheight=1", - "-fortcanningcrunchheight=1", - "-fortcanningspringheight=1", - "-fortcanninggreatworldheight=1", - "-grandcentralheight=1", - "-grandcentralepilogueheight=1", - "-metachainheight=105", - "-df23height=110", - f"-df24height={self.df24height}", - ], - ] - - def run_test(self): - - # Set up - self.setup() - - # Run pre-fork checks - self.pre_fork_checks() - - # Set up Governance vars - self.set_gov_vars() - - # Check masternodes unfrozen - self.check_masternodes_unfrozen() - - # Check unfreeze height cannot be changed after activation - self.test_change_unfreeze() - - # Check setting of new frozen masternodes - self.test_new_frozen_masternodes() - - def setup(self): - - # Get masternode owner address - self.address = self.nodes[0].get_genesis_keys().ownerAuthAddress - - # Generate chain - self.nodes[0].generate(110) - - # Create time locked masternodes - self.node_5 = self.nodes[0].createmasternode( - self.nodes[0].getnewaddress("", "legacy"), "", [], "FIVEYEARTIMELOCK" - ) - self.node_10 = self.nodes[0].createmasternode( - self.nodes[0].getnewaddress("", "legacy"), "", [], "TENYEARTIMELOCK" - ) - self.nodes[0].generate(21) - - # Check masternodes - result = self.nodes[0].getmasternode(self.node_5)[self.node_5] - assert_equal(result["timelock"], "5 years") - assert_equal(len(result["targetMultipliers"]), 3) - result = self.nodes[0].getmasternode(self.node_10)[self.node_10] - assert_equal(result["timelock"], "10 years") - assert_equal(len(result["targetMultipliers"]), 4) - - def pre_fork_checks(self): - - # Unfreeze masternodes before fork - assert_raises_rpc_error( - -32600, - "Cannot be set before DF24Height", - self.nodes[0].setgov, - {"ATTRIBUTES": {"v0/params/feature/unfreeze_masternodes": "210"}}, - ) - - def set_gov_vars(self): - - # Move to fork height - self.nodes[0].generate(self.df24height - self.nodes[0].getblockcount()) - - # Try and set below current height - assert_raises_rpc_error( - -32600, - "Cannot be set at or below current height", - self.nodes[0].setgov, - {"ATTRIBUTES": {"v0/params/feature/unfreeze_masternodes": "200"}}, - ) - - # Set unfreeze height - self.nodes[0].setgov( - {"ATTRIBUTES": {"v0/params/feature/unfreeze_masternodes": "210"}} - ) - self.nodes[0].generate(1) - - # Check unfreeze height - assert_equal( - self.nodes[0].getgov("ATTRIBUTES")["ATTRIBUTES"][ - "v0/params/feature/unfreeze_masternodes" - ], - "210", - ) - - def check_masternodes_unfrozen(self): - - # Move to unfreezing height - self.nodes[0].generate(210 - self.nodes[0].getblockcount()) - - # Check time lock and target multipliers - result = self.nodes[0].getmasternode(self.node_5)[self.node_5] - assert "timelock" not in result - assert_equal(len(result["targetMultipliers"]), 1) - result = self.nodes[0].getmasternode(self.node_10)[self.node_10] - assert "timelock" not in result - assert_equal(len(result["targetMultipliers"]), 1) - - # Test resigning masternodes - self.nodes[0].resignmasternode(self.node_5) - self.nodes[0].resignmasternode(self.node_10) - self.nodes[0].generate(41) - - # Check masternodes resigned - result = self.nodes[0].getmasternode(self.node_5)[self.node_5] - assert_equal(result["state"], "RESIGNED") - result = self.nodes[0].getmasternode(self.node_10)[self.node_10] - assert_equal(result["state"], "RESIGNED") - - def test_change_unfreeze(self): - - # Try and change unfreeze height after activation - assert_raises_rpc_error( - -32600, - "Cannot change masternode unfreeze height after activation", - self.nodes[0].setgov, - {"ATTRIBUTES": {"v0/params/feature/unfreeze_masternodes": "400"}}, - ) - - def test_new_frozen_masternodes(self): - - # Try and create a masternode with a time lock - assert_raises_rpc_error( - -32600, - "Masternode timelock disabled", - self.nodes[0].createmasternode, - self.nodes[0].getnewaddress("", "legacy"), - "", - [], - "FIVEYEARTIMELOCK", - ) - assert_raises_rpc_error( - -32600, - "Masternode timelock disabled", - self.nodes[0].createmasternode, - self.nodes[0].getnewaddress("", "legacy"), - "", - [], - "TENYEARTIMELOCK", - ) - - -if __name__ == "__main__": - UnfreezeMasternodesTest().main() diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index d017348073..c7aba03ce8 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -352,7 +352,6 @@ "feature_shutdown.py", "feature_oracles.py", "feature_checkpoint.py", - "feature_unfreeze_masternodes.py", "rpc_getmininginfo.py", "feature_burn_address.py", "feature_eunos_balances.py",