From 0345033a99bbe398b1fa6b41e3bde2397434b64c Mon Sep 17 00:00:00 2001 From: Ljubisa Isakovic <93769705+sh3ll3x3c@users.noreply.github.com> Date: Wed, 11 Sep 2024 12:45:17 +0200 Subject: [PATCH] re-add fat client CLI options (#696) --- fat/src/config.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++++- fat/src/main.rs | 27 ++++++++++++++++++++++----- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/fat/src/config.rs b/fat/src/config.rs index f28efee11..00ef35d14 100644 --- a/fat/src/config.rs +++ b/fat/src/config.rs @@ -1,6 +1,7 @@ use std::{fs, time::Duration}; use avail_light_core::{ + api::configuration::APIConfig, fat_client, network::{ p2p::{configuration::LibP2PConfig, BOOTSTRAP_LIST_EMPTY_MESSAGE}, @@ -10,7 +11,7 @@ use avail_light_core::{ telemetry::otlp::OtelConfig, types::{ block_matrix_partition_format, option_duration_seconds_format, tracing_level_format, - MultiaddrConfig, + MultiaddrConfig, SecretKey, }, }; use avail_rust::kate_recovery::matrix::Partition; @@ -40,6 +41,21 @@ pub struct CliOpts { /// fraction and number of the block matrix part to fetch (e.g. 2/20 means second 1/20 part of a matrix) (default: None) #[arg(long, value_parser = block_matrix_partition_format::parse)] pub block_matrix_partition: Option, + /// Seed string for libp2p keypair generation + #[arg(long)] + pub seed: Option, + /// P2P port + #[arg(short, long)] + pub port: Option, + /// Set client alias for use in logs and metrics + #[arg(long)] + pub client_alias: Option, + /// Path to the avail_path, where RocksDB stores its data + #[arg(long)] + pub avail_path: Option, + /// HTTP port + #[arg(long)] + pub http_server_port: Option, } #[derive(Debug, Serialize, Deserialize)] @@ -67,6 +83,8 @@ pub struct Config { pub otel: OtelConfig, #[serde(flatten)] pub fat: fat_client::Config, + #[serde(flatten)] + pub api: APIConfig, } impl Default for Config { @@ -82,6 +100,7 @@ impl Default for Config { otel: Default::default(), fat: Default::default(), block_processing_delay: Some(Duration::from_secs(20)), + api: Default::default(), } } } @@ -106,6 +125,32 @@ pub fn load(opts: &CliOpts) -> Result { config.genesis_hash = network.genesis_hash().to_string(); } + if let Some(seed) = &opts.seed { + config.libp2p.secret_key = Some(SecretKey::Seed { + seed: seed.to_string(), + }) + } + + if let Some(port) = opts.port { + config.libp2p.port = port; + } + + if let Some(client_alias) = &opts.client_alias { + config.client_alias = client_alias.clone() + } + + if let Some(avail_path) = &opts.avail_path { + config.avail_path = avail_path.to_string(); + } + + if let Some(http_port) = opts.http_server_port { + config.api.http_server_port = http_port; + } + + if let Some(http_port) = opts.http_server_port { + config.api.http_server_port = http_port; + } + if config.libp2p.bootstraps.is_empty() { return Err(eyre!("{BOOTSTRAP_LIST_EMPTY_MESSAGE}")); } diff --git a/fat/src/main.rs b/fat/src/main.rs index 36fe0f590..95625bfe7 100644 --- a/fat/src/main.rs +++ b/fat/src/main.rs @@ -1,4 +1,6 @@ use avail_light_core::{ + api::{self, configuration::SharedConfig}, + consts::EXPECTED_SYSTEM_VERSION, data::{Database, LatestHeaderKey, DB}, fat_client::{self, OutputEvent as FatEvent}, network::{ @@ -7,7 +9,7 @@ use avail_light_core::{ }, shutdown::Controller, telemetry::{self, MetricCounter, MetricValue, Metrics}, - types::{BlockVerified, ClientChannels, KademliaMode, Origin}, + types::{BlockVerified, ClientChannels, IdentityConfig, KademliaMode, Origin}, utils::{default_subscriber, install_panic_hooks, json_subscriber, spawn_in_span}, }; use clap::Parser; @@ -78,6 +80,9 @@ async fn run(config: Config, db: DB, shutdown: Controller) -> Result<()> let partition = config.fat.block_matrix_partition; let partition_size = format!("{}/{}", partition.number, partition.fraction); + // TODO: Remove once the P2P API is decoupled + let identity_cfg = IdentityConfig::from_suri("//Alice".to_string(), None)?; + let metric_attributes = vec![ ("role", "fat".to_string()), ("version", version.to_string()), @@ -111,10 +116,7 @@ async fn run(config: Config, db: DB, shutdown: Controller) -> Result<()> spawn_in_span(shutdown.with_cancel(p2p_event_loop.run())); - let addrs = vec![ - config.libp2p.tcp_multiaddress(), - config.libp2p.webrtc_multiaddress(), - ]; + let addrs = vec![config.libp2p.tcp_multiaddress()]; p2p_client .start_listening(addrs) @@ -184,6 +186,21 @@ async fn run(config: Config, db: DB, shutdown: Controller) -> Result<()> rpc_event_receiver: client_rpc_event_receiver, }; + let ws_clients = api::v2::types::WsClients::default(); + + let server = api::server::Server { + db: db.clone(), + cfg: SharedConfig::default(), + identity_cfg, + version: format!("v{}", clap::crate_version!()), + network_version: EXPECTED_SYSTEM_VERSION[0].to_string(), + node_client: rpc_client.clone(), + ws_clients: ws_clients.clone(), + shutdown: shutdown.clone(), + p2p_client: p2p_client.clone(), + }; + spawn_in_span(shutdown.with_cancel(server.bind(config.api.clone()))); + let fat_client = fat_client::new(p2p_client.clone(), rpc_client.clone()); let (fat_sender, fat_receiver) = mpsc::unbounded_channel::(); let fat = spawn_in_span(shutdown.with_cancel(fat_client::run(