From c3c9daa22fa1df421708e58937a93f8186b0450c Mon Sep 17 00:00:00 2001 From: Steven Normore Date: Wed, 5 Jun 2024 18:33:57 -0400 Subject: [PATCH] feat(cli): config rpc and handshake http addrs with init flags --- core/cli/Cargo.toml | 4 ++-- core/cli/src/args.rs | 7 +++++++ core/cli/src/cli.rs | 4 ++++ core/cli/src/commands/init.rs | 23 +++++++++++++++++++++++ core/rpc/src/config.rs | 13 ++----------- 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/core/cli/Cargo.toml b/core/cli/Cargo.toml index 5727da259..8a27c6002 100644 --- a/core/cli/Cargo.toml +++ b/core/cli/Cargo.toml @@ -8,6 +8,8 @@ default-run = "lightning-node" [dependencies] lightning-application = { path = "../application" } +lightning-rpc = { path = "../rpc" } +lightning-handshake = { path = "../handshake" } lightning-ebpf-service = { path = "../../etc/ebpf/service" } lightning-interfaces = { path = "../interfaces" } lightning-node = { path = "../node" } @@ -41,7 +43,6 @@ serial_test = "3.0.0" lightning-syncronizer = { path = "../syncronizer" } lightning-broadcast = { path = "../broadcast" } lightning-consensus = { path = "../consensus" } -lightning-handshake = { path = "../handshake" } lightning-service-executor = { path = "../service-executor" } lightning-pool = { path = "../pool" } lightning-rep-collector = { path = "../rep-collector" } @@ -52,7 +53,6 @@ lightning-blockstore-server = { path = "../blockstore-server" } lightning-resolver = { path = "../resolver" } lightning-archive = { path = "../archive" } lightning-pinger = { path = "../pinger" } -lightning-rpc = { path = "../rpc" } fleek-blake3 = "1.5" assert_cmd = "2.0.14" tempdir.workspace = true diff --git a/core/cli/src/args.rs b/core/cli/src/args.rs index 82864333e..a04c8c744 100644 --- a/core/cli/src/args.rs +++ b/core/cli/src/args.rs @@ -1,3 +1,4 @@ +use std::net::SocketAddr; use std::path::PathBuf; use clap::{arg, ArgAction, Parser, Subcommand, ValueEnum}; @@ -59,6 +60,12 @@ pub enum Command { /// Whether to not apply gensis block during initialization. The default is to apply it. #[clap(long)] no_apply_genesis: bool, + /// Set RPC listen address in the generated configuration file. + #[clap(long)] + rpc_address: Option, + /// Set handshake HTTP listen address in the generated configuration file. + #[clap(long)] + handshake_http_address: Option, }, /// Key management utilities. #[command(subcommand)] diff --git a/core/cli/src/cli.rs b/core/cli/src/cli.rs index 354c2cbf3..4fe8e67a2 100644 --- a/core/cli/src/cli.rs +++ b/core/cli/src/cli.rs @@ -49,12 +49,16 @@ impl Cli { network, no_generate_keys, no_apply_genesis, + rpc_address, + handshake_http_address, } => { init::exec::( config_path, network.into(), no_generate_keys, no_apply_genesis, + rpc_address, + handshake_http_address, ) .await }, diff --git a/core/cli/src/commands/init.rs b/core/cli/src/commands/init.rs index decdec47c..17cacd36d 100644 --- a/core/cli/src/commands/init.rs +++ b/core/cli/src/commands/init.rs @@ -1,9 +1,14 @@ +use std::net::SocketAddr; + use anyhow::{anyhow, Context, Result}; use lightning_application::app::Application; use lightning_application::config::Config as AppConfig; use lightning_application::network::Network; use lightning_final_bindings::FinalTypes; +use lightning_handshake::config::HandshakeConfig; +use lightning_handshake::handshake::Handshake; use lightning_interfaces::prelude::*; +use lightning_rpc::{Config as RpcConfig, Rpc}; use lightning_utils::config::TomlConfigProvider; use resolved_pathbuf::ResolvedPathBuf; use tracing::info; @@ -13,6 +18,8 @@ pub async fn exec( network: Network, no_generate_keys: bool, no_apply_genesis: bool, + rpc_address: Option, + handshake_http_address: Option, ) -> Result<()> where C: Collection>, @@ -35,6 +42,22 @@ where ..Default::default() }); + // Update RPC address in the configuration if given. + if let Some(addr) = rpc_address { + config.inject::>(RpcConfig { + addr, + ..Default::default() + }); + } + + // Update handshake HTTP address in the configuration if given. + if let Some(addr) = handshake_http_address { + config.inject::>(HandshakeConfig { + http_address: addr, + ..Default::default() + }); + } + // Write the configuration file. config.write(&config_path)?; info!( diff --git a/core/rpc/src/config.rs b/core/rpc/src/config.rs index c5ef641a7..ee8b7d713 100644 --- a/core/rpc/src/config.rs +++ b/core/rpc/src/config.rs @@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Config { - addr: SocketAddr, - rpc_selection: RPCSelection, + pub addr: SocketAddr, + pub rpc_selection: RPCSelection, } impl Config { @@ -16,15 +16,6 @@ impl Config { } } - pub fn default_with_port_and_addr(addr: String, port: u16) -> Self { - Self { - addr: format!("{}:{}", addr, port) - .parse() - .expect("RPC Socket Addr to parse"), - rpc_selection: Default::default(), - } - } - pub fn default_with_port(port: u16) -> Self { Self { addr: format!("{}:{}", "0.0.0.0", port)