diff --git a/src/governance/common.cpp b/src/governance/common.cpp index 81d1b3f1c0c76..185800edd38cf 100644 --- a/src/governance/common.cpp +++ b/src/governance/common.cpp @@ -12,11 +12,12 @@ 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 +47,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 ae053d850413a..be76b5928b87c 100644 --- a/src/governance/common.h +++ b/src/governance/common.h @@ -34,7 +34,8 @@ 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 +56,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; @@ -67,15 +68,8 @@ class Object SERIALIZE_METHODS(Object, obj) { - READWRITE( - obj.hashParent, - obj.revision, - obj.time, - obj.collateralHash, - obj.vchData, - obj.type, - obj.masternodeOutpoint - ); + READWRITE(obj.hashParent, obj.revision, obj.time, obj.m_commitment_hash, obj.vchData, obj.type, + obj.masternodeOutpoint); if (!(s.GetType() & SER_GETHASH)) { READWRITE(obj.vchSig); } diff --git a/src/governance/governance.cpp b/src/governance/governance.cpp index 00a130e7d1d48..97e96a12d0d46 100644 --- a/src/governance/governance.cpp +++ b/src/governance/governance.cpp @@ -565,7 +565,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())); } }; @@ -684,7 +684,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) @@ -1177,7 +1177,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 a41fb48d00c61..2c3468d315fb4 100644 --- a/src/governance/object.cpp +++ b/src/governance/object.cpp @@ -29,9 +29,9 @@ CGovernanceObject::CGovernanceObject() } CGovernanceObject::CGovernanceObject(const uint256& nHashParentIn, int nRevisionIn, int64_t nTimeIn, - const uint256& nCollateralHashIn, const std::string& strDataHexIn) : + const uint256& commitment_hash, const std::string& strDataHexIn) : cs(), - m_obj{nHashParentIn, nRevisionIn, nTimeIn, nCollateralHashIn, strDataHexIn} + m_obj{nHashParentIn, nRevisionIn, nTimeIn, commitment_hash, strDataHexIn} { // PARSE JSON DATA STORAGE (VCHDATA) LoadData(); @@ -375,19 +375,21 @@ 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); @@ -408,14 +410,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; } @@ -442,12 +444,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; @@ -458,7 +460,8 @@ 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); @@ -468,22 +471,23 @@ 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; } @@ -492,28 +496,29 @@ 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, /* Continued */ + "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; } @@ -528,15 +533,17 @@ 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 826823a33bedc..40f243f10a9ce 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,8 @@ 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,10 +169,7 @@ class CGovernanceObject return m_obj.type; } - const uint256& GetCollateralHash() const - { - return m_obj.collateralHash; - } + const uint256& GetCommitmentHash() const { return m_obj.m_commitment_hash; } const COutPoint& GetMasternodeOutpoint() const { @@ -228,12 +226,15 @@ 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 +248,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 46b6f643171a0..ac1eeb3ec4395 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 bdee7e77402af..d19e25cc8f373 100644 --- a/src/rpc/governance.cpp +++ b/src/rpc/governance.cpp @@ -122,19 +122,19 @@ 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", - "Prepare governance object by signing and creating tx\n" - + HELP_REQUIRING_PASSPHRASE, + return RPCHelpMan{ + "gobject prepare", + "Prepare governance object by signing and creating tx\n" + HELP_REQUIRING_PASSPHRASE, { {"parent-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "hash of the parent object, \"0\" is root"}, {"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"}, {"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 ------ @@ -287,14 +287,15 @@ static RPCHelpMan gobject_list_prepared() */ static RPCHelpMan gobject_submit() { - return RPCHelpMan{"gobject submit", + return RPCHelpMan{ + "gobject submit", "Submit governance object to network\n", { {"parent-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "hash of the parent object, \"0\" is root"}, {"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 +328,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 +346,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 +656,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 +774,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 +1015,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 +1043,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 14ba64998d6ac..8bc55d20834d9 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3488,7 +3488,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); @@ -3506,7 +3506,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 194d734061595..b7220579e4b5c 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1120,7 +1120,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 0a38ac1eaa93a..48217c0af1812 100755 --- a/test/functional/feature_governance.py +++ b/test/functional/feature_governance.py @@ -56,7 +56,7 @@ def run_test(self): self.log.info("Start testing...") 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) @@ -113,9 +113,9 @@ def run_test(self): self.p1_amount = satoshi_round("3.3") self.p2_amount = self.expected_v20_budget - self.p1_amount - p0_collateral_prepare = prepare_object(self.nodes[0], 1, uint256_to_string(0), proposal_time, 1, "Proposal_0", self.p0_amount, self.p0_payout_address) - p1_collateral_prepare = prepare_object(self.nodes[0], 1, uint256_to_string(0), proposal_time, 1, "Proposal_1", self.p1_amount, self.p1_payout_address) - p2_collateral_prepare = prepare_object(self.nodes[0], 1, uint256_to_string(0), proposal_time, 1, "Proposal_2", self.p2_amount, self.p2_payout_address) + p0_prepare = prepare_object(self.nodes[0], 1, uint256_to_string(0), proposal_time, 1, "Proposal_0", self.p0_amount, self.p0_payout_address) + p1_prepare = prepare_object(self.nodes[0], 1, uint256_to_string(0), proposal_time, 1, "Proposal_1", self.p1_amount, self.p1_payout_address) + p2_prepare = prepare_object(self.nodes[0], 1, uint256_to_string(0), proposal_time, 1, "Proposal_2", self.p2_amount, self.p2_payout_address) self.nodes[0].generate(6) self.bump_mocktime(6) @@ -124,9 +124,9 @@ def run_test(self): assert_equal(len(self.nodes[0].gobject("list-prepared")), 3) 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.p2_hash = self.nodes[0].gobject("submit", "0", 1, proposal_time, p2_collateral_prepare["hex"], p2_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"]) + self.p2_hash = self.nodes[0].gobject("submit", "0", 1, proposal_time, p2_prepare["hex"], p2_prepare["commitmentHash"]) assert_equal(len(self.nodes[0].gobject("list")), 3) diff --git a/test/functional/feature_governance_cl.py b/test/functional/feature_governance_cl.py index 99bdf3dfdd864..d8cc937785ee1 100755 --- a/test/functional/feature_governance_cl.py +++ b/test/functional/feature_governance_cl.py @@ -29,10 +29,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, @@ -80,8 +80,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) @@ -93,8 +93,8 @@ def run_test(self): self.log.info("Submit proposals") - 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 612123c6e37b1..4b0448030fa30 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"]) diff --git a/test/functional/interface_zmq_dash.py b/test/functional/interface_zmq_dash.py index c0366d27ef76c..129aae132884b 100755 --- a/test/functional/interface_zmq_dash.py +++ b/test/functional/interface_zmq_dash.py @@ -373,11 +373,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/governance.py b/test/functional/test_framework/governance.py index 2132fb3a27e29..c39a31edfc611 100644 --- a/test/functional/test_framework/governance.py +++ b/test/functional/test_framework/governance.py @@ -19,10 +19,10 @@ def prepare_object(node, 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 = node.gobject("prepare", parent_hash, proposal_rev, proposal_time, proposal_hex) + commitment_hash = node.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/test_framework/messages.py b/test/functional/test_framework/messages.py index 0804b87873054..7f72c13277d7e 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("