Skip to content

Commit

Permalink
Remove unfreeze feature (#3072)
Browse files Browse the repository at this point in the history
* Revert "feat: unfreeze mn (#3062)"

This reverts commit e1972d8.

* Retain GetTimeLockLoop changes
  • Loading branch information
Bushstar authored Sep 30, 2024
1 parent 50a50e8 commit 7b0665e
Show file tree
Hide file tree
Showing 13 changed files with 9 additions and 279 deletions.
7 changes: 0 additions & 7 deletions src/dfi/consensus/masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ Res CMasternodesConsensus::operator()(const CCreateMasterNodeMessage &obj) const
}

if (height >= static_cast<uint32_t>(consensus.DF10EunosPayaHeight)) {
const auto attributes = mnview.GetAttributes();
CDataStructureV0 unfreezeKey{AttributeTypes::Param, ParamIDs::Feature, DFIPKeys::UnfreezeMasternodes};
const auto unfreezeHeight = attributes->GetValue(unfreezeKey, std::numeric_limits<uint64_t>::max());
if (static_cast<uint64_t>(unfreezeHeight) < height && obj.timelock != 0) {
return Res::Err("Masternode timelock disabled");
}

switch (obj.timelock) {
case CMasternode::ZEROYEAR:
case CMasternode::FIVEYEAR:
Expand Down
4 changes: 0 additions & 4 deletions src/dfi/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
27 changes: 1 addition & 26 deletions src/dfi/govvariables/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ const std::map<uint8_t, std::map<std::string, uint8_t>> &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},
Expand Down Expand Up @@ -396,7 +395,6 @@ const std::map<uint8_t, std::map<uint8_t, std::string>> &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"},
Expand Down Expand Up @@ -831,7 +829,6 @@ const std::map<uint8_t, std::map<uint8_t, std::function<ResVal<CAttributeValue>(
{DFIPKeys::TransferDomain, VerifyBool},
{DFIPKeys::LiquidityCalcSamplingPeriod, VerifyMoreThenZeroInt64},
{DFIPKeys::AverageLiquidityPercentage, VerifyPctInt64},
{DFIPKeys::UnfreezeMasternodes, VerifyMoreThenZeroUInt64},
{DFIPKeys::CommunityGovernance, VerifyBool},
{DFIPKeys::AscendingBlockTime, VerifyBool},
{DFIPKeys::GovHeightMinBlocks, VerifyMoreThenZeroUInt64},
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<uint64_t>::max());
}
}

if (attrV0->type == AttributeTypes::Param) {
Expand Down Expand Up @@ -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<uint64_t>(&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) {
Expand Down
2 changes: 0 additions & 2 deletions src/dfi/govvariables/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ enum DFIPKeys : uint8_t {
TransferDomain = 'w',
LiquidityCalcSamplingPeriod = 'x',
AverageLiquidityPercentage = 'y',
UnfreezeMasternodes = 'z',
AscendingBlockTime = 'A',
GovHeightMinBlocks = 'B',
CommunityGovernance = 'C',
Expand Down Expand Up @@ -544,7 +543,6 @@ class ATTRIBUTES : public GovVariable, public AutoRegistrator<GovVariable, ATTRI
bool futureUpdated{};
bool futureDUSDUpdated{};
bool dTokenRestartUpdated{};
std::optional<uint64_t> unfreezeMasternodeHeight = std::nullopt;
std::set<uint32_t> tokenSplits{};
std::set<uint32_t> interestTokens{};
std::set<CAttributeType> changed;
Expand Down
20 changes: 3 additions & 17 deletions src/dfi/masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>::max());
if (static_cast<uint64_t>(blockHeight) >= unfreezeHeight) {
return 1;
}
return timelock == CMasternode::TENYEAR ? 4 : timelock == CMasternode::FIVEYEAR ? 3 : 2;
}

Expand Down Expand Up @@ -544,7 +538,7 @@ void CMasternodesView::EraseSubNodesLastBlockTime(const uint256 &nodeId, const u
std::optional<uint16_t> 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<Timelock, uint16_t>(nodeId)) {
LOCK(cs_main);
// Get last height
auto lastHeight = height - 1;
Expand Down Expand Up @@ -581,14 +575,6 @@ std::optional<uint16_t> CMasternodesView::GetTimelock(const uint256 &nodeId,
return 0;
}

void CMasternodesView::EraseTimelock(const uint256 &nodeId) {
EraseBy<Timelock>(nodeId);
}

std::optional<uint16_t> CMasternodesView::ReadTimelock(const uint256 &nodeId) const {
return ReadBy<Timelock, uint16_t>(nodeId);
}

std::vector<int64_t> CMasternodesView::GetBlockTimes(const CKeyID &keyID,
const uint32_t blockHeight,
const int32_t creationHeight,
Expand All @@ -613,7 +599,7 @@ std::vector<int64_t> 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<CCustomCSView *>(this));
const auto loops = GetTimelockLoops(timelock, blockHeight);
for (uint8_t i{0}; i < loops; ++i) {
if (!subNodesBlockTime[i]) {
subNodesBlockTime[i] = block->GetBlockTime();
Expand Down
4 changes: 1 addition & 3 deletions src/dfi/masternodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -311,8 +311,6 @@ class CMasternodesView : public virtual CStorageView {
std::numeric_limits<uint32_t>::max()});

std::optional<uint16_t> GetTimelock(const uint256 &nodeId, const CMasternode &node, const uint64_t height) const;
std::optional<uint16_t> ReadTimelock(const uint256 &nodeId) const;
void EraseTimelock(const uint256 &nodeId);

// tags
struct ID {
Expand Down
2 changes: 1 addition & 1 deletion src/dfi/rpc_masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 0 additions & 22 deletions src/dfi/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4018,25 +4018,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<uint64_t>::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,
Expand Down Expand Up @@ -4679,9 +4660,6 @@ Res ProcessDeFiEventFallible(const CBlock &block,
}
}

// Process unfreeze masternodes
ProcessUnfreezeMasternodes(pindex, cache, blockCtx);

// Construct undo
FlushCacheCreateUndo(pindex, mnview, cache, uint256S(std::string(64, '1')));

Expand Down
5 changes: 1 addition & 4 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
5 changes: 1 addition & 4 deletions src/pos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>(params.DF10EunosPayaHeight)) {
loops = 1;
}
auto loops = GetTimelockLoops(timelock, height);

bool kernelFound{};
for (uint8_t i{}; i < loops; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading

0 comments on commit 7b0665e

Please sign in to comment.