From b310736382f270302766062cf7c5aca783080634 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Thu, 8 Aug 2024 22:52:10 +0300 Subject: [PATCH] refactor!: Governance collateral/fee is actually a commitment https://github.com/dashpay/docs-core/issues/108 --- src/governance/common.cpp | 6 +- src/governance/common.h | 8 +-- src/governance/governance.cpp | 6 +- src/governance/object.cpp | 72 +++++++++---------- src/governance/object.h | 22 +++--- src/interfaces/node.h | 2 +- src/rpc/governance.cpp | 46 ++++++------ src/wallet/wallet.cpp | 4 +- src/wallet/wallet.h | 2 +- test/functional/feature_governance.py | 2 +- test/functional/feature_governance_cl.py | 12 ++-- test/functional/feature_governance_objects.py | 6 +- test/functional/interface_zmq_dash.py | 6 +- test/functional/test_framework/messages.py | 8 +-- 14 files changed, 101 insertions(+), 101 deletions(-) diff --git a/src/governance/common.cpp b/src/governance/common.cpp index 81d1b3f1c0c768..44e4f24751af91 100644 --- a/src/governance/common.cpp +++ b/src/governance/common.cpp @@ -12,11 +12,11 @@ namespace Governance { -Object::Object(const uint256& nHashParent, int nRevision, int64_t nTime, const uint256& nCollateralHash, const std::string& strDataHex) : +Object::Object(const uint256& nHashParent, int nRevision, int64_t nTime, const uint256& commitment_hash, const std::string& strDataHex) : hashParent{nHashParent}, revision{nRevision}, time{nTime}, - collateralHash{nCollateralHash}, + m_commitment_hash{commitment_hash}, masternodeOutpoint{}, vchSig{}, vchData{ParseHex(strDataHex)} @@ -46,7 +46,7 @@ UniValue Object::ToJson() const UniValue obj(UniValue::VOBJ); obj.pushKV("objectHash", GetHash().ToString()); obj.pushKV("parentHash", hashParent.ToString()); - obj.pushKV("collateralHash", collateralHash.ToString()); + obj.pushKV("commitmentHash", m_commitment_hash.ToString()); obj.pushKV("createdAt", time); obj.pushKV("revision", revision); UniValue data; diff --git a/src/governance/common.h b/src/governance/common.h index ae053d850413a8..d1e0d4ba2c0fb6 100644 --- a/src/governance/common.h +++ b/src/governance/common.h @@ -34,7 +34,7 @@ class Object public: Object() = default; - Object(const uint256& nHashParent, int nRevision, int64_t nTime, const uint256& nCollateralHash, const std::string& strDataHex); + Object(const uint256& nHashParent, int nRevision, int64_t nTime, const uint256& commitment_hash, const std::string& strDataHex); UniValue ToJson() const; @@ -55,8 +55,8 @@ class Object /// time this object was created int64_t time{0}; - /// fee-tx - uint256 collateralHash{}; + /// commitment tx id + uint256 m_commitment_hash{}; /// Masternode info for signed objects COutPoint masternodeOutpoint; @@ -71,7 +71,7 @@ class Object obj.hashParent, obj.revision, obj.time, - obj.collateralHash, + obj.m_commitment_hash, obj.vchData, obj.type, obj.masternodeOutpoint diff --git a/src/governance/governance.cpp b/src/governance/governance.cpp index 6b195ea831d445..284074bd33be4e 100644 --- a/src/governance/governance.cpp +++ b/src/governance/governance.cpp @@ -561,7 +561,7 @@ struct sortProposalsByVotes { bool operator()(const std::pair& left, const std::pair& right) const { if (left.second != right.second) return (left.second > right.second); - return (UintToArith256(left.first->GetCollateralHash()) > UintToArith256(right.first->GetCollateralHash())); + return (UintToArith256(left.first->GetCommitmentHash()) > UintToArith256(right.first->GetCommitmentHash())); } }; @@ -680,7 +680,7 @@ std::optional CGovernanceManager::CreateGovernanceTrigg // no sb_opt, no trigger if (!sb_opt.has_value()) return std::nullopt; - //TODO: Check if nHashParentIn, nRevision and nCollateralHashIn are correct + //TODO: Check if nHashParentIn, nRevision and m_commitment_hash are correct LOCK2(cs_main, cs); // Check if identical trigger (equal DataHash()) is already created (signed by other masternode) @@ -1141,7 +1141,7 @@ void CGovernanceManager::CheckPostponedObjects(PeerManager& peerman) std::string strError; bool fMissingConfirmations; - if (govobj.IsCollateralValid(m_chainman, strError, fMissingConfirmations)) { + if (govobj.IsCommitmentValid(m_chainman, strError, fMissingConfirmations)) { if (govobj.IsValidLocally(Assert(m_dmnman)->GetListAtChainTip(), m_chainman, strError, false)) { AddGovernanceObject(govobj, peerman); } else { diff --git a/src/governance/object.cpp b/src/governance/object.cpp index c176b2196be197..bbe4664f534b59 100644 --- a/src/governance/object.cpp +++ b/src/governance/object.cpp @@ -42,9 +42,9 @@ CGovernanceObject::CGovernanceObject() : LoadData(); } -CGovernanceObject::CGovernanceObject(const uint256& nHashParentIn, int nRevisionIn, int64_t nTimeIn, const uint256& nCollateralHashIn, const std::string& strDataHexIn) : +CGovernanceObject::CGovernanceObject(const uint256& nHashParentIn, int nRevisionIn, int64_t nTimeIn, const uint256& commitment_hash, const std::string& strDataHexIn) : cs(), - m_obj{nHashParentIn, nRevisionIn, nTimeIn, nCollateralHashIn, strDataHexIn}, + m_obj{nHashParentIn, nRevisionIn, nTimeIn, commitment_hash, strDataHexIn}, nDeletionTime(0), fCachedLocalValidity(false), strLocalValidityError(), @@ -400,19 +400,19 @@ UniValue CGovernanceObject::ToJson() const void CGovernanceObject::UpdateLocalValidity(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman) { AssertLockHeld(cs_main); - // THIS DOES NOT CHECK COLLATERAL, THIS IS CHECKED UPON ORIGINAL ARRIVAL + // THIS DOES NOT CHECK COMMITMENT TX, THIS IS CHECKED UPON ORIGINAL ARRIVAL fCachedLocalValidity = IsValidLocally(tip_mn_list, chainman, strLocalValidityError, false); } -bool CGovernanceObject::IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool fCheckCollateral) const +bool CGovernanceObject::IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool check_commitment) const { bool fMissingConfirmations = false; - return IsValidLocally(tip_mn_list, chainman, strError, fMissingConfirmations, fCheckCollateral); + return IsValidLocally(tip_mn_list, chainman, strError, fMissingConfirmations, check_commitment); } -bool CGovernanceObject::IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations, bool fCheckCollateral) const +bool CGovernanceObject::IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations, bool check_commitment) const { AssertLockHeld(cs_main); @@ -433,14 +433,14 @@ bool CGovernanceObject::IsValidLocally(const CDeterministicMNList& tip_mn_list, strError = strprintf("Invalid proposal data, error messages: %s", validator.GetErrorMessages()); return false; } - if (fCheckCollateral && !IsCollateralValid(chainman, strError, fMissingConfirmations)) { - strError = "Invalid proposal collateral"; + if (check_commitment && !IsCommitmentValid(chainman, strError, fMissingConfirmations)) { + strError = "Invalid proposal commitment"; return false; } return true; } case GovernanceObject::TRIGGER: { - if (!fCheckCollateral) { + if (!check_commitment) { // nothing else we can check here (yet?) return true; } @@ -467,12 +467,12 @@ bool CGovernanceObject::IsValidLocally(const CDeterministicMNList& tip_mn_list, } } -CAmount CGovernanceObject::GetMinCollateralFee() const +CAmount CGovernanceObject::GetMinCommitmentAmount() const { - // Only 1 type has a fee for the moment but switch statement allows for future object types + // Only 1 type has a commitment requirement for the moment but switch statement allows for future object types switch (m_obj.type) { case GovernanceObject::PROPOSAL: { - return GOVERNANCE_PROPOSAL_FEE_TX; + return GOVERNANCE_COMMITMENT_AMOUNT; } case GovernanceObject::TRIGGER: { return 0; @@ -483,7 +483,7 @@ CAmount CGovernanceObject::GetMinCollateralFee() const } } -bool CGovernanceObject::IsCollateralValid(const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations) const +bool CGovernanceObject::IsCommitmentValid(const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations) const { AssertLockHeld(cs_main); @@ -493,22 +493,22 @@ bool CGovernanceObject::IsCollateralValid(const ChainstateManager& chainman, std // RETRIEVE TRANSACTION IN QUESTION uint256 nBlockHash; - CTransactionRef txCollateral = GetTransaction(/* block_index */ nullptr, /* mempool */ nullptr, m_obj.collateralHash, Params().GetConsensus(), nBlockHash); - if (!txCollateral) { - strError = strprintf("Can't find collateral tx %s", m_obj.collateralHash.ToString()); - LogPrintf("CGovernanceObject::IsCollateralValid -- %s\n", strError); + CTransactionRef commitment_tx = GetTransaction(/* block_index */ nullptr, /* mempool */ nullptr, m_obj.m_commitment_hash, Params().GetConsensus(), nBlockHash); + if (!commitment_tx) { + strError = strprintf("Can't find commitment tx %s", m_obj.m_commitment_hash.ToString()); + LogPrintf("CGovernanceObject::%s -- %s\n", __func__, strError); return false; } if (nBlockHash == uint256()) { - strError = strprintf("Collateral tx %s is not mined yet", txCollateral->ToString()); - LogPrintf("CGovernanceObject::IsCollateralValid -- %s\n", strError); + strError = strprintf("Commitment tx %s is not mined yet", commitment_tx->ToString()); + LogPrintf("CGovernanceObject::%s -- %s\n", __func__, strError); return false; } - if (txCollateral->vout.empty()) { + if (commitment_tx->vout.empty()) { strError = "tx vout is empty"; - LogPrintf("CGovernanceObject::IsCollateralValid -- %s\n", strError); + LogPrintf("CGovernanceObject::%s -- %s\n", __func__, strError); return false; } @@ -517,28 +517,28 @@ bool CGovernanceObject::IsCollateralValid(const ChainstateManager& chainman, std CScript findScript; findScript << OP_RETURN << ToByteVector(nExpectedHash); - CAmount nMinFee = GetMinCollateralFee(); + CAmount commitment_amount = GetMinCommitmentAmount(); - LogPrint(BCLog::GOBJECT, "CGovernanceObject::IsCollateralValid -- txCollateral->vout.size() = %s, findScript = %s, nMinFee = %lld\n", - txCollateral->vout.size(), ScriptToAsmStr(findScript, false), nMinFee); + LogPrint(BCLog::GOBJECT, "CGovernanceObject::%s -- commitment_tx->vout.size() = %s, findScript = %s, commitment_amount = %lld\n", + __func__, commitment_tx->vout.size(), ScriptToAsmStr(findScript, false), commitment_amount); bool foundOpReturn = false; - for (const auto& output : txCollateral->vout) { - LogPrint(BCLog::GOBJECT, "CGovernanceObject::IsCollateralValid -- txout = %s, output.nValue = %lld, output.scriptPubKey = %s\n", - output.ToString(), output.nValue, ScriptToAsmStr(output.scriptPubKey, false)); + for (const auto& output : commitment_tx->vout) { + LogPrint(BCLog::GOBJECT, "CGovernanceObject::%s -- txout = %s, output.nValue = %lld, output.scriptPubKey = %s\n", + __func__, output.ToString(), output.nValue, ScriptToAsmStr(output.scriptPubKey, false)); if (!output.scriptPubKey.IsPayToPublicKeyHash() && !output.scriptPubKey.IsUnspendable()) { - strError = strprintf("Invalid Script %s", txCollateral->ToString()); - LogPrintf("CGovernanceObject::IsCollateralValid -- %s\n", strError); + strError = strprintf("Invalid Script %s", commitment_tx->ToString()); + LogPrintf("CGovernanceObject::%s -- %s\n", __func__, strError); return false; } - if (output.scriptPubKey == findScript && output.nValue >= nMinFee) { + if (output.scriptPubKey == findScript && output.nValue >= commitment_amount) { foundOpReturn = true; } } if (!foundOpReturn) { - strError = strprintf("Couldn't find opReturn %s in %s", nExpectedHash.ToString(), txCollateral->ToString()); - LogPrintf("CGovernanceObject::IsCollateralValid -- %s\n", strError); + strError = strprintf("Couldn't find opReturn %s in %s", nExpectedHash.ToString(), commitment_tx->ToString()); + LogPrintf("CGovernanceObject::%s -- %s\n", __func__, strError); return false; } @@ -553,15 +553,15 @@ bool CGovernanceObject::IsCollateralValid(const ChainstateManager& chainman, std } } - if (nConfirmationsIn < GOVERNANCE_FEE_CONFIRMATIONS) { - strError = strprintf("Collateral requires at least %d confirmations to be relayed throughout the network (it has only %d)", GOVERNANCE_FEE_CONFIRMATIONS, nConfirmationsIn); - if (nConfirmationsIn >= GOVERNANCE_MIN_RELAY_FEE_CONFIRMATIONS) { + if (nConfirmationsIn < GOVERNANCE_COMMITMENT_CONFIRMATIONS) { + strError = strprintf("Commitment tx requires at least %d confirmations to be relayed throughout the network (it has only %d)", GOVERNANCE_COMMITMENT_CONFIRMATIONS, nConfirmationsIn); + if (nConfirmationsIn >= GOVERNANCE_COMMITMENT_MIN_RELAY_CONFIRMATIONS) { fMissingConfirmations = true; strError += ", pre-accepted -- waiting for required confirmations"; } else { strError += ", rejected -- try again later"; } - LogPrintf("CGovernanceObject::IsCollateralValid -- %s\n", strError); + LogPrintf("CGovernanceObject::%s -- %s\n", __func__, strError); return false; } diff --git a/src/governance/object.h b/src/governance/object.h index 6cfea6eb502da2..b9a72bced1c534 100644 --- a/src/governance/object.h +++ b/src/governance/object.h @@ -30,10 +30,10 @@ extern RecursiveMutex cs_main; static constexpr double GOVERNANCE_FILTER_FP_RATE = 0.001; -static constexpr CAmount GOVERNANCE_PROPOSAL_FEE_TX = (1 * COIN); +static constexpr CAmount GOVERNANCE_COMMITMENT_AMOUNT = (1 * COIN); +static constexpr int64_t GOVERNANCE_COMMITMENT_CONFIRMATIONS = 6; +static constexpr int64_t GOVERNANCE_COMMITMENT_MIN_RELAY_CONFIRMATIONS = 1; -static constexpr int64_t GOVERNANCE_FEE_CONFIRMATIONS = 6; -static constexpr int64_t GOVERNANCE_MIN_RELAY_FEE_CONFIRMATIONS = 1; static constexpr int64_t GOVERNANCE_UPDATE_MIN = 60 * 60; static constexpr int64_t GOVERNANCE_DELETION_DELAY = 10 * 60; static constexpr int64_t GOVERNANCE_ORPHAN_EXPIRATION_TIME = 10 * 60; @@ -142,7 +142,7 @@ class CGovernanceObject public: CGovernanceObject(); - CGovernanceObject(const uint256& nHashParentIn, int nRevisionIn, int64_t nTime, const uint256& nCollateralHashIn, const std::string& strDataHexIn); + CGovernanceObject(const uint256& nHashParentIn, int nRevisionIn, int64_t nTime, const uint256& commitment_hash, const std::string& strDataHexIn); CGovernanceObject(const CGovernanceObject& other); @@ -168,9 +168,9 @@ class CGovernanceObject return m_obj.type; } - const uint256& GetCollateralHash() const + const uint256& GetCommitmentHash() const { - return m_obj.collateralHash; + return m_obj.m_commitment_hash; } const COutPoint& GetMasternodeOutpoint() const @@ -228,12 +228,12 @@ class CGovernanceObject // CORE OBJECT FUNCTIONS - bool IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool fCheckCollateral) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); + bool IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool check_commitment) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); - bool IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations, bool fCheckCollateral) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); + bool IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations, bool check_commitment) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); - /// Check the collateral transaction for the budget proposal/finalized budget - bool IsCollateralValid(const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); + /// Check the commitment transaction for the budget proposal/finalized budget + bool IsCommitmentValid(const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); void UpdateLocalValidity(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman); @@ -247,7 +247,7 @@ class CGovernanceObject } } - CAmount GetMinCollateralFee() const; + CAmount GetMinCommitmentAmount() const; UniValue GetJSONObject() const; diff --git a/src/interfaces/node.h b/src/interfaces/node.h index 46b6f643171a02..ac1eeb3ec43953 100644 --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -64,7 +64,7 @@ class GOV virtual ~GOV() {} virtual void getAllNewerThan(std::vector &objs, int64_t nMoreThanTime) = 0; virtual int32_t getObjAbsYesCount(const CGovernanceObject& obj, vote_signal_enum_t vote_signal) = 0; - virtual bool getObjLocalValidity(const CGovernanceObject& obj, std::string& error, bool check_collateral) = 0; + virtual bool getObjLocalValidity(const CGovernanceObject& obj, std::string& error, bool check_commitment) = 0; virtual bool isEnabled() = 0; virtual void setContext(NodeContext* context) {} }; diff --git a/src/rpc/governance.cpp b/src/rpc/governance.cpp index bdee7e77402af2..2005f3bffbaf68 100644 --- a/src/rpc/governance.cpp +++ b/src/rpc/governance.cpp @@ -122,7 +122,7 @@ static RPCHelpMan gobject_check() } #ifdef ENABLE_WALLET -// PREPARE THE GOVERNANCE OBJECT BY CREATING A COLLATERAL TRANSACTION +// PREPARE THE GOVERNANCE OBJECT BY CREATING A COMMITMENT TRANSACTION static RPCHelpMan gobject_prepare() { return RPCHelpMan{"gobject prepare", @@ -134,7 +134,7 @@ static RPCHelpMan gobject_prepare() {"time", RPCArg::Type::NUM, RPCArg::Optional::NO, "time this object was created"}, {"data-hex", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "data in hex string form"}, {"use-IS", RPCArg::Type::BOOL, /* default */ "false", "Deprecated and ignored"}, - {"outputHash", RPCArg::Type::STR_HEX, /* default */ "", "the single output to submit the proposal fee from"}, + {"outputHash", RPCArg::Type::STR_HEX, /* default */ "", "the single output to submit the proposal commitment from"}, {"outputIndex", RPCArg::Type::NUM, /* default */ "", "The output index."}, }, RPCResults{}, @@ -161,7 +161,7 @@ static RPCHelpMan gobject_prepare() int64_t nTime = ParseInt64V(request.params[2], "time"); std::string strDataHex = request.params[3].get_str(); - // CREATE A NEW COLLATERAL TRANSACTION FOR THIS SPECIFIC OBJECT + // CREATE A NEW COMMITMENT TRANSACTION FOR THIS SPECIFIC OBJECT CGovernanceObject govobj(hashParent, nRevision, nTime, uint256(), strDataHex); @@ -202,24 +202,24 @@ static RPCHelpMan gobject_prepare() throw JSONRPCError(RPC_INTERNAL_ERROR, "Governance object is not valid - " + govobj.GetHash().ToString() + " - " + strError); } - // If specified, spend this outpoint as the proposal fee + // If specified, spend this outpoint as the proposal commitment COutPoint outpoint; outpoint.SetNull(); if (!request.params[5].isNull() && !request.params[6].isNull()) { - uint256 collateralHash(ParseHashV(request.params[5], "outputHash")); - int32_t collateralIndex = ParseInt32V(request.params[6], "outputIndex"); - if (collateralHash.IsNull() || collateralIndex < 0) { - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("invalid hash or index: %s-%d", collateralHash.ToString(), collateralIndex)); + uint256 outputHash(ParseHashV(request.params[5], "outputHash")); + int32_t outputIndex = ParseInt32V(request.params[6], "outputIndex"); + if (outputHash.IsNull() || outputIndex < 0) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("invalid hash or index: %s-%d", outputHash.ToString(), outputIndex)); } - outpoint = COutPoint(collateralHash, (uint32_t)collateralIndex); + outpoint = COutPoint(outputHash, (uint32_t)outputIndex); } CTransactionRef tx; - if (!wallet->GetBudgetSystemCollateralTX(tx, govobj.GetHash(), govobj.GetMinCollateralFee(), outpoint)) { - std::string err = "Error making collateral transaction for governance object. Please check your wallet balance and make sure your wallet is unlocked."; + if (!wallet->CreateGovernanceCommitmentTransaction(tx, govobj.GetHash(), govobj.GetMinCommitmentAmount(), outpoint)) { + std::string err = "Error making commitment transaction for governance object. Please check your wallet balance and make sure your wallet is unlocked."; if (!request.params[5].isNull() && !request.params[6].isNull()) { - err += "Please verify your specified output is valid and is enough for the combined proposal fee and transaction fee."; + err += "Please verify your specified output is valid and is enough for the combined proposal commitment and transaction fee."; } throw JSONRPCError(RPC_INTERNAL_ERROR, err); } @@ -279,7 +279,7 @@ static RPCHelpMan gobject_list_prepared() } #endif // ENABLE_WALLET -// AFTER COLLATERAL TRANSACTION HAS MATURED USER CAN SUBMIT GOVERNANCE OBJECT TO PROPAGATE NETWORK +// AFTER COMMITMENT TRANSACTION HAS MATURED USER CAN SUBMIT GOVERNANCE OBJECT TO PROPAGATE NETWORK /* ------ Example Governance Item ------ @@ -294,7 +294,7 @@ static RPCHelpMan gobject_submit() {"revision", RPCArg::Type::NUM, RPCArg::Optional::NO, "object revision in the system"}, {"time", RPCArg::Type::NUM, RPCArg::Optional::NO, "time this object was created"}, {"data-hex", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "data in hex string form"}, - {"fee-txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "txid of the corresponding proposal fee transaction"}, + {"commitment-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "txid of the corresponding proposal commitment transaction"}, }, RPCResults{}, RPCExamples{""}, @@ -327,10 +327,10 @@ static RPCHelpMan gobject_submit() // ASSEMBLE NEW GOVERNANCE OBJECT FROM USER PARAMETERS - uint256 txidFee; + uint256 commitment_hash; if (!request.params[4].isNull()) { - txidFee = ParseHashV(request.params[4], "fee-txid"); + commitment_hash = ParseHashV(request.params[4], "commitment"); } uint256 hashParent; if (request.params[0].get_str() == "0") { // attach to root node (root node doesn't really exist, but has a hash of zero) @@ -345,10 +345,10 @@ static RPCHelpMan gobject_submit() int64_t nTime = ParseInt64V(request.params[2], "time"); std::string strDataHex = request.params[3].get_str(); - CGovernanceObject govobj(hashParent, nRevision, nTime, txidFee, strDataHex); + CGovernanceObject govobj(hashParent, nRevision, nTime, commitment_hash, strDataHex); - LogPrint(BCLog::GOBJECT, "gobject_submit -- GetDataAsPlainString = %s, hash = %s, txid = %s\n", - govobj.GetDataAsPlainString(), govobj.GetHash().ToString(), txidFee.ToString()); + LogPrint(BCLog::GOBJECT, "gobject_submit -- GetDataAsPlainString = %s, hash = %s, commitment_hash = %s\n", + govobj.GetDataAsPlainString(), govobj.GetHash().ToString(), commitment_hash.ToString()); if (govobj.GetObjectType() == GovernanceObject::TRIGGER) { LogPrintf("govobject(submit) -- Object submission rejected because submission of trigger is disabled\n"); @@ -655,7 +655,7 @@ static UniValue ListObjects(CGovernanceManager& govman, const CDeterministicMNLi bObj.pushKV("DataHex", govObj.GetDataAsHexString()); bObj.pushKV("DataString", govObj.GetDataAsPlainString()); bObj.pushKV("Hash", govObj.GetHash().ToString()); - bObj.pushKV("CollateralHash", govObj.GetCollateralHash().ToString()); + bObj.pushKV("CommitmentHash", govObj.GetCommitmentHash().ToString()); bObj.pushKV("ObjectType", ToUnderlying(govObj.GetObjectType())); bObj.pushKV("CreationTime", govObj.GetCreationTime()); const COutPoint& masternodeOutpoint = govObj.GetMasternodeOutpoint(); @@ -773,7 +773,7 @@ static RPCHelpMan gobject_get() objResult.pushKV("DataHex", pGovObj->GetDataAsHexString()); objResult.pushKV("DataString", pGovObj->GetDataAsPlainString()); objResult.pushKV("Hash", pGovObj->GetHash().ToString()); - objResult.pushKV("CollateralHash", pGovObj->GetCollateralHash().ToString()); + objResult.pushKV("CommitmentHash", pGovObj->GetCommitmentHash().ToString()); objResult.pushKV("ObjectType", ToUnderlying(pGovObj->GetObjectType())); objResult.pushKV("CreationTime", pGovObj->GetCreationTime()); const COutPoint& masternodeOutpoint = pGovObj->GetMasternodeOutpoint(); @@ -1014,7 +1014,7 @@ static RPCHelpMan getgovernanceinfo() RPCResult::Type::OBJ, "", "", { {RPCResult::Type::NUM, "governanceminquorum", "the absolute minimum number of votes needed to trigger a governance action"}, - {RPCResult::Type::NUM, "proposalfee", "the collateral transaction fee which must be paid to create a proposal in " + CURRENCY_UNIT + ""}, + {RPCResult::Type::NUM, "commitmentamount", "the amount which must be paid to create a proposal in " + CURRENCY_UNIT + ""}, {RPCResult::Type::NUM, "superblockcycle", "the number of blocks between superblocks"}, {RPCResult::Type::NUM, "superblockmaturitywindow", "the superblock trigger creation window"}, {RPCResult::Type::NUM, "lastsuperblock", "the block number of the last superblock"}, @@ -1042,7 +1042,7 @@ static RPCHelpMan getgovernanceinfo() UniValue obj(UniValue::VOBJ); obj.pushKV("governanceminquorum", Params().GetConsensus().nGovernanceMinQuorum); - obj.pushKV("proposalfee", ValueFromAmount(GOVERNANCE_PROPOSAL_FEE_TX)); + obj.pushKV("commitmentamount", ValueFromAmount(GOVERNANCE_COMMITMENT_AMOUNT)); obj.pushKV("superblockcycle", Params().GetConsensus().nSuperblockCycle); obj.pushKV("superblockmaturitywindow", Params().GetConsensus().nSuperblockMaturityWindow); obj.pushKV("lastsuperblock", nLastSuperblock); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index bc6bc8f4b1a12e..370e4e861b135e 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3483,7 +3483,7 @@ bool CWallet::HasCollateralInputs(bool fOnlyConfirmed) const return !vCoins.empty(); } -bool CWallet::GetBudgetSystemCollateralTX(CTransactionRef& tx, uint256 hash, CAmount amount, const COutPoint& outpoint) +bool CWallet::CreateGovernanceCommitmentTransaction(CTransactionRef& tx, uint256 hash, CAmount amount, const COutPoint& outpoint) { CScript scriptChange; scriptChange << OP_RETURN << ToByteVector(hash); @@ -3501,7 +3501,7 @@ bool CWallet::GetBudgetSystemCollateralTX(CTransactionRef& tx, uint256 hash, CAm FeeCalculation fee_calc_out; bool success = CreateTransaction(vecSend, tx, nFeeRet, nChangePosRet, error, coinControl, fee_calc_out); if(!success){ - WalletLogPrintf("CWallet::GetBudgetSystemCollateralTX -- Error: %s\n", error.original); + WalletLogPrintf("CWallet::%s -- Error: %s\n", __func__, error.original); return false; } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 4487aa17b95dc8..def324b7376613 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1119,7 +1119,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati float GetAverageAnonymizedRounds() const; CAmount GetNormalizedAnonymizedBalance() const; - bool GetBudgetSystemCollateralTX(CTransactionRef& tx, uint256 hash, CAmount amount, const COutPoint& outpoint=COutPoint()/*defaults null*/); + bool CreateGovernanceCommitmentTransaction(CTransactionRef& tx, uint256 hash, CAmount amount, const COutPoint& outpoint=COutPoint()/*defaults null*/); CAmount GetAvailableBalance(const CCoinControl* coinControl = nullptr) const; /** diff --git a/test/functional/feature_governance.py b/test/functional/feature_governance.py index 9cc92277023aa2..ea350b57c5cd02 100755 --- a/test/functional/feature_governance.py +++ b/test/functional/feature_governance.py @@ -92,7 +92,7 @@ def have_trigger_for_height(self, sb_block_height): def run_test(self): governance_info = self.nodes[0].getgovernanceinfo() assert_equal(governance_info['governanceminquorum'], 1) - assert_equal(governance_info['proposalfee'], 1) + assert_equal(governance_info['commitmentamount'], 1) assert_equal(governance_info['superblockcycle'], 20) assert_equal(governance_info['superblockmaturitywindow'], 10) assert_equal(governance_info['lastsuperblock'], 120) diff --git a/test/functional/feature_governance_cl.py b/test/functional/feature_governance_cl.py index 2e1f9c31e0d71f..dceb2471a2bb30 100755 --- a/test/functional/feature_governance_cl.py +++ b/test/functional/feature_governance_cl.py @@ -27,10 +27,10 @@ def prepare_object(self, object_type, parent_hash, creation_time, revision, name "url": "https://dash.org" } proposal_hex = ''.join(format(x, '02x') for x in json.dumps(proposal_template).encode()) - collateral_hash = self.nodes[0].gobject("prepare", parent_hash, proposal_rev, proposal_time, proposal_hex) + commitment_hash = self.nodes[0].gobject("prepare", parent_hash, proposal_rev, proposal_time, proposal_hex) return { "parentHash": parent_hash, - "collateralHash": collateral_hash, + "commitmentHash": commitment_hash, "createdAt": proposal_time, "revision": proposal_rev, "hex": proposal_hex, @@ -83,8 +83,8 @@ def run_test(self): self.p0_amount = satoshi_round("1.1") self.p1_amount = satoshi_round("3.3") - p0_collateral_prepare = self.prepare_object(1, uint256_to_string(0), proposal_time, 1, "Proposal_0", self.p0_amount, self.p0_payout_address) - p1_collateral_prepare = self.prepare_object(1, uint256_to_string(0), proposal_time, 1, "Proposal_1", self.p1_amount, self.p1_payout_address) + p0_prepare = self.prepare_object(1, uint256_to_string(0), proposal_time, 1, "Proposal_0", self.p0_amount, self.p0_payout_address) + p1_prepare = self.prepare_object(1, uint256_to_string(0), proposal_time, 1, "Proposal_1", self.p1_amount, self.p1_payout_address) self.bump_mocktime(60 * 10 + 1) self.nodes[0].generate(6) @@ -94,8 +94,8 @@ def run_test(self): assert_equal(len(self.nodes[0].gobject("list-prepared")), 2) assert_equal(len(self.nodes[0].gobject("list")), 0) - self.p0_hash = self.nodes[0].gobject("submit", "0", 1, proposal_time, p0_collateral_prepare["hex"], p0_collateral_prepare["collateralHash"]) - self.p1_hash = self.nodes[0].gobject("submit", "0", 1, proposal_time, p1_collateral_prepare["hex"], p1_collateral_prepare["collateralHash"]) + self.p0_hash = self.nodes[0].gobject("submit", "0", 1, proposal_time, p0_prepare["hex"], p0_prepare["commitmentHash"]) + self.p1_hash = self.nodes[0].gobject("submit", "0", 1, proposal_time, p1_prepare["hex"], p1_prepare["commitmentHash"]) assert_equal(len(self.nodes[0].gobject("list")), 2) diff --git a/test/functional/feature_governance_objects.py b/test/functional/feature_governance_objects.py index 5dae7e0bebd0b5..34ef907258e7da 100755 --- a/test/functional/feature_governance_objects.py +++ b/test/functional/feature_governance_objects.py @@ -14,7 +14,7 @@ def validate_object(prepared, rpc_prepared): assert_equal(prepared["parentHash"], rpc_prepared["parentHash"]) - assert_equal(prepared["collateralHash"], rpc_prepared["collateralHash"]) + assert_equal(prepared["commitmentHash"], rpc_prepared["commitmentHash"]) assert_equal(prepared["createdAt"], rpc_prepared["createdAt"]) assert_equal(prepared["revision"], rpc_prepared["revision"]) assert_equal(prepared["hex"], rpc_prepared["data"]["hex"]) @@ -39,10 +39,10 @@ def prepare_object(self, object_type, parent_hash, creation_time, revision, name "url": "https://dash.org" } proposal_hex = ''.join(format(x, '02x') for x in json.dumps(proposal_template).encode()) - collateral_hash = self.nodes[0].gobject("prepare", parent_hash, proposal_rev, proposal_time, proposal_hex) + commitment_hash = self.nodes[0].gobject("prepare", parent_hash, proposal_rev, proposal_time, proposal_hex) return { "parentHash": parent_hash, - "collateralHash": collateral_hash, + "commitmentHash": commitment_hash, "createdAt": proposal_time, "revision": proposal_rev, "hex": proposal_hex, diff --git a/test/functional/interface_zmq_dash.py b/test/functional/interface_zmq_dash.py index ee8931d3406485..f389c590e2fc47 100755 --- a/test/functional/interface_zmq_dash.py +++ b/test/functional/interface_zmq_dash.py @@ -374,11 +374,11 @@ def test_governance_publishers(self): "url": "https://dash.org" } proposal_hex = ''.join(format(x, '02x') for x in json.dumps(proposal_data).encode()) - collateral = self.nodes[0].gobject("prepare", "0", proposal_rev, proposal_time, proposal_hex) - self.wait_for_instantlock(collateral, self.nodes[0]) + commitment_hash = self.nodes[0].gobject("prepare", "0", proposal_rev, proposal_time, proposal_hex) + self.wait_for_instantlock(commitment_hash, self.nodes[0]) self.nodes[0].generate(6) self.sync_blocks() - rpc_proposal_hash = self.nodes[0].gobject("submit", "0", proposal_rev, proposal_time, proposal_hex, collateral) + rpc_proposal_hash = self.nodes[0].gobject("submit", "0", proposal_rev, proposal_time, proposal_hex, commitment_hash) # Validate hashgovernanceobject zmq_governance_object_hash = self.subscribers[ZMQPublisher.hash_governance_object].receive().read(32).hex() assert_equal(zmq_governance_object_hash, rpc_proposal_hash) diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index b98616df86aca6..a7d282c623fead 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -1355,14 +1355,14 @@ def __repr__(self): repr(self.validMembers), self.quorumPublicKey.hex(), self.quorumVvecHash, self.quorumSig.hex(), self.membersSig.hex()) class CGovernanceObject: - __slots__ = ("nHashParent", "nRevision", "nTime", "nCollateralHash", "vchData", "nObjectType", + __slots__ = ("nHashParent", "nRevision", "nTime", "m_commitment_hash", "vchData", "nObjectType", "masternodeOutpoint", "vchSig") def __init__(self): self.nHashParent = 0 self.nRevision = 0 self.nTime = 0 - self.nCollateralHash = 0 + self.m_commitment_hash = 0 self.vchData = [] self.nObjectType = 0 self.masternodeOutpoint = COutPoint() @@ -1372,7 +1372,7 @@ def deserialize(self, f): self.nHashParent = deser_uint256(f) self.nRevision = struct.unpack(" 0: self.vchData = f.read(size) @@ -1387,7 +1387,7 @@ def serialize(self): r += ser_uint256(self.nParentHash) r += struct.pack("