Skip to content

Commit e853d0b

Browse files
Merge #6664: fix: MN port validation on mainnet is broken after 6627
2e8c7ef refactor: simplify (non-)mainnet port check condition (UdjinM6) 78ebaeb test: use mainnet setup in evo_netinfo_tests (Kittywhiskers Van Gogh) 20afc99 fix: MN port validation is broken after 6627 (UdjinM6) Pull request description: ## Issue being fixed or feature implemented #6627 broke MN port validation on mainnet - `develop` fails with `bad-protx-netinfo-port` for a completely valid protx ## What was done? Implement it the way it was before https://github.com/dashpay/dash/pull/6627/files#diff-0998f8dfc4c1089e90cbaafe9607b361035b904cd103df31e3c2339a3cbf790dL1189-L1195 ## How Has This Been Tested? Sync on mainnet ## Breaking Changes n/a ## Checklist: - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [ ] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: kwvg: utACK 2e8c7ef knst: utACK 2e8c7ef Tree-SHA512: 1601d5013479c05e06d2f78f5d0ab133f69d37a4580eb7f69fb2c5c0797623bca4f9e55a0048245abbfeb0fcb44de8a43dae6b8b8e58f5f8501d36277bbdc26d
2 parents 0f94e3e + 2e8c7ef commit e853d0b

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/evo/netinfo.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,9 @@ NetInfoStatus MnNetInfo::ValidateService(const CService& service)
3636
return NetInfoStatus::BadInput;
3737
}
3838

39-
const auto default_port_main = MainParams().GetDefaultPort();
40-
if (IsNodeOnMainnet() && service.GetPort() != default_port_main) {
41-
// Must use mainnet port on mainnet
42-
return NetInfoStatus::BadPort;
43-
} else if (service.GetPort() == default_port_main) {
44-
// Using mainnet port prohibited outside of mainnet
39+
if (IsNodeOnMainnet() != (service.GetPort() == MainParams().GetDefaultPort())) {
40+
// Must use mainnet port on mainnet.
41+
// Must NOT use mainnet port on other networks.
4542
return NetInfoStatus::BadPort;
4643
}
4744

src/test/evo_netinfo_tests.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,31 @@
1111

1212
#include <boost/test/unit_test.hpp>
1313

14+
BOOST_FIXTURE_TEST_SUITE(evo_netinfo_tests, BasicTestingSetup)
15+
1416
const std::vector<std::pair</*input=*/std::string, /*expected_ret=*/NetInfoStatus>> vals{
1517
// Address and port specified
16-
{"1.1.1.1:8888", NetInfoStatus::Success},
18+
{"1.1.1.1:9999", NetInfoStatus::Success},
1719
// Address specified, port should default to default P2P core
1820
{"1.1.1.1", NetInfoStatus::Success},
19-
// Mainnet P2P port on non-mainnet
20-
{"1.1.1.1:9999", NetInfoStatus::BadPort},
21+
// Non-mainnet port on mainnet
22+
{"1.1.1.1:9998", NetInfoStatus::BadPort},
23+
// Internal addresses not allowed on mainnet
24+
{"127.0.0.1:9999", NetInfoStatus::BadInput},
2125
// Valid IPv4 formatting but invalid IPv4 address
22-
{"0.0.0.0:8888", NetInfoStatus::BadInput},
26+
{"0.0.0.0:9999", NetInfoStatus::BadInput},
2327
// Port greater than uint16_t max
2428
{"1.1.1.1:99999", NetInfoStatus::BadInput},
2529
// Only IPv4 allowed
26-
{"[2606:4700:4700::1111]:8888", NetInfoStatus::BadInput},
30+
{"[2606:4700:4700::1111]:9999", NetInfoStatus::BadInput},
2731
// Domains are not allowed
28-
{"example.com:8888", NetInfoStatus::BadInput},
32+
{"example.com:9999", NetInfoStatus::BadInput},
2933
// Incorrect IPv4 address
30-
{"1.1.1.256:8888", NetInfoStatus::BadInput},
34+
{"1.1.1.256:9999", NetInfoStatus::BadInput},
3135
// Missing address
32-
{":8888", NetInfoStatus::BadInput},
36+
{":9999", NetInfoStatus::BadInput},
3337
};
3438

35-
BOOST_FIXTURE_TEST_SUITE(evo_netinfo_tests, RegTestingSetup)
36-
3739
void ValidateGetEntries(const CServiceList& entries, const size_t expected_size)
3840
{
3941
BOOST_CHECK_EQUAL(entries.size(), expected_size);

0 commit comments

Comments
 (0)