Skip to content

Commit

Permalink
feat(cli): config rpc and handshake http addrs with init flags
Browse files Browse the repository at this point in the history
  • Loading branch information
snormore committed Jun 5, 2024
1 parent 1773ded commit c3c9daa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
4 changes: 2 additions & 2 deletions core/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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" }
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions core/cli/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::net::SocketAddr;
use std::path::PathBuf;

use clap::{arg, ArgAction, Parser, Subcommand, ValueEnum};
Expand Down Expand Up @@ -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<SocketAddr>,
/// Set handshake HTTP listen address in the generated configuration file.
#[clap(long)]
handshake_http_address: Option<SocketAddr>,
},
/// Key management utilities.
#[command(subcommand)]
Expand Down
4 changes: 4 additions & 0 deletions core/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ impl Cli {
network,
no_generate_keys,
no_apply_genesis,
rpc_address,
handshake_http_address,
} => {
init::exec::<C>(
config_path,
network.into(),
no_generate_keys,
no_apply_genesis,
rpc_address,
handshake_http_address,
)
.await
},
Expand Down
23 changes: 23 additions & 0 deletions core/cli/src/commands/init.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,6 +18,8 @@ pub async fn exec<C>(
network: Network,
no_generate_keys: bool,
no_apply_genesis: bool,
rpc_address: Option<SocketAddr>,
handshake_http_address: Option<SocketAddr>,
) -> Result<()>
where
C: Collection<ConfigProviderInterface = TomlConfigProvider<C>>,
Expand All @@ -35,6 +42,22 @@ where
..Default::default()
});

// Update RPC address in the configuration if given.
if let Some(addr) = rpc_address {
config.inject::<Rpc<FinalTypes>>(RpcConfig {
addr,
..Default::default()
});
}

// Update handshake HTTP address in the configuration if given.
if let Some(addr) = handshake_http_address {
config.inject::<Handshake<FinalTypes>>(HandshakeConfig {
http_address: addr,
..Default::default()
});
}

// Write the configuration file.
config.write(&config_path)?;
info!(
Expand Down
13 changes: 2 additions & 11 deletions core/rpc/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit c3c9daa

Please sign in to comment.