Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve clippy warnings. #235

Merged
merged 4 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/light_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ pub async fn process_block(
Ok(())
}

pub struct Channels {
pub block_sender: Option<Sender<BlockVerified>>,
pub header_receiver: Receiver<(Header, Instant)>,
pub error_sender: Sender<anyhow::Error>,
}

/// Runs light client.
///
/// # Arguments
Expand All @@ -389,16 +395,14 @@ pub async fn process_block(
pub async fn run(
light_client: impl LightClient,
cfg: LightClientConfig,
block_tx: Option<Sender<BlockVerified>>,
pp: PublicParameters,
metrics: Metrics,
counter: Arc<Mutex<u32>>,
mut message_rx: Receiver<(Header, Instant)>,
error_sender: Sender<anyhow::Error>,
mut channels: Channels,
) {
info!("Starting light client...");

while let Some((header, received_at)) = message_rx.recv().await {
while let Some((header, received_at)) = channels.header_receiver.recv().await {
if let Some(seconds) = cfg.block_processing_delay.sleep_duration(received_at) {
info!("Sleeping for {seconds:?} seconds");
tokio::time::sleep(seconds).await;
Expand All @@ -416,7 +420,7 @@ pub async fn run(
.await
{
error!("Cannot process block: {error}");
if let Err(error) = error_sender.send(error).await {
if let Err(error) = channels.error_sender.send(error).await {
error!("Cannot send error message: {error}");
}
return;
Expand All @@ -429,7 +433,7 @@ pub async fn run(

// notify dht-based application client
// that newly mined block has been received
if let Some(ref channel) = block_tx {
if let Some(ref channel) = channels.block_sender {
if let Err(error) = channel.send(client_msg).await {
error!("Cannot send block verified message: {error}");
continue;
Expand Down
10 changes: 7 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,19 @@ async fn run(error_sender: Sender<anyhow::Error>) -> Result<()> {

let light_client = light_client::new(db, network_client, rpc_client);

let lc_channels = light_client::Channels {
block_sender: block_tx,
header_receiver: message_rx,
error_sender,
};

tokio::task::spawn(light_client::run(
light_client,
(&cfg).into(),
block_tx,
pp,
lc_metrics,
counter,
message_rx,
error_sender,
lc_channels,
));
Ok(())
}
Expand Down
2 changes: 2 additions & 0 deletions src/network/mem_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl Default for MemoryStoreConfig {
}

impl MemoryStore {
#[allow(dead_code)]
/// Creates a new `MemoryRecordStore` with a default configuration.
pub fn new(local_id: PeerId) -> Self {
Self::with_config(local_id, Default::default())
Expand All @@ -88,6 +89,7 @@ impl MemoryStore {
}
}

#[allow(dead_code)]
/// Retains the records satisfying a predicate.
pub fn retain<F>(&mut self, f: F)
where
Expand Down
6 changes: 3 additions & 3 deletions src/network/network_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub async fn start_traffic_analyzer(port: u16, sampling_interval: u64) {
},
};
let mut dev: Option<Device> = None;
for device in devices.clone() {
for device in devices {
if !device.addresses.is_empty()
// The first interface with Connected status is usually the one with all the traffic
&& device.flags.connection_status == ConnectionStatus::Connected
Expand All @@ -36,14 +36,14 @@ pub async fn start_traffic_analyzer(port: u16, sampling_interval: u64) {
let total_bytes = Arc::new(AtomicU32::new(0));

// Listen to loopback device for local testing
if let Ok(_) = start_listening_on_device("lo".to_owned(), port, Arc::clone(&total_bytes)) {
if start_listening_on_device("lo".to_owned(), port, Arc::clone(&total_bytes)).is_ok() {
is_one_capture_active = true;
}

// Listen to non-loopback device for local testing
if let Some(device) = dev {
debug!("Non lo device selected: {}", device.name.as_str());
if let Ok(_) = start_listening_on_device(device.name, port, Arc::clone(&total_bytes)) {
if start_listening_on_device(device.name, port, Arc::clone(&total_bytes)).is_ok() {
is_one_capture_active = true;
}
};
Expand Down
Loading