diff --git a/.changelog/unreleased/improvements/1886-validators-by-hostnames.md b/.changelog/unreleased/improvements/1886-validators-by-hostnames.md new file mode 100644 index 0000000000..fc96da016e --- /dev/null +++ b/.changelog/unreleased/improvements/1886-validators-by-hostnames.md @@ -0,0 +1,2 @@ +- Added support for validators' hostnames in configuration. + ([\#1886](https://github.com/anoma/namada/pull/1886)) \ No newline at end of file diff --git a/apps/src/lib/cli.rs b/apps/src/lib/cli.rs index 4d760d60c1..70cba50687 100644 --- a/apps/src/lib/cli.rs +++ b/apps/src/lib/cli.rs @@ -2457,7 +2457,6 @@ pub mod args { use std::collections::HashMap; use std::convert::TryFrom; use std::env; - use std::net::SocketAddr; use std::path::PathBuf; use std::str::FromStr; @@ -2621,7 +2620,7 @@ pub mod args { arg("max-commission-rate-change"); pub const MAX_ETH_GAS: ArgOpt = arg_opt("max_eth-gas"); pub const MODE: ArgOpt = arg_opt("mode"); - pub const NET_ADDRESS: Arg = arg("net-address"); + pub const NET_ADDRESS: Arg = arg("net-address"); pub const NAMADA_START_TIME: ArgOpt = arg_opt("time"); pub const NO_CONVERSIONS: ArgFlag = flag("no-conversions"); pub const NUT: ArgFlag = flag("nut"); @@ -5577,7 +5576,7 @@ pub mod args { pub alias: String, pub commission_rate: Dec, pub max_commission_rate_change: Dec, - pub net_address: SocketAddr, + pub net_address: String, pub unsafe_dont_encrypt: bool, pub key_scheme: SchemeType, } diff --git a/apps/src/lib/client/utils.rs b/apps/src/lib/client/utils.rs index 0eedb23968..2bf3f23ab0 100644 --- a/apps/src/lib/client/utils.rs +++ b/apps/src/lib/client/utils.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; use std::env; use std::fs::{self, File, OpenOptions}; use std::io::Write; -use std::net::SocketAddr; use std::path::{Path, PathBuf}; use std::str::FromStr; @@ -799,8 +798,8 @@ pub fn init_network( config.ledger.cometbft.p2p.addr_book_strict = !localhost; // Clear the net address from the config and use it to set ports let net_address = validator_config.net_address.take().unwrap(); - let _ip = SocketAddr::from_str(&net_address).unwrap().ip(); - let first_port = SocketAddr::from_str(&net_address).unwrap().port(); + let split: Vec<&str> = net_address.split(':').collect(); + let first_port = split[1].parse::().unwrap(); if localhost { config.ledger.cometbft.p2p.laddr = TendermintAddress::from_str( &format!("127.0.0.1:{}", first_port), @@ -1050,7 +1049,7 @@ pub fn init_genesis_validator( tendermint_node_key: Some(HexString( pre_genesis.tendermint_node_key.ref_to().to_string(), )), - net_address: Some(net_address.to_string()), + net_address: Some(net_address), ..Default::default() }, )]), diff --git a/apps/src/lib/config/utils.rs b/apps/src/lib/config/utils.rs index ca038dcb42..03725d112c 100644 --- a/apps/src/lib/config/utils.rs +++ b/apps/src/lib/config/utils.rs @@ -47,8 +47,7 @@ fn num_of_threads_aux( } } -// fixme: Handle this gracefully with either an Option or a Result. Ensure that -// hostname resolution works. +// FIXME: Handle this gracefully with either an Option or a Result. pub fn convert_tm_addr_to_socket_addr( tm_addr: &TendermintAddress, ) -> SocketAddr { diff --git a/genesis/e2e-tests-single-node.toml b/genesis/e2e-tests-single-node.toml index 5419429563..dbf8c1ea76 100644 --- a/genesis/e2e-tests-single-node.toml +++ b/genesis/e2e-tests-single-node.toml @@ -16,7 +16,7 @@ validator_vp = "vp_validator" commission_rate = "0.05" # Maximum change per epoch in the commission rate max_commission_rate_change = "0.01" -# Public IP:port address. +# (Public IP | Hostname):port address. # We set the port to be the default+1000, so that if a local node was running at # the same time as the E2E tests, it wouldn't affect them. net_address = "127.0.0.1:27656" diff --git a/tests/src/e2e/helpers.rs b/tests/src/e2e/helpers.rs index e2d887b5a2..5e4edce6aa 100644 --- a/tests/src/e2e/helpers.rs +++ b/tests/src/e2e/helpers.rs @@ -167,14 +167,9 @@ pub fn get_actor_rpc(test: &Test, who: &Who) -> String { }; let config = Config::load(base_dir, &test.net.chain_id, Some(tendermint_mode)); - let ip = convert_tm_addr_to_socket_addr(&config.ledger.cometbft.rpc.laddr) - .ip() - .to_string(); - let port = - convert_tm_addr_to_socket_addr(&config.ledger.cometbft.rpc.laddr) - .port() - .to_string(); - format!("{}:{}", ip, port) + let socket_addr = + convert_tm_addr_to_socket_addr(&config.ledger.cometbft.rpc.laddr); + format!("{}:{}", socket_addr.ip(), socket_addr.port()) } /// Get the public key of the validator diff --git a/tests/src/e2e/setup.rs b/tests/src/e2e/setup.rs index eecc60588f..9a58230072 100644 --- a/tests/src/e2e/setup.rs +++ b/tests/src/e2e/setup.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; use std::ffi::OsStr; use std::fmt::Display; use std::fs::{File, OpenOptions}; -use std::net::SocketAddr; use std::path::{Path, PathBuf}; use std::process::Command; use std::str::FromStr; @@ -122,17 +121,17 @@ where let validator_0 = genesis.validator.get_mut("validator-0").unwrap(); // Clone the first validator before modifying it let other_validators = validator_0.clone(); - let net_address_0 = - SocketAddr::from_str(validator_0.net_address.as_ref().unwrap()) - .unwrap(); - let net_address_port_0 = net_address_0.port(); + let validator_0_target = validator_0.net_address.clone().unwrap(); + let split: Vec<&str> = validator_0_target.split(':').collect(); + let (net_target_0, net_address_port_0) = + (split[0], split[1].parse::().unwrap()); for ix in 0..num { let mut validator = other_validators.clone(); - let mut net_address = net_address_0; + let mut net_target = net_target_0.to_string(); // 6 ports for each validator let first_port = net_address_port_0 + port_offset(ix); - net_address.set_port(first_port); - validator.net_address = Some(net_address.to_string()); + net_target = format!("{}:{}", net_target, first_port); + validator.net_address = Some(net_target.to_string()); let name = format!("validator-{}", ix); genesis.validator.insert(name, validator); }