Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support validators' hostnames in config #1886

Merged
merged 5 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Added support for validators' hostnames in configuration.
([\#1886](https://github.com/anoma/namada/pull/1886))
5 changes: 2 additions & 3 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2455,7 +2455,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;

Expand Down Expand Up @@ -2611,7 +2610,7 @@ pub mod args {
arg("max-commission-rate-change");
pub const MAX_ETH_GAS: ArgOpt<u64> = arg_opt("max_eth-gas");
pub const MODE: ArgOpt<String> = arg_opt("mode");
pub const NET_ADDRESS: Arg<SocketAddr> = arg("net-address");
pub const NET_ADDRESS: Arg<String> = arg("net-address");
pub const NAMADA_START_TIME: ArgOpt<DateTimeUtc> = arg_opt("time");
pub const NO_CONVERSIONS: ArgFlag = flag("no-conversions");
pub const NUT: ArgFlag = flag("nut");
Expand Down Expand Up @@ -5567,7 +5566,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,
}
Expand Down
7 changes: 3 additions & 4 deletions apps/src/lib/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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::<u16>().unwrap();
if localhost {
config.ledger.cometbft.p2p.laddr = TendermintAddress::from_str(
&format!("127.0.0.1:{}", first_port),
Expand Down Expand Up @@ -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()
},
)]),
Expand Down
3 changes: 1 addition & 2 deletions apps/src/lib/config/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion genesis/e2e-tests-single-node.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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"
Expand Down
11 changes: 3 additions & 8 deletions tests/src/e2e/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions tests/src/e2e/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<u16>().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);
}
Expand Down