Skip to content

Commit

Permalink
refactor: Global renaming from hpmn to evo (#5508)
Browse files Browse the repository at this point in the history
## Issue being fixed or feature implemented

## What was done?
Renaming of all classes/variables/functions/rpcs from `hpmn` to `evo`.

## How Has This Been Tested?
All unit and func tests are passing.
Sync of Testnet.

## Breaking Changes
All protx RPCs ending with `_hpmn` were converted to `_evo`.
`_hpmn` RPCs are now deprecated.
Although, they can still be enabled by adding `-deprecatedrpc=hpmn`.


## Checklist:
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [x] I have added or updated relevant unit/integration/functional/e2e
tests
- [x] I have made corresponding changes to the documentation
- [x] I have assigned this pull request to a milestone _(for repository
code-owners and collaborators only)_

---------

Co-authored-by: thephez <[email protected]>
Co-authored-by: UdjinM6 <[email protected]>
  • Loading branch information
3 people authored Aug 17, 2023
1 parent 24a4ed3 commit 93f8df1
Show file tree
Hide file tree
Showing 19 changed files with 255 additions and 227 deletions.
14 changes: 14 additions & 0 deletions doc/release-notes-5508.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Updated RPCs
--------

- `protx register_hpmn` is renamed to `protx register_evo`.
- `protx register_fund_hpmn` is renamed to `protx register_fund_evo`.
- `protx register_prepare_hpmn` is renamed to `protx register_prepare_evo`.
- `protx update_service_hpmn` is renamed to `protx update_service_evo`.

Please note that _hpmn RPCs are deprecated.
Although, they can still be enabled by adding `-deprecatedrpc=hpmn`.

- `masternodelist` filter `hpmn` is renamed to `evo`.
- `masternode count` return total number of EvoNodes under field `evo` instead of `hpmn`.
- Description type string `HighPerformance` is renamed to `Evo`: affects most RPCs return MNs details.
2 changes: 1 addition & 1 deletion src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct Params {
int DIP0020Height;
/** Block height at which DIP0024 (Quorum Rotation) and decreased governance proposal fee becomes active */
int DIP0024Height;
/** Block height at which V19 (Basic BLS and HPMNs/EvoNodes) becomes active */
/** Block height at which V19 (Basic BLS and EvoNodes) becomes active */
int V19Height;
/** Don't warn about unknown BIP 9 activations below this height.
* This prevents us from warning about the CSV and DIP activations. */
Expand Down
80 changes: 40 additions & 40 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,22 @@ CDeterministicMNCPtr CDeterministicMNList::GetMNPayee(const CBlockIndex* pIndex)

bool isv19Active = llmq::utils::IsV19Active(pIndex);
bool isMNRewardReallocation = llmq::utils::IsMNRewardReallocationActive(pIndex);
// Starting from v19 and until MNRewardReallocation (Platform release), HPMN will be rewarded 4 blocks in a row
// Starting from v19 and until MNRewardReallocation (Platform release), EvoNodes will be rewarded 4 blocks in a row
CDeterministicMNCPtr best = nullptr;
if (isv19Active && !isMNRewardReallocation) {
ForEachMNShared(true, [&](const CDeterministicMNCPtr& dmn) {
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 && dmn->pdmnState->nConsecutivePayments < dmn_types::HighPerformance.voting_weight) {
// If the last payee is an EvoNode, we need to check its consecutive payments and pay him again if needed
if (dmn->nType == MnType::Evo && dmn->pdmnState->nConsecutivePayments < dmn_types::Evo.voting_weight) {
best = dmn;
}
}
});

if (best != nullptr) return best;

// Note: If the last payee was a regular MN or if the payee is a HPMN that was removed from the mnList then that's fine.
// Note: If the last payee was a regular MN or if the payee is an EvoNode that was removed from the mnList then that's fine.
// We can proceed with classic MN payee selection
}

Expand Down Expand Up @@ -226,39 +226,39 @@ std::vector<CDeterministicMNCPtr> CDeterministicMNList::GetProjectedMNPayees(con
std::vector<CDeterministicMNCPtr> result;
result.reserve(nCount);

auto remaining_hpmn_payments = 0;
CDeterministicMNCPtr hpmn_to_be_skipped = nullptr;
auto remaining_evo_payments = 0;
CDeterministicMNCPtr evo_to_be_skipped = nullptr;
bool isMNRewardReallocation = llmq::utils::IsMNRewardReallocationActive(pindex);
ForEachMNShared(true, [&](const CDeterministicMNCPtr& dmn) {
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 (!isMNRewardReallocation && dmn->nType == MnType::HighPerformance && dmn->pdmnState->nConsecutivePayments < dmn_types::HighPerformance.voting_weight) {
remaining_hpmn_payments = dmn_types::HighPerformance.voting_weight - dmn->pdmnState->nConsecutivePayments;
for ([[maybe_unused]] auto _ : irange::range(remaining_hpmn_payments)) {
// If the last payee is an EvoNode, we need to check its consecutive payments and pay him again if needed
if (!isMNRewardReallocation && dmn->nType == MnType::Evo && dmn->pdmnState->nConsecutivePayments < dmn_types::Evo.voting_weight) {
remaining_evo_payments = dmn_types::Evo.voting_weight - dmn->pdmnState->nConsecutivePayments;
for ([[maybe_unused]] auto _ : irange::range(remaining_evo_payments)) {
result.emplace_back(dmn);
hpmn_to_be_skipped = dmn;
evo_to_be_skipped = dmn;
}
}
}
return;
});

ForEachMNShared(true, [&](const CDeterministicMNCPtr& dmn) {
if (dmn == hpmn_to_be_skipped) return;
if (dmn == evo_to_be_skipped) return;
for ([[maybe_unused]] auto _ : irange::range(GetMnType(dmn->nType).voting_weight)) {
result.emplace_back(dmn);
}
});

if (hpmn_to_be_skipped != nullptr) {
// if hpmn is in the middle of payments, add entries for already paid ones to the end of the list
for ([[maybe_unused]] auto _ : irange::range(hpmn_to_be_skipped->pdmnState->nConsecutivePayments)) {
result.emplace_back(hpmn_to_be_skipped);
if (evo_to_be_skipped != nullptr) {
// if EvoNode is in the middle of payments, add entries for already paid ones to the end of the list
for ([[maybe_unused]] auto _ : irange::range(evo_to_be_skipped->pdmnState->nConsecutivePayments)) {
result.emplace_back(evo_to_be_skipped);
}
}

std::sort(result.begin() + remaining_hpmn_payments, result.end(), [&](const CDeterministicMNCPtr& a, const CDeterministicMNCPtr& b) {
std::sort(result.begin() + remaining_evo_payments, result.end(), [&](const CDeterministicMNCPtr& a, const CDeterministicMNCPtr& b) {
return CompareByLastPaid(a.get(), b.get());
});

Expand All @@ -267,9 +267,9 @@ std::vector<CDeterministicMNCPtr> CDeterministicMNList::GetProjectedMNPayees(con
return result;
}

std::vector<CDeterministicMNCPtr> CDeterministicMNList::CalculateQuorum(size_t maxSize, const uint256& modifier, const bool onlyHighPerformanceMasternodes) const
std::vector<CDeterministicMNCPtr> CDeterministicMNList::CalculateQuorum(size_t maxSize, const uint256& modifier, const bool onlyEvoNodes) const
{
auto scores = CalculateScores(modifier, onlyHighPerformanceMasternodes);
auto scores = CalculateScores(modifier, onlyEvoNodes);

// sort is descending order
std::sort(scores.rbegin(), scores.rend(), [](const std::pair<arith_uint256, CDeterministicMNCPtr>& a, const std::pair<arith_uint256, CDeterministicMNCPtr>& b) {
Expand All @@ -289,7 +289,7 @@ std::vector<CDeterministicMNCPtr> CDeterministicMNList::CalculateQuorum(size_t m
return result;
}

std::vector<std::pair<arith_uint256, CDeterministicMNCPtr>> CDeterministicMNList::CalculateScores(const uint256& modifier, const bool onlyHighPerformanceMasternodes) const
std::vector<std::pair<arith_uint256, CDeterministicMNCPtr>> CDeterministicMNList::CalculateScores(const uint256& modifier, const bool onlyEvoNodes) const
{
std::vector<std::pair<arith_uint256, CDeterministicMNCPtr>> scores;
scores.reserve(GetAllMNsCount());
Expand All @@ -299,8 +299,8 @@ std::vector<std::pair<arith_uint256, CDeterministicMNCPtr>> CDeterministicMNList
// future quorums
return;
}
if (onlyHighPerformanceMasternodes) {
if (dmn->nType != MnType::HighPerformance)
if (onlyEvoNodes) {
if (dmn->nType != MnType::Evo)
return;
}
// calculate sha256(sha256(proTxHash, confirmedHash), modifier) per MN
Expand Down Expand Up @@ -467,7 +467,7 @@ void CDeterministicMNList::AddMN(const CDeterministicMNCPtr& dmn, bool fBumpTota
dmn->proTxHash.ToString(), dmn->pdmnState->pubKeyOperator.ToString())));
}

if (dmn->nType == MnType::HighPerformance) {
if (dmn->nType == MnType::Evo) {
if (dmn->pdmnState->platformNodeID != uint160() && !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 @@ -507,7 +507,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.ToString())));
}
if (dmn->nType == MnType::HighPerformance) {
if (dmn->nType == MnType::Evo) {
if (!UpdateUniqueProperty(*dmn, oldState->platformNodeID, 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 @@ -568,7 +568,7 @@ void CDeterministicMNList::RemoveMN(const uint256& proTxHash)
proTxHash.ToString(), dmn->pdmnState->pubKeyOperator.ToString())));
}

if (dmn->nType == MnType::HighPerformance) {
if (dmn->nType == MnType::Evo) {
if (dmn->pdmnState->platformNodeID != uint160() && !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 @@ -743,7 +743,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-protx-payload");
}

if (proTx.nType == MnType::HighPerformance && !llmq::utils::IsV19Active(pindexPrev)) {
if (proTx.nType == MnType::Evo && !llmq::utils::IsV19Active(pindexPrev)) {
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-protx-payload");
}

Expand Down Expand Up @@ -806,7 +806,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-protx-payload");
}

if (proTx.nType == MnType::HighPerformance && !llmq::utils::IsV19Active(pindexPrev)) {
if (proTx.nType == MnType::Evo && !llmq::utils::IsV19Active(pindexPrev)) {
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-protx-payload");
}

Expand All @@ -828,7 +828,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
auto newState = std::make_shared<CDeterministicMNState>(*dmn->pdmnState);
newState->addr = proTx.addr;
newState->scriptOperatorPayout = proTx.scriptOperatorPayout;
if (proTx.nType == MnType::HighPerformance) {
if (proTx.nType == MnType::Evo) {
newState->platformNodeID = proTx.platformNodeID;
newState->platformP2PPort = proTx.platformP2PPort;
newState->platformHTTPPort = proTx.platformHTTPPort;
Expand Down Expand Up @@ -945,13 +945,13 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
auto dmn = newList.GetMN(payee->proTxHash);
auto newState = std::make_shared<CDeterministicMNState>(*dmn->pdmnState);
newState->nLastPaidHeight = nHeight;
// Starting from v19 and until MNRewardReallocation, HPMN will be paid 4 blocks in a row
// No need to check if v19 is active, since HPMN ProRegTx are allowed only after v19 activation
// Starting from v19 and until MNRewardReallocation, EvoNodes will be paid 4 blocks in a row
// No need to check if v19 is active, since EvoNode ProRegTxes are allowed only after v19 activation
// Note: If the payee wasn't found in the current block that's fine
if (dmn->nType == MnType::HighPerformance && !isMNRewardReallocation) {
if (dmn->nType == MnType::Evo && !isMNRewardReallocation) {
++newState->nConsecutivePayments;
if (debugLogs) {
LogPrint(BCLog::MNPAYMENTS, "CDeterministicMNManager::%s -- MN %s is a HPMN, bumping nConsecutivePayments to %d\n",
LogPrint(BCLog::MNPAYMENTS, "CDeterministicMNManager::%s -- MN %s is an EvoNode, bumping nConsecutivePayments to %d\n",
__func__, dmn->proTxHash.ToString(), newState->nConsecutivePayments);
}
}
Expand All @@ -963,10 +963,10 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
}
}

// reset nConsecutivePayments on non-paid HPMNs
// reset nConsecutivePayments on non-paid EvoNodes
auto newList2 = newList;
newList2.ForEachMN(false, [&](auto& dmn) {
if (dmn.nType != MnType::HighPerformance) return;
if (dmn.nType != MnType::Evo) return;
if (payee != nullptr && dmn.proTxHash == payee->proTxHash && !isMNRewardReallocation) return;
if (dmn.pdmnState->nConsecutivePayments == 0) return;
if (debugLogs) {
Expand Down Expand Up @@ -1496,7 +1496,7 @@ bool CheckProRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxVali
return false;
}

if (ptx.nType == MnType::HighPerformance) {
if (ptx.nType == MnType::Evo) {
if (!CheckPlatformFields(ptx, state)) {
return false;
}
Expand Down Expand Up @@ -1560,8 +1560,8 @@ bool CheckProRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxVali
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-dup-key");
}

// never allow duplicate platformNodeIds for HPMNs
if (ptx.nType == MnType::HighPerformance) {
// never allow duplicate platformNodeIds for EvoNodes
if (ptx.nType == MnType::Evo) {
if (mnList.HasUniqueProperty(ptx.platformNodeID)) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-dup-platformnodeid");
}
Expand Down Expand Up @@ -1616,7 +1616,7 @@ bool CheckProUpServTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxV
return false;
}

if (ptx.nType == MnType::HighPerformance) {
if (ptx.nType == MnType::Evo) {
if (!CheckPlatformFields(ptx, state)) {
return false;
}
Expand All @@ -1634,8 +1634,8 @@ bool CheckProUpServTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxV
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-dup-addr");
}

// don't allow updating to platformNodeIds already used by other HPMNs
if (ptx.nType == MnType::HighPerformance) {
// don't allow updating to platformNodeIds already used by other EvoNodes
if (ptx.nType == MnType::Evo) {
if (mnList.HasUniqueProperty(ptx.platformNodeID) && mnList.GetUniquePropertyMN(ptx.platformNodeID)->proTxHash != ptx.proTxHash) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-dup-platformnodeid");
}
Expand Down
12 changes: 6 additions & 6 deletions src/evo/deterministicmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,14 @@ class CDeterministicMNList
return ranges::count_if(mnMap, [this](const auto& p){ return IsMNValid(*p.second); });
}

[[nodiscard]] size_t GetAllHPMNsCount() const
[[nodiscard]] size_t GetAllEvoCount() const
{
return ranges::count_if(mnMap, [this](const auto& p) { return p.second->nType == MnType::HighPerformance; });
return ranges::count_if(mnMap, [this](const auto& p) { return p.second->nType == MnType::Evo; });
}

[[nodiscard]] size_t GetValidHPMNsCount() const
[[nodiscard]] size_t GetValidEvoCount() const
{
return ranges::count_if(mnMap, [this](const auto& p) { return p.second->nType == MnType::HighPerformance && IsMNValid(*p.second); });
return ranges::count_if(mnMap, [this](const auto& p) { return p.second->nType == MnType::Evo && IsMNValid(*p.second); });
}

[[nodiscard]] size_t GetValidWeightedMNsCount() const
Expand Down Expand Up @@ -351,8 +351,8 @@ class CDeterministicMNList
* @param modifier
* @return
*/
[[nodiscard]] std::vector<CDeterministicMNCPtr> CalculateQuorum(size_t maxSize, const uint256& modifier, const bool onlyHighPerformanceMasternodes = false) const;
[[nodiscard]] std::vector<std::pair<arith_uint256, CDeterministicMNCPtr>> CalculateScores(const uint256& modifier, const bool onlyHighPerformanceMasternodes) const;
[[nodiscard]] std::vector<CDeterministicMNCPtr> CalculateQuorum(size_t maxSize, const uint256& modifier, const bool onlyEvoNodes = false) const;
[[nodiscard]] std::vector<std::pair<arith_uint256, CDeterministicMNCPtr>> CalculateScores(const uint256& modifier, const bool onlyEvoNodes) const;

/**
* Calculates the maximum penalty which is allowed at the height of this MN list. It is dynamic and might change
Expand Down
10 changes: 5 additions & 5 deletions src/evo/dmn_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

enum class MnType : uint16_t {
Regular = 0,
HighPerformance = 1,
Evo = 1,
COUNT,
Invalid = std::numeric_limits<uint16_t>::max(),
};
Expand All @@ -34,10 +34,10 @@ constexpr auto Regular = mntype_struct{
.collat_amount = 1000 * COIN,
.description = "Regular",
};
constexpr auto HighPerformance = mntype_struct{
constexpr auto Evo = mntype_struct{
.voting_weight = 4,
.collat_amount = 4000 * COIN,
.description = "HighPerformance",
.description = "Evo",
};
constexpr auto Invalid = mntype_struct{
.voting_weight = 0,
Expand All @@ -48,7 +48,7 @@ constexpr auto Invalid = mntype_struct{
[[nodiscard]] static constexpr bool IsCollateralAmount(CAmount amount)
{
return amount == Regular.collat_amount ||
amount == HighPerformance.collat_amount;
amount == Evo.collat_amount;
}

} // namespace dmn_types
Expand All @@ -57,7 +57,7 @@ constexpr auto Invalid = mntype_struct{
{
switch (type) {
case MnType::Regular: return dmn_types::Regular;
case MnType::HighPerformance: return dmn_types::HighPerformance;
case MnType::Evo: return dmn_types::Evo;
default: return dmn_types::Invalid;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/evo/dmnstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void CDeterministicMNState::ToJson(UniValue& obj, MnType nType) const
obj.pushKV("revocationReason", nRevocationReason);
obj.pushKV("ownerAddress", EncodeDestination(PKHash(keyIDOwner)));
obj.pushKV("votingAddress", EncodeDestination(PKHash(keyIDVoting)));
if (nType == MnType::HighPerformance) {
if (nType == MnType::Evo) {
obj.pushKV("platformNodeID", platformNodeID.ToString());
obj.pushKV("platformP2PPort", platformP2PPort);
obj.pushKV("platformHTTPPort", platformHTTPPort);
Expand Down Expand Up @@ -114,7 +114,7 @@ void CDeterministicMNStateDiff::ToJson(UniValue& obj, MnType nType) const
if (fields & Field_pubKeyOperator) {
obj.pushKV("pubKeyOperator", state.pubKeyOperator.ToString());
}
if (nType == MnType::HighPerformance) {
if (nType == MnType::Evo) {
if (fields & Field_platformNodeID) {
obj.pushKV("platformNodeID", state.platformNodeID.ToString());
}
Expand Down
Loading

0 comments on commit 93f8df1

Please sign in to comment.