Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -268,7 +268,7 @@ std::vector<std::pair<arith_uint256, CDeterministicMNCPtr>> CDeterministicMNList
return;
}
if (onlyHighPerformanceMasternodes) {
if (dmn->nType != MnType::HighPerformance.index)
if (dmn->nType != MnType::HighPerformance)
return;
}
// calculate sha256(sha256(proTxHash, confirmedHash), modifier) per MN
Expand Down Expand Up @@ -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__,
Expand Down Expand Up @@ -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__,
Expand Down Expand Up @@ -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__,
Expand Down Expand Up @@ -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<CDeterministicMN>(newList.GetTotalRegisteredCount(), proTx.nType == MnType::HighPerformance.index);
auto dmn = std::make_shared<CDeterministicMN>(newList.GetTotalRegisteredCount(), proTx.nType);
dmn->proTxHash = tx.GetHash();

// collateralOutpoint is either pointing to an external collateral or to the ProRegTx itself
Expand Down Expand Up @@ -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");
}

Expand All @@ -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<CDeterministicMNState>(*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;
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions src/evo/deterministicmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>::max());
Expand All @@ -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<const CDeterministicMNState> pdmnState;

template <typename Stream, typename Operation>
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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; });
}

/**
Expand Down
47 changes: 30 additions & 17 deletions src/evo/dmn_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,52 @@
#define BITCOIN_EVO_DMN_TYPES_H

#include <amount.h>
#include <serialize.h>

#include <cassert>
#include <string_view>

class CDeterministicMNType
enum class MnType : uint16_t {
Regular = 0,
HighPerformance = 1,
};

template<> struct is_serializable_enum<MnType> : 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);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/evo/providertx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<int>(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
Expand All @@ -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<int>(nType), proTxHash.ToString(), addr.ToString(), payee, platformNodeID.ToString(), platformP2PPort, platformHTTPPort);
}

maybe_error CProUpRegTx::IsTriviallyValid(bool is_bls_legacy_scheme) const
Expand Down
16 changes: 8 additions & 8 deletions src/evo/providertx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -92,7 +92,7 @@ class CProRegTx
obj.clear();
obj.setObject();
obj.pushKV("version", nVersion);
obj.pushKV("type", nType);
obj.pushKV("type", static_cast<uint16_t>(nType));
obj.pushKV("collateralHash", collateralOutpoint.hash.ToString());
obj.pushKV("collateralIndex", (int)collateralOutpoint.n);
obj.pushKV("service", addr.ToString(false));
Expand All @@ -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);
Expand All @@ -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{};
Expand Down Expand Up @@ -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,
Expand All @@ -178,14 +178,14 @@ class CProUpServTx
obj.clear();
obj.setObject();
obj.pushKV("version", nVersion);
obj.pushKV("type", nType);
obj.pushKV("type", static_cast<uint16_t>(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);
Expand Down
6 changes: 3 additions & 3 deletions src/evo/simplifiedmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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
Expand All @@ -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<uint16_t>(nType));
if (nType == MnType::HighPerformance) {
obj.pushKV("platformHTTPPort", platformHTTPPort);
obj.pushKV("platformNodeID", platformNodeID.ToString());
}
Expand Down
4 changes: 2 additions & 2 deletions src/evo/simplifiedmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
Loading