Skip to content

Commit c3c9daa

Browse files
committed
feat(cli): config rpc and handshake http addrs with init flags
1 parent 1773ded commit c3c9daa

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

core/cli/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ default-run = "lightning-node"
88

99
[dependencies]
1010
lightning-application = { path = "../application" }
11+
lightning-rpc = { path = "../rpc" }
12+
lightning-handshake = { path = "../handshake" }
1113
lightning-ebpf-service = { path = "../../etc/ebpf/service" }
1214
lightning-interfaces = { path = "../interfaces" }
1315
lightning-node = { path = "../node" }
@@ -41,7 +43,6 @@ serial_test = "3.0.0"
4143
lightning-syncronizer = { path = "../syncronizer" }
4244
lightning-broadcast = { path = "../broadcast" }
4345
lightning-consensus = { path = "../consensus" }
44-
lightning-handshake = { path = "../handshake" }
4546
lightning-service-executor = { path = "../service-executor" }
4647
lightning-pool = { path = "../pool" }
4748
lightning-rep-collector = { path = "../rep-collector" }
@@ -52,7 +53,6 @@ lightning-blockstore-server = { path = "../blockstore-server" }
5253
lightning-resolver = { path = "../resolver" }
5354
lightning-archive = { path = "../archive" }
5455
lightning-pinger = { path = "../pinger" }
55-
lightning-rpc = { path = "../rpc" }
5656
fleek-blake3 = "1.5"
5757
assert_cmd = "2.0.14"
5858
tempdir.workspace = true

core/cli/src/args.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::net::SocketAddr;
12
use std::path::PathBuf;
23

34
use clap::{arg, ArgAction, Parser, Subcommand, ValueEnum};
@@ -59,6 +60,12 @@ pub enum Command {
5960
/// Whether to not apply gensis block during initialization. The default is to apply it.
6061
#[clap(long)]
6162
no_apply_genesis: bool,
63+
/// Set RPC listen address in the generated configuration file.
64+
#[clap(long)]
65+
rpc_address: Option<SocketAddr>,
66+
/// Set handshake HTTP listen address in the generated configuration file.
67+
#[clap(long)]
68+
handshake_http_address: Option<SocketAddr>,
6269
},
6370
/// Key management utilities.
6471
#[command(subcommand)]

core/cli/src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,16 @@ impl Cli {
4949
network,
5050
no_generate_keys,
5151
no_apply_genesis,
52+
rpc_address,
53+
handshake_http_address,
5254
} => {
5355
init::exec::<C>(
5456
config_path,
5557
network.into(),
5658
no_generate_keys,
5759
no_apply_genesis,
60+
rpc_address,
61+
handshake_http_address,
5862
)
5963
.await
6064
},

core/cli/src/commands/init.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
use std::net::SocketAddr;
2+
13
use anyhow::{anyhow, Context, Result};
24
use lightning_application::app::Application;
35
use lightning_application::config::Config as AppConfig;
46
use lightning_application::network::Network;
57
use lightning_final_bindings::FinalTypes;
8+
use lightning_handshake::config::HandshakeConfig;
9+
use lightning_handshake::handshake::Handshake;
610
use lightning_interfaces::prelude::*;
11+
use lightning_rpc::{Config as RpcConfig, Rpc};
712
use lightning_utils::config::TomlConfigProvider;
813
use resolved_pathbuf::ResolvedPathBuf;
914
use tracing::info;
@@ -13,6 +18,8 @@ pub async fn exec<C>(
1318
network: Network,
1419
no_generate_keys: bool,
1520
no_apply_genesis: bool,
21+
rpc_address: Option<SocketAddr>,
22+
handshake_http_address: Option<SocketAddr>,
1623
) -> Result<()>
1724
where
1825
C: Collection<ConfigProviderInterface = TomlConfigProvider<C>>,
@@ -35,6 +42,22 @@ where
3542
..Default::default()
3643
});
3744

45+
// Update RPC address in the configuration if given.
46+
if let Some(addr) = rpc_address {
47+
config.inject::<Rpc<FinalTypes>>(RpcConfig {
48+
addr,
49+
..Default::default()
50+
});
51+
}
52+
53+
// Update handshake HTTP address in the configuration if given.
54+
if let Some(addr) = handshake_http_address {
55+
config.inject::<Handshake<FinalTypes>>(HandshakeConfig {
56+
http_address: addr,
57+
..Default::default()
58+
});
59+
}
60+
3861
// Write the configuration file.
3962
config.write(&config_path)?;
4063
info!(

core/rpc/src/config.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize};
44

55
#[derive(Debug, Clone, Serialize, Deserialize)]
66
pub struct Config {
7-
addr: SocketAddr,
8-
rpc_selection: RPCSelection,
7+
pub addr: SocketAddr,
8+
pub rpc_selection: RPCSelection,
99
}
1010

1111
impl Config {
@@ -16,15 +16,6 @@ impl Config {
1616
}
1717
}
1818

19-
pub fn default_with_port_and_addr(addr: String, port: u16) -> Self {
20-
Self {
21-
addr: format!("{}:{}", addr, port)
22-
.parse()
23-
.expect("RPC Socket Addr to parse"),
24-
rpc_selection: Default::default(),
25-
}
26-
}
27-
2819
pub fn default_with_port(port: u16) -> Self {
2920
Self {
3021
addr: format!("{}:{}", "0.0.0.0", port)

0 commit comments

Comments
 (0)