diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index f58ef238004d..c171ba137e00 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -192,7 +192,7 @@ CDeterministicMNCPtr CDeterministicMNList::GetMNPayee(const CBlockIndex* pIndex) if (dmn->pdmnState->nLastPaidHeight == nHeight) { // We found the last MN Payee. // If the last payee is a HPMN, we need to check its consecutive payments and pay him again if needed - if (dmn->nType == MnType::HighPerformance.index && dmn->pdmnState->nConsecutivePayments < MnType::HighPerformance.voting_weight) { + if (dmn->nType == MnType::HighPerformance && dmn->pdmnState->nConsecutivePayments < dmn_types::HighPerformance.voting_weight) { best = dmn; } } @@ -268,7 +268,7 @@ std::vector> CDeterministicMNList return; } if (onlyHighPerformanceMasternodes) { - if (dmn->nType != MnType::HighPerformance.index) + if (dmn->nType != MnType::HighPerformance) return; } // calculate sha256(sha256(proTxHash, confirmedHash), modifier) per MN @@ -471,7 +471,7 @@ void CDeterministicMNList::AddMN(const CDeterministicMNCPtr& dmn, bool fBumpTota dmn->proTxHash.ToString(), dmn->pdmnState->pubKeyOperator.Get().ToString()))); } - if (dmn->nType == MnType::HighPerformance.index) { + if (dmn->nType == MnType::HighPerformance) { if (!AddUniqueProperty(*dmn, dmn->pdmnState->platformNodeID)) { mnUniquePropertyMap = mnUniquePropertyMapSaved; throw(std::runtime_error(strprintf("%s: Can't add a masternode %s with a duplicate platformNodeID=%s", __func__, @@ -512,7 +512,7 @@ void CDeterministicMNList::UpdateMN(const CDeterministicMN& oldDmn, const std::s throw(std::runtime_error(strprintf("%s: Can't update a masternode %s with a duplicate pubKeyOperator=%s", __func__, oldDmn.proTxHash.ToString(), pdmnState->pubKeyOperator.Get().ToString()))); } - if (dmn->nType == MnType::HighPerformance.index) { + if (dmn->nType == MnType::HighPerformance) { if (!UpdateUniqueProperty(*dmn, oldState->platformNodeID, dmn->pdmnState->platformNodeID)) { mnUniquePropertyMap = mnUniquePropertyMapSaved; throw(std::runtime_error(strprintf("%s: Can't update a masternode %s with a duplicate platformNodeID=%s", __func__, @@ -572,7 +572,7 @@ void CDeterministicMNList::RemoveMN(const uint256& proTxHash) proTxHash.ToString(), dmn->pdmnState->pubKeyOperator.Get().ToString()))); } - if (dmn->nType == MnType::HighPerformance.index) { + if (dmn->nType == MnType::HighPerformance) { if (!DeleteUniqueProperty(*dmn, dmn->pdmnState->platformNodeID)) { mnUniquePropertyMap = mnUniquePropertyMapSaved; throw(std::runtime_error(strprintf("%s: Can't delete a masternode %s with a duplicate platformNodeID=%s", __func__, @@ -745,11 +745,11 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C return _state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-protx-payload"); } - if (proTx.nType == MnType::HighPerformance.index && !llmq::utils::IsV19Active(pindexPrev)) { + if (proTx.nType == MnType::HighPerformance && !llmq::utils::IsV19Active(pindexPrev)) { return _state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-protx-payload"); } - auto dmn = std::make_shared(newList.GetTotalRegisteredCount(), proTx.nType == MnType::HighPerformance.index); + auto dmn = std::make_shared(newList.GetTotalRegisteredCount(), proTx.nType); dmn->proTxHash = tx.GetHash(); // collateralOutpoint is either pointing to an external collateral or to the ProRegTx itself @@ -808,7 +808,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C return _state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-protx-payload"); } - if (proTx.nType == MnType::HighPerformance.index && !llmq::utils::IsV19Active(pindexPrev)) { + if (proTx.nType == MnType::HighPerformance && !llmq::utils::IsV19Active(pindexPrev)) { return _state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-protx-payload"); } @@ -820,17 +820,17 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C if (!dmn) { return _state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-protx-hash"); } - if (proTx.nType == MnType::HighPerformance.index && dmn->nType != MnType::HighPerformance.index) { - return _state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-protx-type"); + if (proTx.nType != dmn->nType) { + return _state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-protx-type-mismatch"); } - if (proTx.nType == MnType::Regular.index && dmn->nType != MnType::Regular.index) { + if (proTx.nType != MnType::Regular && proTx.nType != MnType::HighPerformance) { return _state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-protx-type"); } auto newState = std::make_shared(*dmn->pdmnState); newState->addr = proTx.addr; newState->scriptOperatorPayout = proTx.scriptOperatorPayout; - if (proTx.nType == MnType::HighPerformance.index) { + if (proTx.nType == MnType::HighPerformance) { newState->platformNodeID = proTx.platformNodeID; newState->platformP2PPort = proTx.platformP2PPort; newState->platformHTTPPort = proTx.platformHTTPPort; @@ -946,7 +946,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C // No need to check if v19 is active, since HPMN ProRegTx are allowed only after v19 activation // TODO: Skip this code once v20 is active // Note: If the payee wasn't found in the current block that's fine - if (dmn->nType == MnType::HighPerformance.index) { + if (dmn->nType == MnType::HighPerformance) { ++newState->nConsecutivePayments; if (debugLogs) { LogPrintf("CDeterministicMNManager::%s -- MN %s is a HPMN, bumping nConsecutivePayments to %d\n", @@ -965,7 +965,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C auto newList2 = newList; newList2.ForEachMN(false, [&](auto& dmn) { if (payee != nullptr && dmn.proTxHash == payee->proTxHash) return; - if (dmn.nType != MnType::HighPerformance.index) return; + if (dmn.nType != MnType::HighPerformance) return; if (dmn.pdmnState->nConsecutivePayments == 0) return; if (debugLogs) { LogPrintf("CDeterministicMNManager::%s -- MN %s, reset nConsecutivePayments %d->0\n", @@ -1399,7 +1399,7 @@ bool CheckProRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValid return false; } - if (ptx.nType == MnType::HighPerformance.index) { + if (ptx.nType == MnType::HighPerformance) { if (!CheckPlatformFields(ptx, state)) { return false; } @@ -1510,7 +1510,7 @@ bool CheckProUpServTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CVa return false; } - if (ptx.nType == MnType::HighPerformance.index) { + if (ptx.nType == MnType::HighPerformance) { if (!CheckPlatformFields(ptx, state)) { return false; } diff --git a/src/evo/deterministicmns.h b/src/evo/deterministicmns.h index 701a07fa3e03..357605a8f979 100644 --- a/src/evo/deterministicmns.h +++ b/src/evo/deterministicmns.h @@ -45,9 +45,9 @@ class CDeterministicMN static constexpr uint16_t MN_TYPE_FORMAT = 1; CDeterministicMN() = delete; // no default constructor, must specify internalId - explicit CDeterministicMN(uint64_t _internalId, bool highPerformanceMasternode = false) : + explicit CDeterministicMN(uint64_t _internalId, MnType mnType = MnType::Regular) : internalId(_internalId), - nType(highPerformanceMasternode ? MnType::HighPerformance.index : MnType::Regular.index) + nType(mnType) { // only non-initial values assert(_internalId != std::numeric_limits::max()); @@ -62,7 +62,7 @@ class CDeterministicMN uint256 proTxHash; COutPoint collateralOutpoint; uint16_t nOperatorReward{0}; - uint16_t nType{MnType::Regular.index}; + MnType nType{MnType::Regular}; std::shared_ptr pdmnState; template @@ -89,7 +89,7 @@ class CDeterministicMN if (format_version >= MN_TYPE_FORMAT && (s.GetVersion() == CLIENT_VERSION || s.GetVersion() >= DMN_TYPE_PROTO_VERSION)) { READWRITE(nType); } else { - nType = MnType::Regular.index; + nType = MnType::Regular; } } @@ -227,7 +227,7 @@ class CDeterministicMNList [[nodiscard]] size_t GetAllHPMNsCount() const { - return ranges::count_if(mnMap, [](const auto& p) { return p.second->nType == MnType::HighPerformance.index; }); + return ranges::count_if(mnMap, [](const auto& p) { return p.second->nType == MnType::HighPerformance; }); } /** diff --git a/src/evo/dmn_types.h b/src/evo/dmn_types.h index b69cb9ced323..d16e8f9d3803 100644 --- a/src/evo/dmn_types.h +++ b/src/evo/dmn_types.h @@ -6,39 +6,52 @@ #define BITCOIN_EVO_DMN_TYPES_H #include +#include + #include #include -class CDeterministicMNType +enum class MnType : uint16_t { + Regular = 0, + HighPerformance = 1, +}; + +template<> struct is_serializable_enum : std::true_type {}; + +namespace dmn_types { + +struct mntype_struct { -public: - uint8_t index; - int32_t voting_weight; - CAmount collat_amount; - std::string_view description; + const int32_t voting_weight; + const CAmount collat_amount; + const std::string_view description; }; -namespace MnType { -constexpr auto Regular = CDeterministicMNType{ - .index = 0, +constexpr auto Regular = mntype_struct{ .voting_weight = 1, .collat_amount = 1000 * COIN, .description = "Regular", }; -constexpr auto HighPerformance = CDeterministicMNType{ - .index = 1, +constexpr auto HighPerformance = mntype_struct{ .voting_weight = 4, .collat_amount = 4000 * COIN, .description = "HighPerformance", }; -} // namespace MnType -constexpr const auto& GetMnType(int index) +[[nodiscard]] static constexpr bool IsCollateralAmount(CAmount amount) +{ + return amount == Regular.collat_amount || + amount == HighPerformance.collat_amount; +} + +} // namespace dmn_types + +[[nodiscard]] constexpr const dmn_types::mntype_struct GetMnType(MnType type) { - switch (index) { - case 0: return MnType::Regular; - case 1: return MnType::HighPerformance; - default: assert(false); + switch (type) { + case MnType::Regular: return dmn_types::Regular; + case MnType::HighPerformance: return dmn_types::HighPerformance; + default: assert(false); } } diff --git a/src/evo/providertx.cpp b/src/evo/providertx.cpp index 4d1139f9a2ab..ed62a142590d 100644 --- a/src/evo/providertx.cpp +++ b/src/evo/providertx.cpp @@ -15,7 +15,7 @@ maybe_error CProRegTx::IsTriviallyValid(bool is_bls_legacy_scheme) const if (nVersion == 0 || nVersion > GetVersion(is_bls_legacy_scheme)) { return {ValidationInvalidReason::CONSENSUS, "bad-protx-version"}; } - if (nType != MnType::Regular.index && nType != MnType::HighPerformance.index) { + if (nType != MnType::Regular && nType != MnType::HighPerformance) { return {ValidationInvalidReason::CONSENSUS, "bad-protx-type"}; } if (nMode != 0) { @@ -80,7 +80,7 @@ std::string CProRegTx::ToString() const } return strprintf("CProRegTx(nVersion=%d, nType=%d, collateralOutpoint=%s, addr=%s, nOperatorReward=%f, ownerAddress=%s, pubKeyOperator=%s, votingAddress=%s, scriptPayout=%s, platformNodeID=%s, platformP2PPort=%d, platformHTTPPort=%d)", - nVersion, nType, collateralOutpoint.ToStringShort(), addr.ToString(), (double)nOperatorReward / 100, EncodeDestination(PKHash(keyIDOwner)), pubKeyOperator.ToString(nVersion == LEGACY_BLS_VERSION), EncodeDestination(PKHash(keyIDVoting)), payee, platformNodeID.ToString(), platformP2PPort, platformHTTPPort); + nVersion, static_cast(nType), collateralOutpoint.ToStringShort(), addr.ToString(), (double)nOperatorReward / 100, EncodeDestination(PKHash(keyIDOwner)), pubKeyOperator.ToString(nVersion == LEGACY_BLS_VERSION), EncodeDestination(PKHash(keyIDVoting)), payee, platformNodeID.ToString(), platformP2PPort, platformHTTPPort); } maybe_error CProUpServTx::IsTriviallyValid(bool is_bls_legacy_scheme) const @@ -101,7 +101,7 @@ std::string CProUpServTx::ToString() const } return strprintf("CProUpServTx(nVersion=%d, nType=%d, proTxHash=%s, addr=%s, operatorPayoutAddress=%s, platformNodeID=%s, platformP2PPort=%d, platformHTTPPort=%d)", - nVersion, nType, proTxHash.ToString(), addr.ToString(), payee, platformNodeID.ToString(), platformP2PPort, platformHTTPPort); + nVersion, static_cast(nType), proTxHash.ToString(), addr.ToString(), payee, platformNodeID.ToString(), platformP2PPort, platformHTTPPort); } maybe_error CProUpRegTx::IsTriviallyValid(bool is_bls_legacy_scheme) const diff --git a/src/evo/providertx.h b/src/evo/providertx.h index 341ac1a12ce3..a202d711107b 100644 --- a/src/evo/providertx.h +++ b/src/evo/providertx.h @@ -34,7 +34,7 @@ class CProRegTx } uint16_t nVersion{LEGACY_BLS_VERSION}; // message version - uint16_t nType{MnType::Regular.index}; + MnType nType{MnType::Regular}; uint16_t nMode{0}; // only 0 supported for now COutPoint collateralOutpoint{uint256(), (uint32_t)-1}; // if hash is null, we refer to a ProRegTx output CService addr; @@ -70,7 +70,7 @@ class CProRegTx obj.scriptPayout, obj.inputsHash ); - if (obj.nVersion == BASIC_BLS_VERSION && obj.nType == MnType::HighPerformance.index) { + if (obj.nVersion == BASIC_BLS_VERSION && obj.nType == MnType::HighPerformance) { READWRITE( obj.platformNodeID, obj.platformP2PPort, @@ -92,7 +92,7 @@ class CProRegTx obj.clear(); obj.setObject(); obj.pushKV("version", nVersion); - obj.pushKV("type", nType); + obj.pushKV("type", static_cast(nType)); obj.pushKV("collateralHash", collateralOutpoint.hash.ToString()); obj.pushKV("collateralIndex", (int)collateralOutpoint.n); obj.pushKV("service", addr.ToString(false)); @@ -105,7 +105,7 @@ class CProRegTx } obj.pushKV("pubKeyOperator", pubKeyOperator.ToString(nVersion == LEGACY_BLS_VERSION)); obj.pushKV("operatorReward", (double)nOperatorReward / 100); - if (nType == MnType::HighPerformance.index) { + if (nType == MnType::HighPerformance) { obj.pushKV("platformNodeID", platformNodeID.ToString()); obj.pushKV("platformP2PPort", platformP2PPort); obj.pushKV("platformHTTPPort", platformHTTPPort); @@ -129,7 +129,7 @@ class CProUpServTx } uint16_t nVersion{LEGACY_BLS_VERSION}; // message version - uint16_t nType{MnType::Regular.index}; + MnType nType{MnType::Regular}; uint256 proTxHash; CService addr; uint160 platformNodeID{}; @@ -158,7 +158,7 @@ class CProUpServTx obj.scriptOperatorPayout, obj.inputsHash ); - if (obj.nVersion == BASIC_BLS_VERSION && obj.nType == MnType::HighPerformance.index) { + if (obj.nVersion == BASIC_BLS_VERSION && obj.nType == MnType::HighPerformance) { READWRITE( obj.platformNodeID, obj.platformP2PPort, @@ -178,14 +178,14 @@ class CProUpServTx obj.clear(); obj.setObject(); obj.pushKV("version", nVersion); - obj.pushKV("type", nType); + obj.pushKV("type", static_cast(nType)); obj.pushKV("proTxHash", proTxHash.ToString()); obj.pushKV("service", addr.ToString(false)); CTxDestination dest; if (ExtractDestination(scriptOperatorPayout, dest)) { obj.pushKV("operatorPayoutAddress", EncodeDestination(dest)); } - if (nType == MnType::HighPerformance.index) { + if (nType == MnType::HighPerformance) { obj.pushKV("platformNodeID", platformNodeID.ToString()); obj.pushKV("platformP2PPort", platformP2PPort); obj.pushKV("platformHTTPPort", platformHTTPPort); diff --git a/src/evo/simplifiedmns.cpp b/src/evo/simplifiedmns.cpp index 97447ef7365d..a90cf9776efa 100644 --- a/src/evo/simplifiedmns.cpp +++ b/src/evo/simplifiedmns.cpp @@ -57,7 +57,7 @@ std::string CSimplifiedMNListEntry::ToString() const } return strprintf("CSimplifiedMNListEntry(nType=%d, proRegTxHash=%s, confirmedHash=%s, service=%s, pubKeyOperator=%s, votingAddress=%s, isValid=%d, payoutAddress=%s, operatorPayoutAddress=%s, platformHTTPPort=%d, platformNodeID=%s)", - nType, proRegTxHash.ToString(), confirmedHash.ToString(), service.ToString(false), pubKeyOperator.Get().ToString(), EncodeDestination(PKHash(keyIDVoting)), isValid, payoutAddress, operatorPayoutAddress, platformHTTPPort, platformNodeID.ToString()); + static_cast(nType), proRegTxHash.ToString(), confirmedHash.ToString(), service.ToString(false), pubKeyOperator.Get().ToString(), EncodeDestination(PKHash(keyIDVoting)), isValid, payoutAddress, operatorPayoutAddress, platformHTTPPort, platformNodeID.ToString()); } void CSimplifiedMNListEntry::ToJson(UniValue& obj, bool extended) const @@ -71,8 +71,8 @@ void CSimplifiedMNListEntry::ToJson(UniValue& obj, bool extended) const obj.pushKV("votingAddress", EncodeDestination(PKHash(keyIDVoting))); obj.pushKV("isValid", isValid); obj.pushKV("nVersion", nVersion); - obj.pushKV("nType", nType); - if (nType == MnType::HighPerformance.index) { + obj.pushKV("nType", static_cast(nType)); + if (nType == MnType::HighPerformance) { obj.pushKV("platformHTTPPort", platformHTTPPort); obj.pushKV("platformNodeID", platformNodeID.ToString()); } diff --git a/src/evo/simplifiedmns.h b/src/evo/simplifiedmns.h index 9cb9718932ab..dd3882ca41a7 100644 --- a/src/evo/simplifiedmns.h +++ b/src/evo/simplifiedmns.h @@ -34,7 +34,7 @@ class CSimplifiedMNListEntry CBLSLazyPublicKey pubKeyOperator; CKeyID keyIDVoting; bool isValid{false}; - uint16_t nType{MnType::Regular.index}; + MnType nType{MnType::Regular}; uint16_t platformHTTPPort{0}; uint160 platformNodeID{}; CScript scriptPayout; // mem-only @@ -75,7 +75,7 @@ class CSimplifiedMNListEntry ); if (obj.nVersion == BASIC_BLS_VERSION) { READWRITE(obj.nType); - if (obj.nType == MnType::HighPerformance.index) { + if (obj.nType == MnType::HighPerformance) { READWRITE(obj.platformHTTPPort); READWRITE(obj.platformNodeID); } diff --git a/src/rpc/evo.cpp b/src/rpc/evo.cpp index 77831e7273db..a93d08a9e63e 100644 --- a/src/rpc/evo.cpp +++ b/src/rpc/evo.cpp @@ -557,8 +557,9 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request, const bool isExternalRegister, const bool isFundRegister, const bool isPrepareRegister, - const bool isHPMNrequested) + const MnType mnType) { + const bool isHPMNrequested = mnType == MnType::HighPerformance; if (isHPMNrequested) { if (isFundRegister && (request.fHelp || (request.params.size() < 10 || request.params.size() > 12))) { protx_register_fund_hpmn_help(request); @@ -585,7 +586,7 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request, } bool isV19active = llmq::utils::IsV19Active(WITH_LOCK(cs_main, return ::ChainActive().Tip();)); - if (isHPMNrequested && !isV19active) { + if (mnType == MnType::HighPerformance && !isV19active) { throw JSONRPCError(RPC_INVALID_REQUEST, "HPMN aren't allowed yet"); } @@ -601,8 +602,7 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request, } else { ptx.nVersion = CProRegTx::GetVersion(isV19active); } - auto mn_type = isHPMNrequested ? MnType::HighPerformance : MnType::Regular; - ptx.nType = mn_type.index; + ptx.nType = mnType; if (isFundRegister) { CTxDestination collateralDest = DecodeDestination(request.params[paramIdx].get_str()); @@ -611,7 +611,7 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request, } CScript collateralScript = GetScriptForDestination(collateralDest); - CAmount fundCollateral = mn_type.collat_amount; + CAmount fundCollateral = GetMnType(mnType).collat_amount; CTxOut collateralTxOut(fundCollateral, collateralScript); tx.vout.emplace_back(collateralTxOut); @@ -705,7 +705,7 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request, } if (isFundRegister) { - CAmount fundCollateral = mn_type.collat_amount; + CAmount fundCollateral = GetMnType(mnType).collat_amount; uint32_t collateralIndex = (uint32_t) -1; for (uint32_t i = 0; i < tx.vout.size(); i++) { if (tx.vout[i].nValue == fundCollateral) { @@ -765,7 +765,7 @@ static UniValue protx_register_hpmn(const JSONRPCRequest& request) bool isExternalRegister = request.strMethod == "protxregister_hpmn"; bool isFundRegister = request.strMethod == "protxregister_fund_hpmn"; bool isPrepareRegister = request.strMethod == "protxregister_prepare_hpmn"; - return protx_register_common_wrapper(request, false, isExternalRegister, isFundRegister, isPrepareRegister, true); + return protx_register_common_wrapper(request, false, isExternalRegister, isFundRegister, isPrepareRegister, MnType::HighPerformance); } static UniValue protx_register(const JSONRPCRequest& request) @@ -773,7 +773,7 @@ static UniValue protx_register(const JSONRPCRequest& request) bool isExternalRegister = request.strMethod == "protxregister"; bool isFundRegister = request.strMethod == "protxregister_fund"; bool isPrepareRegister = request.strMethod == "protxregister_prepare"; - return protx_register_common_wrapper(request, false, isExternalRegister, isFundRegister, isPrepareRegister, false); + return protx_register_common_wrapper(request, false, isExternalRegister, isFundRegister, isPrepareRegister, MnType::Regular); } static UniValue protx_register_legacy(const JSONRPCRequest& request) @@ -781,7 +781,7 @@ static UniValue protx_register_legacy(const JSONRPCRequest& request) bool isExternalRegister = request.strMethod == "protxregister_legacy"; bool isFundRegister = request.strMethod == "protxregister_fund_legacy"; bool isPrepareRegister = request.strMethod == "protxregister_prepare_legacy"; - return protx_register_common_wrapper(request, true, isExternalRegister, isFundRegister, isPrepareRegister, false); + return protx_register_common_wrapper(request, true, isExternalRegister, isFundRegister, isPrepareRegister, MnType::Regular); } static UniValue protx_register_submit(const JSONRPCRequest& request) @@ -862,8 +862,9 @@ static void protx_update_service_hpmn_help(const JSONRPCRequest& request) }.Check(request); } -static UniValue protx_update_service_common_wrapper(const JSONRPCRequest& request, const bool isHPMNrequested) +static UniValue protx_update_service_common_wrapper(const JSONRPCRequest& request, const MnType mnType) { + const bool isHPMNrequested = mnType == MnType::HighPerformance; if (isHPMNrequested) { protx_update_service_hpmn_help(request); } else { @@ -882,7 +883,7 @@ static UniValue protx_update_service_common_wrapper(const JSONRPCRequest& reques CProUpServTx ptx; ptx.nVersion = CProUpServTx::GetVersion(llmq::utils::IsV19Active(::ChainActive().Tip())); - ptx.nType = isHPMNrequested ? MnType::HighPerformance.index : MnType::Regular.index; + ptx.nType = mnType; ptx.proTxHash = ParseHashV(request.params[0], "proTxHash"); if (!Lookup(request.params[1].get_str().c_str(), ptx.addr, Params().GetDefaultPort(), false)) { @@ -917,10 +918,8 @@ static UniValue protx_update_service_common_wrapper(const JSONRPCRequest& reques if (!dmn) { throw std::runtime_error(strprintf("masternode with proTxHash %s not found", ptx.proTxHash.ToString())); } - if (isHPMNrequested && dmn->nType != MnType::HighPerformance.index) { - throw std::runtime_error(strprintf("masternode with proTxHash %s is not a HPMN", ptx.proTxHash.ToString())); - } else if (!isHPMNrequested && dmn->nType == MnType::HighPerformance.index) { - throw std::runtime_error(strprintf("masternode with proTxHash %s is a HPMN", ptx.proTxHash.ToString())); + if (dmn->nType != mnType) { + throw std::runtime_error(strprintf("masternode with proTxHash %s is not a %s", ptx.proTxHash.ToString(), GetMnType(mnType).description)); } if (keyOperator.GetPublicKey() != dmn->pdmnState->pubKeyOperator.Get()) { @@ -1505,9 +1504,9 @@ static UniValue protx(const JSONRPCRequest& request) } else if (command == "protxregister_submit") { return protx_register_submit(new_request); } else if (command == "protxupdate_service") { - return protx_update_service_common_wrapper(new_request, false); + return protx_update_service_common_wrapper(new_request, MnType::Regular); } else if (command == "protxupdate_service_hpmn") { - return protx_update_service_common_wrapper(new_request, true); + return protx_update_service_common_wrapper(new_request, MnType::HighPerformance); } else if (command == "protxupdate_registrar") { return protx_update_registrar(new_request); } else if (command == "protxupdate_registrar_legacy") { diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 365f26611252..7ce4515f1fe2 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -668,7 +668,7 @@ static UniValue masternodelist(const JSONRPCRequest& request) objMN.pushKV("payee", payeeStr); objMN.pushKV("status", dmnToStatus(dmn)); objMN.pushKV("type", std::string(GetMnType(dmn.nType).description)); - if (dmn.nType == MnType::HighPerformance.index) { + if (dmn.nType == MnType::HighPerformance) { objMN.pushKV("platformNodeID", dmn.pdmnState->platformNodeID.ToString()); objMN.pushKV("platformP2PPort", dmn.pdmnState->platformP2PPort); objMN.pushKV("platformHTTPPort", dmn.pdmnState->platformHTTPPort); diff --git a/src/test/block_reward_reallocation_tests.cpp b/src/test/block_reward_reallocation_tests.cpp index 0626ccbec412..8c457d79237e 100644 --- a/src/test/block_reward_reallocation_tests.cpp +++ b/src/test/block_reward_reallocation_tests.cpp @@ -132,7 +132,7 @@ static CMutableTransaction CreateProRegTx(const CTxMemPool& mempool, SimpleUTXOM CMutableTransaction tx; tx.nVersion = 3; tx.nType = TRANSACTION_PROVIDER_REGISTER; - FundTransaction(tx, utxos, scriptPayout, MnType::Regular.collat_amount); + FundTransaction(tx, utxos, scriptPayout, dmn_types::Regular.collat_amount); proTx.inputsHash = CalcTxInputsHash(CTransaction(tx)); SetTxPayload(tx, proTx); SignTransaction(mempool, tx, coinbaseKey); diff --git a/src/test/evo_deterministicmns_tests.cpp b/src/test/evo_deterministicmns_tests.cpp index 807028d73229..20528bc7875c 100644 --- a/src/test/evo_deterministicmns_tests.cpp +++ b/src/test/evo_deterministicmns_tests.cpp @@ -110,7 +110,7 @@ static CMutableTransaction CreateProRegTx(const CTxMemPool& mempool, SimpleUTXOM CMutableTransaction tx; tx.nVersion = 3; tx.nType = TRANSACTION_PROVIDER_REGISTER; - FundTransaction(tx, utxos, scriptPayout, MnType::Regular.collat_amount, coinbaseKey); + FundTransaction(tx, utxos, scriptPayout, dmn_types::Regular.collat_amount, coinbaseKey); proTx.inputsHash = CalcTxInputsHash(CTransaction(tx)); SetTxPayload(tx, proTx); SignTransaction(mempool, tx, coinbaseKey); @@ -468,7 +468,7 @@ void FuncTestMempoolReorg(TestChainSetup& setup) // Create a MN with an external collateral CMutableTransaction tx_collateral; - FundTransaction(tx_collateral, utxos, scriptCollateral, MnType::Regular.collat_amount, setup.coinbaseKey); + FundTransaction(tx_collateral, utxos, scriptCollateral, dmn_types::Regular.collat_amount, setup.coinbaseKey); SignTransaction(*(setup.m_node.mempool), tx_collateral, setup.coinbaseKey); auto block = std::make_shared(setup.CreateBlock({tx_collateral}, setup.coinbaseKey)); @@ -486,7 +486,7 @@ void FuncTestMempoolReorg(TestChainSetup& setup) payload.scriptPayout = scriptPayout; for (size_t i = 0; i < tx_collateral.vout.size(); ++i) { - if (tx_collateral.vout[i].nValue == MnType::Regular.collat_amount) { + if (tx_collateral.vout[i].nValue == dmn_types::Regular.collat_amount) { payload.collateralOutpoint = COutPoint(tx_collateral.GetHash(), i); break; } @@ -495,7 +495,7 @@ void FuncTestMempoolReorg(TestChainSetup& setup) CMutableTransaction tx_reg; tx_reg.nVersion = 3; tx_reg.nType = TRANSACTION_PROVIDER_REGISTER; - FundTransaction(tx_reg, utxos, scriptPayout, MnType::Regular.collat_amount, setup.coinbaseKey); + FundTransaction(tx_reg, utxos, scriptPayout, dmn_types::Regular.collat_amount, setup.coinbaseKey); payload.inputsHash = CalcTxInputsHash(CTransaction(tx_reg)); CMessageSigner::SignMessage(payload.MakeSignString(), payload.vchSig, collateralKey); SetTxPayload(tx_reg, payload); @@ -555,7 +555,7 @@ void FuncTestMempoolDualProregtx(TestChainSetup& setup) payload.scriptPayout = scriptPayout; for (size_t i = 0; i < tx_reg1.vout.size(); ++i) { - if (tx_reg1.vout[i].nValue == MnType::Regular.collat_amount) { + if (tx_reg1.vout[i].nValue == dmn_types::Regular.collat_amount) { payload.collateralOutpoint = COutPoint(tx_reg1.GetHash(), i); break; } @@ -564,7 +564,7 @@ void FuncTestMempoolDualProregtx(TestChainSetup& setup) CMutableTransaction tx_reg2; tx_reg2.nVersion = 3; tx_reg2.nType = TRANSACTION_PROVIDER_REGISTER; - FundTransaction(tx_reg2, utxos, scriptPayout, MnType::Regular.collat_amount, setup.coinbaseKey); + FundTransaction(tx_reg2, utxos, scriptPayout, dmn_types::Regular.collat_amount, setup.coinbaseKey); payload.inputsHash = CalcTxInputsHash(CTransaction(tx_reg2)); CMessageSigner::SignMessage(payload.MakeSignString(), payload.vchSig, collateralKey); SetTxPayload(tx_reg2, payload); @@ -599,7 +599,7 @@ void FuncVerifyDB(TestChainSetup& setup) // Create a MN with an external collateral CMutableTransaction tx_collateral; - FundTransaction(tx_collateral, utxos, scriptCollateral, MnType::Regular.collat_amount, setup.coinbaseKey); + FundTransaction(tx_collateral, utxos, scriptCollateral, dmn_types::Regular.collat_amount, setup.coinbaseKey); SignTransaction(*(setup.m_node.mempool), tx_collateral, setup.coinbaseKey); auto block = std::make_shared(setup.CreateBlock({tx_collateral}, setup.coinbaseKey)); @@ -617,7 +617,7 @@ void FuncVerifyDB(TestChainSetup& setup) payload.scriptPayout = scriptPayout; for (size_t i = 0; i < tx_collateral.vout.size(); ++i) { - if (tx_collateral.vout[i].nValue == MnType::Regular.collat_amount) { + if (tx_collateral.vout[i].nValue == dmn_types::Regular.collat_amount) { payload.collateralOutpoint = COutPoint(tx_collateral.GetHash(), i); break; } @@ -626,7 +626,7 @@ void FuncVerifyDB(TestChainSetup& setup) CMutableTransaction tx_reg; tx_reg.nVersion = 3; tx_reg.nType = TRANSACTION_PROVIDER_REGISTER; - FundTransaction(tx_reg, utxos, scriptPayout, MnType::Regular.collat_amount, setup.coinbaseKey); + FundTransaction(tx_reg, utxos, scriptPayout, dmn_types::Regular.collat_amount, setup.coinbaseKey); payload.inputsHash = CalcTxInputsHash(CTransaction(tx_reg)); CMessageSigner::SignMessage(payload.MakeSignString(), payload.vchSig, collateralKey); SetTxPayload(tx_reg, payload); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 7c188d38cf6c..ad8c61f72448 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2535,7 +2535,7 @@ void CWallet::AvailableCoins(std::vector &vCoins, bool fOnlySafe, const if (CCoinJoin::IsCollateralAmount(pcoin->tx->vout[i].nValue)) continue; // do not use collateral amounts found = !CCoinJoin::IsDenominatedAmount(pcoin->tx->vout[i].nValue); } else if(nCoinType == CoinType::ONLY_MASTERNODE_COLLATERAL) { - found = pcoin->tx->vout[i].nValue == MnType::Regular.collat_amount || pcoin->tx->vout[i].nValue == MnType::HighPerformance.collat_amount; + found = dmn_types::IsCollateralAmount(pcoin->tx->vout[i].nValue); } else if(nCoinType == CoinType::ONLY_COINJOIN_COLLATERAL) { found = CCoinJoin::IsCollateralAmount(pcoin->tx->vout[i].nValue); } else { @@ -3046,7 +3046,7 @@ std::vector CWallet::SelectCoinsGroupedByAddresses(bool fSkipD if(fAnonymizable) { // ignore collaterals if(CCoinJoin::IsCollateralAmount(wtx.tx->vout[i].nValue)) continue; - if (fMasternodeMode && (wtx.tx->vout[i].nValue == MnType::Regular.collat_amount || wtx.tx->vout[i].nValue == MnType::HighPerformance.collat_amount)) continue; + if (fMasternodeMode && dmn_types::IsCollateralAmount(wtx.tx->vout[i].nValue)) continue; // ignore outputs that are 10 times smaller then the smallest denomination // otherwise they will just lead to higher fee / lower priority if(wtx.tx->vout[i].nValue <= nSmallestDenom/10) continue;