Skip to content

dash: payload constructors, net-info conversions and service validation for provider update transactions #1450

Open

Description

@llbartekll

Problem

Platform's wallet builds ProUpRegTx and ProUpServTx in rs-platform-wallet (masternode/update_registrar.rs, masternode/update_service.rs). Next to the wallet work (choosing keys, reading the masternode list over SPV, funding), that code restates Dash Core rules that no wallet owns. dashcore has the payload types, but not the rules around them:

  • Net-info entry to socket address. MasternodeListEntry::primary_service_address converts in a private closure, so the wallet keeps its own copy.
  • The version-3 address map of an evonode built from one address and the two Platform ports, as protx update_service_evo builds it.
  • Which payload version and address form Core accepts for a masternode type and V24 state. CURRENT_VERSION is 2 on both update payloads, so every caller chooses version 3 and the ExtNetInfo form itself. Platform does it in two builders.
  • Service validation as in MnNetInfo::ValidateService and CheckProviderNetworkFields: IPv4 only, routable outside regtest, the mainnet port rules, distinct Platform ports, a non-zero node id.
  • Which entry ExtNetInfo::validate_ports_and_duplicates refused. ExtNetInfoError::Duplicate and BadPort(u16) do not name the purpose, so the wallet searches the map by port to write a usable error.
  • Whether V24 is active, read from a coinbase payload's version.
  • Uniqueness against the masternode list (bad-protx-dup-netinfo-entry, bad-protx-dup-platformnodeid, bad-protx-dup-key). MasternodeList::has_masternode_at_location answers yes or no for one address and port; the checks need the holder, an entry to leave out, every purpose of a version-3 map, the Platform node id, and the operator key under either BLS scheme.
  • Payload signing and the ProUpRegTx payee and collateral checks (bad-protx-payee, bad-protx-payee-reuse, bad-protx-collateral-reuse).

This came up in review of dashpay/platform#5889: a second consumer would have to write all of it again.

Proposal

A sketch; names are open. Line references are to rev 6b985d1.

Net-info conversions (dash/src/sml/masternode_list_entry/net_info.rs):

impl NetInfoEntry {
    /// IPv4/IPv6 service entry as a socket address; None for Tor/I2P/CJDNS, a domain, or an invalid entry.
    pub fn socket_addr(&self) -> Option<SocketAddr>;
    /// A service entry for `addr`; an IPv4-mapped IPv6 address is written as IPv4.
    pub fn service(addr: SocketAddr) -> Self;
}
impl ExtNetInfo {
    /// The map `protx update_service_evo` builds from bare ports, purposes ascending.
    pub fn for_legacy_evonode(service: SocketAddr, platform_p2p_port: u16, platform_http_port: u16) -> Self;
    /// The map of a regular masternode with one Core P2P address.
    pub fn for_core_p2p(service: SocketAddr) -> Self;
    pub fn socket_addrs(&self) -> impl Iterator<Item = SocketAddr> + '_;
}
impl MasternodeNetInfo {
    pub fn socket_addrs(&self) -> Vec<SocketAddr>;
}

Errors that name the refused entry:

pub enum ExtNetInfoError {
    Duplicate { purpose: NetInfoPurpose, other: NetInfoPurpose, port: u16 },
    BadPort { purpose: NetInfoPurpose, port: u16 },
}

Chain parameters (dash-network, next to Network::default_p2p_port); 443 exists today as the private PLATFORM_HTTPS_PORT in net_info.rs:

impl Network {
    pub const fn default_platform_p2p_port(self) -> Option<u16>;  // 26656 on mainnet
    pub const fn default_platform_http_port(self) -> Option<u16>; // 443 on mainnet
}

Service values and the ProUpServTx payload (provider_update_service.rs):

pub struct ProviderServiceValues {
    pub service: SocketAddr,
    pub platform: Option<PlatformServiceValues>, // node id, P2P port, HTTP port: all or none
}
pub enum ProviderServiceError { /* one variant per Core reject reason */ }

impl ProviderServiceValues {
    /// MnNetInfo::ValidateService and CheckProviderNetworkFields.
    pub fn validate(&self, network: Network) -> Result<(), ProviderServiceError>;
}
impl ProviderUpdateServicePayload {
    /// The lowest version Core accepts for this masternode type and V24 state, with the matching
    /// address form: version 3 and an ExtNetInfo map for an evonode once V24 is active or for an
    /// entry already at version 3, otherwise version 2 with the legacy address and scalar ports.
    pub fn unsigned(
        pro_tx_hash: Txid,
        mn_type: ProviderMasternodeType,
        values: &ProviderServiceValues,
        entry_is_ext_addr: bool,
        v24_active: bool,
        script_payout: ScriptBuf,
    ) -> Result<Self, ProviderServiceError>;
    /// CheckProUpServTx after V24: an evonode update below version 3 is refused.
    pub fn refused_after_v24(&self) -> bool;
    /// Behind the `bls` feature.
    pub fn sign(&mut self, inputs_hash: InputsHash, operator_secret: &[u8; 32]) -> Result<(), /* .. */>;
}

/// CNetAddr::IsRoutable, IPv4 arm.
pub fn ipv4_is_routable(ip: Ipv4Addr) -> bool;

The ProUpRegTx payload (provider_update_registrar.rs):

impl ProviderUpdateRegistrarPayload {
    pub fn sign(&mut self, inputs_hash: InputsHash, owner: &EcdsaSecretKey, compressed: bool);
    /// CheckProUpRegTx: bad-protx-payee, bad-protx-payee-reuse, bad-protx-collateral-reuse.
    pub fn check_payee_and_collateral(
        &self,
        owner_key_hash: &PubkeyHash,
        collateral_script: &Script,
    ) -> Result<(), /* .. */>;
}

V24 from a coinbase payload (coinbase.rs):

impl CoinbasePayload {
    pub const V24_VERSION: u16 = 4;
    /// CheckCbTx: the version is 4 or higher exactly while DEPLOYMENT_V24 is active.
    pub fn shows_v24(&self) -> bool;
}

Uniqueness queries (dash/src/sml/masternode_list):

impl MasternodeList {
    pub fn socket_addr_holder(&self, addr: &SocketAddr, except: &ProTxHash) -> Option<&ProTxHash>;
    pub fn platform_node_id_holder(&self, id: &PlatformNodeId, except: &ProTxHash) -> Option<&ProTxHash>;
    /// Under either BLS scheme.
    pub fn operator_key_holder(&self, key: &BLSPublicKey, except: &ProTxHash) -> Option<&ProTxHash>;
}

Relation to #1401

#1401 asks for typed key-wallet builders for these two transactions: the finalizer and the rule that the transaction always carries an output. The API here is the dashcore layer those builders would call. The output rule stays in #1401.

Out of scope

What stays with the consumer: choosing which wallet keys to rotate to, reading the masternode list and the coinbase over SPV, fetching the registration transaction, reservations and broadcast.

Order

The conversions and ProviderUpdateServicePayload::unsigned come first: they remove the version and address-form choice Platform now makes in two builders. ProviderServiceValues::validate with the port parameters is next, then the error detail. The rest is independent.

Context

The Core function and reject names above are the ones the wallet code was written against (Dash Core v24). They should be checked against Dash Core when this is implemented.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions