Skip to content

Commit e155529

Browse files
committed
evo: stop using platform{HTTP,P2P}Port fields if using extended addrs
1 parent bfbfe3c commit e155529

File tree

9 files changed

+76
-47
lines changed

9 files changed

+76
-47
lines changed

src/evo/deterministicmns.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -918,39 +918,41 @@ static bool CheckService(const ProTx& proTx, TxValidationState& state)
918918
}
919919

920920
template <typename ProTx>
921-
static bool CheckPlatformFields(const ProTx& proTx, TxValidationState& state)
921+
static bool CheckPlatformFields(const ProTx& proTx, bool is_extended_addr, TxValidationState& state)
922922
{
923923
if (proTx.platformNodeID.IsNull()) {
924924
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-platform-nodeid");
925925
}
926926

927-
// TODO: use real args here
928-
static int mainnetPlatformP2PPort = CreateChainParams(ArgsManager{}, CBaseChainParams::MAIN)->GetDefaultPlatformP2PPort();
929-
if (Params().NetworkIDString() == CBaseChainParams::MAIN) {
930-
if (proTx.platformP2PPort != mainnetPlatformP2PPort) {
927+
if (is_extended_addr) {
928+
// platformHTTPPort and platformP2PPort have been subsumed by netInfo. They should always be zero.
929+
if (proTx.platformP2PPort != 0) {
931930
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-platform-p2p-port");
932931
}
932+
if (proTx.platformHTTPPort != 0) {
933+
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-platform-http-port");
934+
}
935+
return true;
933936
}
934937

935-
// TODO: use real args here
936-
static int mainnetPlatformHTTPPort = CreateChainParams(ArgsManager{}, CBaseChainParams::MAIN)->GetDefaultPlatformHTTPPort();
937-
if (Params().NetworkIDString() == CBaseChainParams::MAIN) {
938-
if (proTx.platformHTTPPort != mainnetPlatformHTTPPort) {
938+
if (::IsNodeOnMainnet()) {
939+
if (proTx.platformP2PPort != ::MainParams().GetDefaultPlatformP2PPort()) {
940+
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-platform-p2p-port");
941+
}
942+
if (proTx.platformHTTPPort != ::MainParams().GetDefaultPlatformHTTPPort()) {
939943
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-platform-http-port");
940944
}
941945
}
942-
943-
// TODO: use real args here
944-
static int mainnetDefaultP2PPort = CreateChainParams(ArgsManager{}, CBaseChainParams::MAIN)->GetDefaultPort();
945-
if (proTx.platformP2PPort == mainnetDefaultP2PPort) {
946+
if (proTx.platformP2PPort == ::MainParams().GetDefaultPort()) {
946947
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-platform-p2p-port");
947948
}
948-
if (proTx.platformHTTPPort == mainnetDefaultP2PPort) {
949+
if (proTx.platformHTTPPort == ::MainParams().GetDefaultPort()) {
949950
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-platform-http-port");
950951
}
951952

952-
if (proTx.platformP2PPort == proTx.platformHTTPPort || proTx.platformP2PPort == proTx.netInfo->GetPrimary().GetPort() ||
953-
proTx.platformHTTPPort == proTx.netInfo->GetPrimary().GetPort()) {
953+
const uint16_t core_port{proTx.netInfo->GetPrimary().GetPort()};
954+
if (proTx.platformP2PPort == proTx.platformHTTPPort || proTx.platformP2PPort == core_port ||
955+
proTx.platformHTTPPort == core_port) {
954956
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-platform-dup-ports");
955957
}
956958

@@ -1062,7 +1064,7 @@ bool CheckProRegTx(CDeterministicMNManager& dmnman, const CTransaction& tx, gsl:
10621064
}
10631065

10641066
if (opt_ptx->nType == MnType::Evo) {
1065-
if (!CheckPlatformFields(*opt_ptx, state)) {
1067+
if (!CheckPlatformFields(*opt_ptx, opt_ptx->nVersion >= ProTxVersion::ExtAddr, state)) {
10661068
return false;
10671069
}
10681070
}
@@ -1181,7 +1183,7 @@ bool CheckProUpServTx(CDeterministicMNManager& dmnman, const CTransaction& tx, g
11811183
}
11821184

11831185
if (opt_ptx->nType == MnType::Evo) {
1184-
if (!CheckPlatformFields(*opt_ptx, state)) {
1186+
if (!CheckPlatformFields(*opt_ptx, opt_ptx->nVersion >= ProTxVersion::ExtAddr, state)) {
11851187
return false;
11861188
}
11871189
}

src/evo/dmnstate.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,12 @@ class CDeterministicMNState
102102
obj.nVersion >= ProTxVersion::ExtAddr),
103103
obj.scriptPayout,
104104
obj.scriptOperatorPayout,
105-
obj.platformNodeID,
105+
obj.platformNodeID);
106+
if (obj.nVersion < ProTxVersion::ExtAddr) {
107+
READWRITE(
106108
obj.platformP2PPort,
107109
obj.platformHTTPPort);
110+
}
108111
}
109112

110113
void ResetOperatorFields()

src/evo/netinfo.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,20 @@ static std::once_flag g_main_params_flag;
2121
static constexpr std::string_view SAFE_CHARS_IPV4{"1234567890."};
2222
static constexpr std::string_view SAFE_CHARS_IPV4_6{"abcdefABCDEF1234567890.:[]"};
2323

24-
bool IsNodeOnMainnet() { return Params().NetworkIDString() == CBaseChainParams::MAIN; }
25-
const CChainParams& MainParams()
26-
{
27-
// TODO: use real args here
28-
std::call_once(g_main_params_flag,
29-
[&]() { g_main_params = CreateChainParams(ArgsManager{}, CBaseChainParams::MAIN); });
30-
return *Assert(g_main_params);
31-
}
32-
3324
bool MatchCharsFilter(std::string_view input, std::string_view filter)
3425
{
3526
return std::all_of(input.begin(), input.end(), [&filter](char c) { return filter.find(c) != std::string_view::npos; });
3627
}
3728
} // anonymous namespace
3829

30+
bool IsNodeOnMainnet() { return Params().NetworkIDString() == CBaseChainParams::MAIN; }
31+
32+
const CChainParams& MainParams()
33+
{
34+
std::call_once(g_main_params_flag, [&]() { g_main_params = CreateChainParams(::gArgs, CBaseChainParams::MAIN); });
35+
return *Assert(g_main_params);
36+
}
37+
3938
UniValue ArrFromService(const CService& addr)
4039
{
4140
UniValue obj(UniValue::VARR);

src/evo/netinfo.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <variant>
1313

14+
class CChainParams;
1415
class CService;
1516

1617
class UniValue;
@@ -96,9 +97,15 @@ constexpr std::string_view PurposeToString(const NetInfoPurpose purpose)
9697
return "";
9798
}
9899

99-
/* Identical to IsDeprecatedRPCEnabled("service"). For use outside of RPC code. */
100+
/** Will return true if node is running on mainnet */
101+
bool IsNodeOnMainnet();
102+
103+
/** Identical to IsDeprecatedRPCEnabled("service"). For use outside of RPC code */
100104
bool IsServiceDeprecatedRPCEnabled();
101105

106+
/** Equivalent to Params() if node is running on mainnet */
107+
const CChainParams& MainParams();
108+
102109
class NetInfoEntry
103110
{
104111
public:

src/evo/providertx.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,13 @@ std::string CProRegTx::ToString() const
144144
}
145145

146146
return strprintf("CProRegTx(nVersion=%d, nType=%d, collateralOutpoint=%s, netInfo=%s, nOperatorReward=%f, "
147-
"ownerAddress=%s, pubKeyOperator=%s, votingAddress=%s, scriptPayout=%s, platformNodeID=%s, "
148-
"platformP2PPort=%d, platformHTTPPort=%d)\n",
147+
"ownerAddress=%s, pubKeyOperator=%s, votingAddress=%s, scriptPayout=%s, platformNodeID=%s%s)\n",
149148
nVersion, ToUnderlying(nType), collateralOutpoint.ToStringShort(), netInfo->ToString(),
150149
(double)nOperatorReward / 100, EncodeDestination(PKHash(keyIDOwner)), pubKeyOperator.ToString(),
151-
EncodeDestination(PKHash(keyIDVoting)), payee, platformNodeID.ToString(), platformP2PPort,
152-
platformHTTPPort);
150+
EncodeDestination(PKHash(keyIDVoting)), payee, platformNodeID.ToString(),
151+
(nVersion >= ProTxVersion::ExtAddr
152+
? ""
153+
: strprintf(", platformP2PPort=%d, platformHTTPPort=%d", platformP2PPort, platformHTTPPort)));
153154
}
154155

155156
bool CProUpServTx::IsTriviallyValid(gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state) const
@@ -188,9 +189,12 @@ std::string CProUpServTx::ToString() const
188189
}
189190

190191
return strprintf("CProUpServTx(nVersion=%d, nType=%d, proTxHash=%s, netInfo=%s, operatorPayoutAddress=%s, "
191-
"platformNodeID=%s, platformP2PPort=%d, platformHTTPPort=%d)\n",
192+
"platformNodeID=%s%s)\n",
192193
nVersion, ToUnderlying(nType), proTxHash.ToString(), netInfo->ToString(), payee,
193-
platformNodeID.ToString(), platformP2PPort, platformHTTPPort);
194+
platformNodeID.ToString(),
195+
(nVersion >= ProTxVersion::ExtAddr
196+
? ""
197+
: strprintf(", platformP2PPort=%d, platformHTTPPort=%d", platformP2PPort, platformHTTPPort)));
194198
}
195199

196200
bool CProUpRegTx::IsTriviallyValid(gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state) const

src/evo/providertx.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,12 @@ class CProRegTx
102102
);
103103
if (obj.nType == MnType::Evo) {
104104
READWRITE(
105-
obj.platformNodeID,
105+
obj.platformNodeID);
106+
if (obj.nVersion < ProTxVersion::ExtAddr) {
107+
READWRITE(
106108
obj.platformP2PPort,
107109
obj.platformHTTPPort);
110+
}
108111
}
109112
if (!(s.GetType() & SER_GETHASH)) {
110113
READWRITE(obj.vchSig);
@@ -161,9 +164,12 @@ class CProUpServTx
161164
);
162165
if (obj.nType == MnType::Evo) {
163166
READWRITE(
164-
obj.platformNodeID,
167+
obj.platformNodeID);
168+
if (obj.nVersion < ProTxVersion::ExtAddr) {
169+
READWRITE(
165170
obj.platformP2PPort,
166171
obj.platformHTTPPort);
172+
}
167173
}
168174
if (!(s.GetType() & SER_GETHASH)) {
169175
READWRITE(

src/evo/simplifiedmns.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ std::string CSimplifiedMNListEntry::ToString() const
5858

5959
return strprintf("CSimplifiedMNListEntry(nVersion=%d, nType=%d, proRegTxHash=%s, confirmedHash=%s, netInfo=%s, "
6060
"pubKeyOperator=%s, votingAddress=%s, isValid=%d, payoutAddress=%s, operatorPayoutAddress=%s, "
61-
"platformHTTPPort=%d, platformNodeID=%s)\n",
61+
"platformNodeID=%s%s)\n",
6262
nVersion, ToUnderlying(nType), proRegTxHash.ToString(), confirmedHash.ToString(),
6363
netInfo->ToString(), pubKeyOperator.ToString(), EncodeDestination(PKHash(keyIDVoting)), isValid,
64-
payoutAddress, operatorPayoutAddress, platformHTTPPort, platformNodeID.ToString());
64+
payoutAddress, operatorPayoutAddress, platformNodeID.ToString(),
65+
(nVersion >= ProTxVersion::ExtAddr ? "" : strprintf(", platformHTTPPort=%d", platformHTTPPort)));
6566
}
6667

