mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add with-unused-ports cli argument (#6314)
This commit is contained in:
@ -77,6 +77,13 @@ pub struct NodeCommand<Ext: RethCliExt = ()> {
|
||||
#[arg(long, value_name = "INSTANCE", global = true, default_value_t = 1, value_parser = value_parser!(u16).range(..=200))]
|
||||
pub instance: u16,
|
||||
|
||||
/// Sets all ports to unused, allowing the OS to choose random unused ports when sockets are
|
||||
/// bound.
|
||||
///
|
||||
/// Mutually exclusive with `--instance`.
|
||||
#[arg(long, conflicts_with = "instance", global = true)]
|
||||
pub with_unused_ports: bool,
|
||||
|
||||
/// Overrides the KZG trusted setup by reading from the supplied file.
|
||||
#[arg(long, value_name = "PATH")]
|
||||
pub trusted_setup_file: Option<PathBuf>,
|
||||
@ -134,6 +141,7 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
|
||||
metrics,
|
||||
trusted_setup_file,
|
||||
instance,
|
||||
with_unused_ports,
|
||||
network,
|
||||
rpc,
|
||||
txpool,
|
||||
@ -152,6 +160,7 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
|
||||
chain,
|
||||
metrics,
|
||||
instance,
|
||||
with_unused_ports,
|
||||
trusted_setup_file,
|
||||
network,
|
||||
rpc,
|
||||
@ -176,6 +185,7 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
|
||||
metrics,
|
||||
trusted_setup_file,
|
||||
instance,
|
||||
with_unused_ports,
|
||||
network,
|
||||
rpc,
|
||||
txpool,
|
||||
@ -193,7 +203,7 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
|
||||
let database = DatabaseBuilder::Real(datadir);
|
||||
|
||||
// set up node config
|
||||
let node_config = NodeConfig {
|
||||
let mut node_config = NodeConfig {
|
||||
database,
|
||||
config,
|
||||
chain,
|
||||
@ -212,6 +222,10 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
|
||||
rollup,
|
||||
};
|
||||
|
||||
if with_unused_ports {
|
||||
node_config = node_config.with_unused_ports();
|
||||
}
|
||||
|
||||
let executor = ctx.task_executor;
|
||||
|
||||
// launch the node
|
||||
@ -390,4 +404,37 @@ mod tests {
|
||||
// check network listening port number
|
||||
assert_eq!(cmd.network.port, 30305);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_with_unused_ports() {
|
||||
let cmd = NodeCommand::<()>::parse_from(["reth", "--with-unused-ports"]);
|
||||
assert!(cmd.with_unused_ports);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_unused_ports_conflicts_with_instance() {
|
||||
let err =
|
||||
NodeCommand::<()>::try_parse_from(["reth", "--with-unused-ports", "--instance", "2"])
|
||||
.unwrap_err();
|
||||
assert_eq!(err.kind(), clap::error::ErrorKind::ArgumentConflict);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_unused_ports_check_zero() {
|
||||
let mut cmd = NodeCommand::<()>::parse_from(["reth"]);
|
||||
cmd.rpc = cmd.rpc.with_unused_ports();
|
||||
cmd.network = cmd.network.with_unused_ports();
|
||||
|
||||
// make sure the rpc ports are zero
|
||||
assert_eq!(cmd.rpc.auth_port, 0);
|
||||
assert_eq!(cmd.rpc.http_port, 0);
|
||||
assert_eq!(cmd.rpc.ws_port, 0);
|
||||
|
||||
// make sure the network ports are zero
|
||||
assert_eq!(cmd.network.port, 0);
|
||||
assert_eq!(cmd.network.discovery.port, 0);
|
||||
|
||||
// make sure the ipc path is not the default
|
||||
assert_ne!(cmd.rpc.ipcpath, String::from("/tmp/reth.ipc"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user