Skip to content

Commit

Permalink
Remove obsolete LightClientConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
aterentic-ethernal committed Sep 5, 2024
1 parent 1cf94d7 commit 624488d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 42 deletions.
14 changes: 2 additions & 12 deletions client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -57,16 +57,6 @@ pub struct RuntimeConfig {
pub client_alias: Option<String>,
}

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 {
Expand Down
6 changes: 4 additions & 2 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 4 additions & 2 deletions core/src/app_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 9 additions & 9 deletions core/src/light_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand All @@ -58,7 +58,7 @@ pub async fn process_block(
db: impl Database,
network_client: &impl network::Client,
metrics: &Arc<impl Metrics>,
cfg: &LightClientConfig,
confidence: f64,
header: AvailHeader,
received_at: Instant,
event_sender: mpsc::Sender<OutputEvent>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<impl Metrics>,
mut channels: ClientChannels,
shutdown: Controller<String>,
Expand All @@ -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;
Expand All @@ -269,7 +270,7 @@ pub async fn run(
db.clone(),
&network_client,
&metrics,
&cfg,
confidence,
header.clone(),
received_at,
event_sender,
Expand Down Expand Up @@ -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<Cell> = vec![];
let cells_unfetched = [
Position { row: 1, col: 3 },
Expand Down Expand Up @@ -402,7 +402,7 @@ mod tests {
db,
&mock_network_client,
&Arc::new(tests::MockMetrics {}),
&cfg,
99.9,
header,
recv,
sender,
Expand Down
6 changes: 4 additions & 2 deletions core/src/sync_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,10 @@ mod tests {
#[tokio::test]
pub async fn test_process_blocks_without_rpc() {
let (block_tx, _) = broadcast::channel::<types::BlockVerified>(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();
Expand Down
15 changes: 0 additions & 15 deletions core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,21 +353,6 @@ pub enum SecretKey {

pub struct Delay(pub Option<Duration>);

/// 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<Duration> {
(self.0?)
Expand Down

0 comments on commit 624488d

Please sign in to comment.