From 8333330bd32641fe8c8431996b482d61a992292d Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Mon, 9 Nov 2026 14:40:20 +0700 Subject: [PATCH] refactor(platform-wallet): check a converted evonode address map with rust-dashcore's Core rules The V24 conversion of a legacy evonode into a version-3 address map was checked against a copy of Dash Core v24's port and duplicate-entry rules (IsBadPort ports, port 0, 443 only for Platform HTTPS, one address listed twice). rust-dashcore now ships those rules as ExtNetInfo::validate_ports_and_duplicates, so the wallet builds the map first and checks it with that helper; the copied port list and the two wallet checks are removed. The helper's error does not name the refused entry, so the wallet finds it by port in the converted map (one entry per purpose, all at the legacy IP) and keeps its existing messages: the purpose and port Core refuses, or the two services that would share a port. A future error variant falls back to a message carrying the helper's error. The accept/refuse set is unchanged. When a conversion breaks both rules at once, the duplicate is now reported first, the order Core applies. Tests: the existing conversion tests pass unchanged. Mutation checks through the new path: skipping the helper call fails both tests; naming the purpose of a different port fails the bad-port test; naming a different pair fails the repeated-address test. Co-Authored-By: Claude Opus 5.5 --- .../src/masternode/update_service.rs | 136 ++++++++---------- 1 file changed, 56 insertions(+), 80 deletions(-) diff --git a/packages/rs-platform-wallet/src/masternode/update_service.rs b/packages/rs-platform-wallet/src/masternode/update_service.rs index 828d158e6b5..9996530a311 100644 --- a/packages/rs-platform-wallet/src/masternode/update_service.rs +++ b/packages/rs-platform-wallet/src/masternode/update_service.rs @@ -28,7 +28,7 @@ use dashcore::bls_sig_utils::BLSSignature; use dashcore::hash_types::{InputsHash, SpecialTransactionPayloadHash}; use dashcore::hashes::sha256d; use dashcore::sml::masternode_list_entry::net_info::{ - Bip155Network, ExtNetInfo, NetInfoEntry, NetInfoPurpose, + Bip155Network, ExtNetInfo, ExtNetInfoError, NetInfoEntry, NetInfoPurpose, }; use dashcore::sml::masternode_list_entry::{ EntryMasternodeType, MasternodeListEntry, MasternodeNetInfo, @@ -397,8 +397,8 @@ const MAINNET_PLATFORM_P2P_PORT: u16 = 26656; /// Platform P2P port 26656: Core holds a pre-v3 mainnet evonode to that /// port, while the version-3 address map has no such rule, so another /// port would be accepted and kept. On every network it refuses a port -/// Core refuses in the address map (see [`require_port_core_accepts`]) -/// and a port two services would share (see [`require_distinct_ports`]); +/// Core refuses in the address map and a port two services would share +/// (see [`require_core_accepts_converted_net_info`]); /// - any other legacy entry stays at version 2 (BasicBLS), which Core /// accepts for a regular masternode on either side of V24 and for an /// evonode before it. @@ -478,22 +478,11 @@ pub(crate) fn prepare_update_service_placeholder( {MAINNET_PLATFORM_P2P_PORT}" ))); } - let ports = [ - (NetInfoPurpose::CoreP2P, service.port()), - (NetInfoPurpose::PlatformP2P, p2p_port), - (NetInfoPurpose::PlatformHttps, *platform_http_port), - ]; - for (purpose, port) in ports { - require_port_core_accepts(purpose, port)?; - } - require_distinct_ports(&ports)?; + let net_info = legacy_evonode_net_info(*service, p2p_port, *platform_http_port); + require_core_accepts_converted_net_info(&net_info)?; ( ProTxVersion::ExtAddr, - MasternodeNetInfo::Extended(legacy_evonode_net_info( - *service, - p2p_port, - *platform_http_port, - )), + MasternodeNetInfo::Extended(net_info), None, ) } else { @@ -560,79 +549,66 @@ fn require_listed_platform_p2p_port( ))) } -/// Dash Core's `PRIVILEGED_PORTS_THRESHOLD`: `IsBadPort` refuses every port -/// from 1 to this one, the system ports. -const CORE_PRIVILEGED_PORTS_THRESHOLD: u16 = 1023; - -/// The ports above the system ports that Dash Core's `IsBadPort` refuses, -/// copied from `src/netbase.cpp` in Dash Core v24.0.0-rc.4. -const CORE_BAD_PORTS: [u16; 21] = [ - 1719, // h323gatestat - 1720, // h323hostcall - 1723, // pptp - 2049, // nfs - 3659, // apple-sasl / PasswordServer - 4045, // lockd - 5060, // sip - 5061, // sips - 6000, // X11 - 6566, // sane-port - 6665, // Alternate IRC - 6666, // Alternate IRC - 6667, // Standard IRC - 6668, // Alternate IRC - 6669, // Alternate IRC - 6697, // IRC + TLS - 8332, // Bitcoin RPC - 8333, // Bitcoin P2P - 10080, // Amanda - 18332, // Bitcoin testnet RPC - 18333, // Bitcoin testnet RPC -]; - -/// Dash Core v24 checks the port of every IP-address entry of a version-3 -/// address map (`ExtNetInfo::ValidateService`) and refuses the transaction +/// Dash Core v24 refuses a version-3 address map (`ExtNetInfo::Validate`) /// with `bad-protx-netinfo-port` for port 0 and for every port `IsBadPort` -/// lists, except 443 for Platform HTTPS. Pre-v3 entries were never held to -/// this rule, so a legacy evonode can carry such a port, and its conversion +/// lists, except 443 for Platform HTTPS, and with +/// `bad-protx-dup-netinfo-entry` when it lists one address twice; +/// rust-dashcore's [`ExtNetInfo::validate_ports_and_duplicates`] applies +/// those rules. Pre-v3 entries were never held to them, so a legacy evonode +/// can carry such a port, and its conversion gives all its services the +/// same IP, so two services on one port repeat an address. The conversion /// is refused here before anything is built rather than broadcast to a /// network that never confirms it. -fn require_port_core_accepts( - purpose: NetInfoPurpose, - port: u16, +/// +/// The helper's error does not name the entry it refuses. A converted map +/// holds one entry per purpose, all at the legacy IP, so the entry is found +/// by its port: the one on the refused port, or the two sharing a port. +fn require_core_accepts_converted_net_info( + net_info: &ExtNetInfo, ) -> Result<(), PlatformWalletError> { - let is_bad_port = - (1..=CORE_PRIVILEGED_PORTS_THRESHOLD).contains(&port) || CORE_BAD_PORTS.contains(&port); - let is_allowed_https_port = purpose == NetInfoPurpose::PlatformHttps && port == 443; - let refused = port == 0 || (is_bad_port && !is_allowed_https_port); - if !refused { + let Err(error) = net_info.validate_ports_and_duplicates() else { return Ok(()); + }; + let ports: Vec<(NetInfoPurpose, u16)> = net_info + .purposes + .iter() + .flat_map(|(purpose, entries)| { + entries + .iter() + .filter_map(|entry| Some((*purpose, entry.port()?))) + }) + .collect(); + match error { + ExtNetInfoError::BadPort(port) => { + if let Some((purpose, _)) = ports.iter().find(|(_, listed)| *listed == port) { + return Err(PlatformWalletError::InvalidParameter(format!( + "Dash Core v24 refuses {purpose:?} port {port}, which this update would write \ + into the evonode's version-3 address map: ports 0 to 1023 (except 443 for \ + Platform HTTPS) and some well-known service ports are refused there; move \ + the service to another port and register it with Dash Core's `protx \ + update_service_evo`" + ))); + } + } + ExtNetInfoError::Duplicate => { + for (index, (purpose, port)) in ports.iter().enumerate() { + if let Some((other, _)) = ports[..index].iter().find(|(_, other)| other == port) { + return Err(PlatformWalletError::InvalidParameter(format!( + "{other:?} and {purpose:?} would both use port {port}, and Dash Core v24 \ + refuses a version-3 address map that lists the same address twice; give \ + each service its own port" + ))); + } + } + } + _ => {} } Err(PlatformWalletError::InvalidParameter(format!( - "Dash Core v24 refuses {purpose:?} port {port}, which this update would write into the \ - evonode's version-3 address map: ports 0 to 1023 (except 443 for Platform HTTPS) and \ - some well-known service ports are refused there; move the service to another port and \ - register it with Dash Core's `protx update_service_evo`" + "Dash Core v24 refuses the version-3 address map this update would write into the \ + evonode ({error}); register its addresses with Dash Core's `protx update_service_evo`" ))) } -/// Dash Core v24 refuses a version-3 address map that lists one address -/// twice (`ExtNetInfo::HasAddrPortDuplicates`, `bad-protx-dup-netinfo-entry`). -/// The conversion of a legacy evonode gives all its services the same IP, so -/// their ports must differ. -fn require_distinct_ports(ports: &[(NetInfoPurpose, u16)]) -> Result<(), PlatformWalletError> { - for (index, (purpose, port)) in ports.iter().enumerate() { - if let Some((other, _)) = ports[..index].iter().find(|(_, other)| other == port) { - return Err(PlatformWalletError::InvalidParameter(format!( - "{other:?} and {purpose:?} would both use port {port}, and Dash Core v24 refuses \ - a version-3 address map that lists the same address twice; give each service \ - its own port" - ))); - } - } - Ok(()) -} - /// The version-3 address map for a legacy evonode, as Dash Core's `protx /// update_service_evo` builds it from bare platform ports: the legacy /// address as CoreP2P, and its IP with each platform port as PlatformP2P