From 624488d9a0f9cabca194a1ba3b431077debeb6dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksandar=20Terenti=C4=87?= Date: Wed, 4 Sep 2024 18:47:27 +0200 Subject: [PATCH] Remove obsolete LightClientConfig --- client/src/config.rs | 14 ++------------ client/src/main.rs | 6 ++++-- core/src/app_client.rs | 6 ++++-- core/src/light_client.rs | 18 +++++++++--------- core/src/sync_client.rs | 6 ++++-- core/src/types.rs | 15 --------------- 6 files changed, 23 insertions(+), 42 deletions(-) diff --git a/client/src/config.rs b/client/src/config.rs index 495292cff..85c6a851f 100644 --- a/client/src/config.rs +++ b/client/src/config.rs @@ -5,8 +5,8 @@ use avail_light_core::{ network::{p2p::configuration::LibP2PConfig, rpc::configuration::RPCConfig}, telemetry::otlp::OtelConfig, types::{ - option_duration_seconds_format, tracing_level_format, AppClientConfig, Delay, - LightClientConfig, MaintenanceConfig, Origin, SyncClientConfig, + option_duration_seconds_format, tracing_level_format, AppClientConfig, MaintenanceConfig, + Origin, SyncClientConfig, }, }; use serde::{Deserialize, Serialize}; @@ -57,16 +57,6 @@ pub struct RuntimeConfig { pub client_alias: Option, } -impl From<&RuntimeConfig> for LightClientConfig { - fn from(val: &RuntimeConfig) -> Self { - let block_processing_delay = val.block_processing_delay; - LightClientConfig { - confidence: val.confidence, - block_processing_delay: Delay(block_processing_delay), - } - } -} - impl From<&RuntimeConfig> for SyncClientConfig { fn from(val: &RuntimeConfig) -> Self { SyncClientConfig { diff --git a/client/src/main.rs b/client/src/main.rs index f8c03a036..56c572440 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -16,7 +16,8 @@ use avail_light_core::{ sync_finality::SyncFinality, telemetry::{self, MetricCounter, Metrics}, types::{ - load_or_init_suri, IdentityConfig, MaintenanceConfig, MultiaddrConfig, SecretKey, Uuid, + load_or_init_suri, Delay, IdentityConfig, MaintenanceConfig, MultiaddrConfig, SecretKey, + Uuid, }, utils::{default_subscriber, install_panic_hooks, json_subscriber, spawn_in_span}, }; @@ -309,7 +310,8 @@ async fn run( spawn_in_span(shutdown.with_cancel(light_client::run( db.clone(), light_network_client, - (&cfg).into(), + cfg.confidence, + Delay(cfg.block_processing_delay), ot_metrics.clone(), channels, shutdown.clone(), diff --git a/core/src/app_client.rs b/core/src/app_client.rs index f7a69013a..79674076a 100644 --- a/core/src/app_client.rs +++ b/core/src/app_client.rs @@ -524,8 +524,10 @@ mod tests { #[tokio::test] async fn test_process_blocks_without_rpc() { - let mut cfg = AppClientConfig::default(); - cfg.disable_rpc = true; + let cfg = AppClientConfig { + disable_rpc: true, + ..Default::default() + }; let pp = Arc::new(testnet::public_params(1024)); let dimensions: Dimensions = Dimensions::new(1, 128).unwrap(); let mut mock_client = MockClient::new(); diff --git a/core/src/light_client.rs b/core/src/light_client.rs index fdde341e1..93eacbae0 100644 --- a/core/src/light_client.rs +++ b/core/src/light_client.rs @@ -36,7 +36,7 @@ use crate::{ }, shutdown::Controller, telemetry::{MetricCounter, MetricValue, Metrics}, - types::{self, BlockRange, ClientChannels, LightClientConfig}, + types::{self, BlockRange, ClientChannels, Delay}, utils::{calculate_confidence, extract_kate}, }; @@ -58,7 +58,7 @@ pub async fn process_block( db: impl Database, network_client: &impl network::Client, metrics: &Arc, - cfg: &LightClientConfig, + confidence: f64, header: AvailHeader, received_at: Instant, event_sender: mpsc::Sender, @@ -107,7 +107,7 @@ pub async fn process_block( } let commitments = commitments::from_slice(&commitment)?; - let cell_count = rpc::cell_count_for_confidence(cfg.confidence); + let cell_count = rpc::cell_count_for_confidence(confidence); let positions = rpc::generate_random_cells(dimensions, cell_count); info!( block_number, @@ -218,15 +218,16 @@ pub async fn process_block( /// # Arguments /// /// * `light_client` - Light client implementation -/// * `cfg` - Light client configuration /// * `metrics` - Metrics registry /// * `state` - Processed blocks state /// * `channels` - Communication channels /// * `shutdown` - Shutdown controller +#[allow(clippy::too_many_arguments)] pub async fn run( db: impl Database + Clone, network_client: impl network::Client, - cfg: LightClientConfig, + confidence: f64, + block_processing_delay: Delay, metrics: Arc, mut channels: ClientChannels, shutdown: Controller, @@ -249,7 +250,7 @@ pub async fn run( }, }; - if let Some(seconds) = cfg.block_processing_delay.sleep_duration(received_at) { + if let Some(seconds) = block_processing_delay.sleep_duration(received_at) { metrics .record(MetricValue::BlockProcessingDelay(seconds.as_secs_f64())) .await; @@ -269,7 +270,7 @@ pub async fn run( db.clone(), &network_client, &metrics, - &cfg, + confidence, header.clone(), received_at, event_sender, @@ -338,7 +339,6 @@ mod tests { async fn test_process_block_with_rpc() { let mut mock_network_client = network::MockClient::new(); let db = data::MemoryDB::default(); - let cfg = LightClientConfig::default(); let cells_fetched: Vec = vec![]; let cells_unfetched = [ Position { row: 1, col: 3 }, @@ -402,7 +402,7 @@ mod tests { db, &mock_network_client, &Arc::new(tests::MockMetrics {}), - &cfg, + 99.9, header, recv, sender, diff --git a/core/src/sync_client.rs b/core/src/sync_client.rs index 54c379799..083d8e9b5 100644 --- a/core/src/sync_client.rs +++ b/core/src/sync_client.rs @@ -315,8 +315,10 @@ mod tests { #[tokio::test] pub async fn test_process_blocks_without_rpc() { let (block_tx, _) = broadcast::channel::(10); - let mut cfg = SyncClientConfig::default(); - cfg.disable_rpc = true; + let cfg = SyncClientConfig { + disable_rpc: true, + ..Default::default() + }; let mut mock_network_client = network::MockClient::new(); let mut mock_client = MockClient::new(); let header = default_header(); diff --git a/core/src/types.rs b/core/src/types.rs index bdba1e799..8ed71fda1 100644 --- a/core/src/types.rs +++ b/core/src/types.rs @@ -353,21 +353,6 @@ pub enum SecretKey { pub struct Delay(pub Option); -/// Light client configuration (see [RuntimeConfig] for details) -pub struct LightClientConfig { - pub confidence: f64, - pub block_processing_delay: Delay, -} - -impl Default for LightClientConfig { - fn default() -> Self { - Self { - confidence: 99.9, - block_processing_delay: Delay(Some(Duration::from_secs(20))), - } - } -} - impl Delay { pub fn sleep_duration(&self, from: Instant) -> Option { (self.0?)