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
29 changes: 29 additions & 0 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ void CDeterministicMNList::AddMN(const CDeterministicMNCPtr& dmn, bool fBumpTota
throw std::runtime_error(strprintf("%s: Can't add a masternode %s with a duplicate address=%s", __func__,
dmn->proTxHash.ToString(), service_opt->ToStringAddrPort()));
}
} else if (const auto domain_opt{entry.GetDomainPort()}) {
if (!AddUniqueProperty(*dmn, *domain_opt)) {
mnUniquePropertyMap = mnUniquePropertyMapSaved;
throw std::runtime_error(strprintf("%s: Can't add a masternode %s with a duplicate address=%s",
__func__, dmn->proTxHash.ToString(), domain_opt->ToStringAddrPort()));
}
} else {
mnUniquePropertyMap = mnUniquePropertyMapSaved;
throw std::runtime_error(
Expand Down Expand Up @@ -494,6 +500,10 @@ void CDeterministicMNList::UpdateMN(const CDeterministicMN& oldDmn, const std::s
if (!DeleteUniqueProperty(dmn, *service_opt)) {
return "internal error"; // This shouldn't be possible
}
} else if (const auto domain_opt{old_entry.GetDomainPort()}) {
if (!DeleteUniqueProperty(dmn, *domain_opt)) {
return "internal error"; // This shouldn't be possible
}
} else {
return "invalid address";
}
Expand All @@ -503,6 +513,10 @@ void CDeterministicMNList::UpdateMN(const CDeterministicMN& oldDmn, const std::s
if (!AddUniqueProperty(dmn, *service_opt)) {
return strprintf("duplicate (%s)", service_opt->ToStringAddrPort());
}
} else if (const auto domain_opt{new_entry.GetDomainPort()}) {
if (!AddUniqueProperty(dmn, *domain_opt)) {
return strprintf("duplicate (%s)", domain_opt->ToStringAddrPort());
}
} else {
return "invalid address";
}
Expand Down Expand Up @@ -583,6 +597,12 @@ void CDeterministicMNList::RemoveMN(const uint256& proTxHash)
throw std::runtime_error(strprintf("%s: Can't delete a masternode %s with an address=%s", __func__,
proTxHash.ToString(), service_opt->ToStringAddrPort()));
}
} else if (const auto domain_opt{entry.GetDomainPort()}) {
if (!DeleteUniqueProperty(*dmn, *domain_opt)) {
mnUniquePropertyMap = mnUniquePropertyMapSaved;
throw std::runtime_error(strprintf("%s: Can't delete a masternode %s with an address=%s", __func__,
proTxHash.ToString(), domain_opt->ToStringAddrPort()));
}
} else {
mnUniquePropertyMap = mnUniquePropertyMapSaved;
throw std::runtime_error(strprintf("%s: Can't delete a masternode %s with invalid address", __func__,
Expand Down Expand Up @@ -1142,6 +1162,11 @@ bool CheckProRegTx(CDeterministicMNManager& dmnman, const CTransaction& tx, gsl:
mnList.GetUniquePropertyMN(*service_opt)->collateralOutpoint != collateralOutpoint) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-dup-netinfo-entry");
}
} else if (const auto domain_opt{entry.GetDomainPort()}) {
if (mnList.HasUniqueProperty(*domain_opt) &&
mnList.GetUniquePropertyMN(*domain_opt)->collateralOutpoint != collateralOutpoint) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-dup-netinfo-entry");
}
} else {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-netinfo-entry");
}
Expand Down Expand Up @@ -1224,6 +1249,10 @@ bool CheckProUpServTx(CDeterministicMNManager& dmnman, const CTransaction& tx, g
mnList.GetUniquePropertyMN(*service_opt)->proTxHash != opt_ptx->proTxHash) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-dup-netinfo-entry");
}
} else if (const auto domain_opt{entry.GetDomainPort()}) {
if (mnList.HasUniqueProperty(*domain_opt) && mnList.GetUniquePropertyMN(*domain_opt)->proTxHash != opt_ptx->proTxHash) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-dup-netinfo-entry");
}
} else {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-netinfo-entry");
}
Expand Down
12 changes: 11 additions & 1 deletion src/evo/deterministicmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,17 @@ class CDeterministicMNList
DMNL_NO_TEMPLATE(NetInfoInterface);
DMNL_NO_TEMPLATE(std::shared_ptr<NetInfoInterface>);
#undef DMNL_NO_TEMPLATE
return ::SerializeHash(v);
int ser_version{PROTOCOL_VERSION};
if constexpr (std::is_same_v<std::decay_t<T>, CService>) {
// Special handling is required if we're using addresses that can only be (de)serialized using
// ADDRv2. Without this step, the address gets truncated, the hashmap gets contaminated with
// an invalid entry and subsequent attempts at registering ADDRv2 entries get blocked. We cannot
// apply this treatment ADDRv1 compatible addresses for backwards compatibility with the existing map.
if (!v.IsAddrV1Compatible()) {
ser_version |= ADDRV2_FORMAT;
}
}
return ::SerializeHash(v, /*nType=*/SER_GETHASH, /*nVersion=*/ser_version);
}
template <typename T>
[[nodiscard]] bool AddUniqueProperty(const CDeterministicMN& dmn, const T& v)
Expand Down
Loading
Loading