From 2204c853706cf35e269a68ce4265688beb30d0cc Mon Sep 17 00:00:00 2001 From: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com> Date: Mon, 1 Nov 2021 11:31:48 -0400 Subject: [PATCH] governance: Implement reduced governance fee (#4241) * Implement hf for reduced governance fee Signed-off-by: pasta * update VersionBitsDeploymentInfo * Adjust activation times for gov fee hard fork * Use raw timestamps * Adjust timestamps Co-authored-by: UdjinM6 --- src/chainparams.cpp | 34 ++++++++++++++++++++++++++++++++++ src/consensus/params.h | 1 + src/governance/object.cpp | 10 +++++++--- src/governance/object.h | 5 +++-- src/rpc/governance.cpp | 5 ++++- src/versionbitsinfo.cpp | 5 +++++ 6 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 63ad23cb15..f0dd018112 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -216,6 +216,15 @@ public: consensus.vDeployments[Consensus::DEPLOYMENT_DIP0020].nThresholdMin = 2420; // 60% of 4032 consensus.vDeployments[Consensus::DEPLOYMENT_DIP0020].nFalloffCoeff = 5; // this corresponds to 10 periods + // Deployment of decreased proposal fee + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].bit = 7; + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nStartTime = 1638316800; // Dec 1st, 2021 + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nTimeout = 1669852800; // Dec 1st, 2022 + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nWindowSize = 4032; + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nThresholdStart = 3226; // 80% of 4032 + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nThresholdMin = 2420; // 60% of 4032 + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nFalloffCoeff = 5; // this corresponds to 10 periods + // The best chain should have at least this much work. consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000549cd3ccb81a55892330"); // 1450000 @@ -426,6 +435,15 @@ public: consensus.vDeployments[Consensus::DEPLOYMENT_DIP0020].nThresholdMin = 60; // 60% of 100 consensus.vDeployments[Consensus::DEPLOYMENT_DIP0020].nFalloffCoeff = 5; // this corresponds to 10 periods + // Deployment of decreased proposal fee + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].bit = 7; + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nStartTime = 999999999999ULL; // TODO renable this before first RC + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nTimeout = 999999999999ULL; + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nWindowSize = 4032; + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nThresholdStart = 3226; // 80% of 4032 + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nThresholdMin = 2420; // 60% of 4032 + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nFalloffCoeff = 5; // this corresponds to 10 periods + // The best chain should have at least this much work. consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000000000022f14ac5d56b5ef"); // 470000 @@ -608,6 +626,15 @@ public: consensus.vDeployments[Consensus::DEPLOYMENT_DIP0020].nThresholdMin = 60; // 60% of 100 consensus.vDeployments[Consensus::DEPLOYMENT_DIP0020].nFalloffCoeff = 5; // this corresponds to 10 periods + // Deployment of decreased proposal fee + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].bit = 7; + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nStartTime = 1635724800; // Nov 1st, 2021 + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nTimeout = 999999999999ULL; + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nWindowSize = 4032; + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nThresholdStart = 3226; // 80% of 4032 + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nThresholdMin = 2420; // 60% of 4032 + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nFalloffCoeff = 5; // this corresponds to 10 periods + // The best chain should have at least this much work. consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000000000000000000000000"); @@ -810,6 +837,13 @@ public: consensus.vDeployments[Consensus::DEPLOYMENT_DIP0020].nThresholdStart = 80; consensus.vDeployments[Consensus::DEPLOYMENT_DIP0020].nThresholdMin = 60; consensus.vDeployments[Consensus::DEPLOYMENT_DIP0020].nFalloffCoeff = 5; + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].bit = 7; + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nStartTime = 0; + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nTimeout = 999999999999ULL; + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nWindowSize = 100; + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nThresholdStart = 80; + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nThresholdMin = 60; + consensus.vDeployments[Consensus::DEPLOYMENT_GOV_FEE].nFalloffCoeff = 5; // 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 d2ae2345d6..4f66dc9fd3 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -23,6 +23,7 @@ enum DeploymentPos DEPLOYMENT_DIP0008, // Deployment of ChainLock enforcement DEPLOYMENT_REALLOC, // Deployment of Block Reward Reallocation DEPLOYMENT_DIP0020, // Deployment of DIP0020, DIP0021 and LMQ_100_67 quorums + DEPLOYMENT_GOV_FEE, // Deployment of decreased governance proposal fee // NOTE: Also add new deployments to VersionBitsDeploymentInfo in versionbits.cpp MAX_VERSION_BITS_DEPLOYMENTS }; diff --git a/src/governance/object.cpp b/src/governance/object.cpp index 28c9c87154..e904ae276f 100644 --- a/src/governance/object.cpp +++ b/src/governance/object.cpp @@ -507,12 +507,13 @@ bool CGovernanceObject::IsValidLocally(std::string& strError, bool& fMissingConf } } -CAmount CGovernanceObject::GetMinCollateralFee() const +CAmount CGovernanceObject::GetMinCollateralFee(bool fork_active) const { // Only 1 type has a fee for the moment but switch statement allows for future object types switch (nObjectType) { case GOVERNANCE_OBJECT_PROPOSAL: - return GOVERNANCE_PROPOSAL_FEE_TX; + if (fork_active) return GOVERNANCE_PROPOSAL_FEE_TX; + else return GOVERNANCE_PROPOSAL_FEE_TX_OLD; case GOVERNANCE_OBJECT_TRIGGER: return 0; default: @@ -524,7 +525,6 @@ bool CGovernanceObject::IsCollateralValid(std::string& strError, bool& fMissingC { strError = ""; fMissingConfirmations = false; - CAmount nMinFee = GetMinCollateralFee(); uint256 nExpectedHash = GetHash(); CTransactionRef txCollateral; @@ -555,6 +555,10 @@ bool CGovernanceObject::IsCollateralValid(std::string& strError, bool& fMissingC CScript findScript; findScript << OP_RETURN << ToByteVector(nExpectedHash); + AssertLockHeld(cs_main); + bool fork_active = VersionBitsState(LookupBlockIndex(nBlockHash), Params().GetConsensus(), Consensus::DEPLOYMENT_GOV_FEE, versionbitscache) == ThresholdState::ACTIVE; + CAmount nMinFee = GetMinCollateralFee(fork_active); + LogPrint(BCLog::GOBJECT, "CGovernanceObject::IsCollateralValid -- txCollateral->vout.size() = %s, findScript = %s, nMinFee = %lld\n", txCollateral->vout.size(), ScriptToAsmStr(findScript, false), nMinFee); diff --git a/src/governance/object.h b/src/governance/object.h index 85e1b393b2..edcb917d3e 100644 --- a/src/governance/object.h +++ b/src/governance/object.h @@ -30,7 +30,8 @@ static constexpr int GOVERNANCE_OBJECT_UNKNOWN = 0; static constexpr int GOVERNANCE_OBJECT_PROPOSAL = 1; static constexpr int GOVERNANCE_OBJECT_TRIGGER = 2; -static constexpr CAmount GOVERNANCE_PROPOSAL_FEE_TX = (5.0 * COIN); +static constexpr CAmount GOVERNANCE_PROPOSAL_FEE_TX = (1 * COIN); +static constexpr CAmount GOVERNANCE_PROPOSAL_FEE_TX_OLD = (5 * COIN); static constexpr int64_t GOVERNANCE_FEE_CONFIRMATIONS = 6; static constexpr int64_t GOVERNANCE_MIN_RELAY_FEE_CONFIRMATIONS = 1; @@ -258,7 +259,7 @@ public: } } - CAmount GetMinCollateralFee() const; + CAmount GetMinCollateralFee(bool fork_active) const; UniValue GetJSONObject() const; diff --git a/src/rpc/governance.cpp b/src/rpc/governance.cpp index a8f3e71893..67d2e1662e 100644 --- a/src/rpc/governance.cpp +++ b/src/rpc/governance.cpp @@ -220,7 +220,10 @@ static UniValue gobject_prepare(const JSONRPCRequest& request) } CTransactionRef tx; - if (!pwallet->GetBudgetSystemCollateralTX(*locked_chain, tx, govobj.GetHash(), govobj.GetMinCollateralFee(), outpoint)) { + + bool fork_active = VersionBitsTipState(Params().GetConsensus(), Consensus::DEPLOYMENT_GOV_FEE) == ThresholdState::ACTIVE; + + if (!pwallet->GetBudgetSystemCollateralTX(*locked_chain, tx, govobj.GetHash(), govobj.GetMinCollateralFee(fork_active), outpoint)) { std::string err = "Error making collateral transaction for governance object. Please check your wallet balance and make sure your wallet is unlocked."; if (!request.params[6].isNull() && !request.params[7].isNull()) { err += "Please verify your specified output is valid and is enough for the combined proposal fee and transaction fee."; diff --git a/src/versionbitsinfo.cpp b/src/versionbitsinfo.cpp index 50baed90dc..2b30fbf464 100644 --- a/src/versionbitsinfo.cpp +++ b/src/versionbitsinfo.cpp @@ -47,4 +47,9 @@ const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_B /*.gbt_force =*/ true, /*.check_mn_protocol =*/ false, }, + { + /*.name =*/ "gov_fee", + /*.gbt_force =*/ true, + /*.check_mn_protocol =*/ false, + }, };