6768
CSimplifiedMNList::CSimplifiedMNList(std::vector<std::unique_ptr<CSimplifiedMNListEntry>>&& smlEntries)

src/evo/simplifiedmns.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class CSimplifiedMNListEntry
6565
SERIALIZE_METHODS(CSimplifiedMNListEntry, obj)
6666
{
6767
if ((s.GetType() & SER_NETWORK) && s.GetVersion() >= SMNLE_VERSIONED_PROTO_VERSION) {
68-
READWRITE(obj.nVersion);
68+
READWRITE(
69+
obj.nVersion);
6970
}
7071
READWRITE(
7172
obj.proRegTxHash,
@@ -74,16 +75,20 @@ class CSimplifiedMNListEntry
7475
obj.nVersion >= ProTxVersion::ExtAddr),
7576
CBLSLazyPublicKeyVersionWrapper(const_cast<CBLSLazyPublicKey&>(obj.pubKeyOperator), (obj.nVersion == ProTxVersion::LegacyBLS)),
7677
obj.keyIDVoting,
77-
obj.isValid
78-
);
78+
obj.isValid);
7979
if ((s.GetType() & SER_NETWORK) && s.GetVersion() < DMN_TYPE_PROTO_VERSION) {
8080
return;
8181
}
8282
if (obj.nVersion >= ProTxVersion::BasicBLS) {
83-
READWRITE(obj.nType);
83+
READWRITE(
84+
obj.nType);
8485
if (obj.nType == MnType::Evo) {
85-
READWRITE(obj.platformHTTPPort);
86-
READWRITE(obj.platformNodeID);
86+
if (obj.nVersion < ProTxVersion::ExtAddr) {
87+
READWRITE(
88+
obj.platformHTTPPort);
89+
}
90+
READWRITE(
91+
obj.platformNodeID);
8792
}
8893
}
8994
}

src/evo/specialtxman.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,10 @@ bool CSpecialTxProcessor::BuildNewListFromBlock(const CBlock& block, gsl::not_nu
323323
newState->scriptOperatorPayout = opt_proTx->scriptOperatorPayout;
324324
if (opt_proTx->nType == MnType::Evo) {
325325
newState->platformNodeID = opt_proTx->platformNodeID;
326-
newState->platformP2PPort = opt_proTx->platformP2PPort;
327-
newState->platformHTTPPort = opt_proTx->platformHTTPPort;
326+
if (opt_proTx->nVersion < ProTxVersion::ExtAddr) {
327+
newState->platformP2PPort = opt_proTx->platformP2PPort;
328+
newState->platformHTTPPort = opt_proTx->platformHTTPPort;
329+
}
328330
}
329331
if (newState->IsBanned()) {
330332
// only revive when all keys are set

0 commit comments

Comments
 (0)