From 70dcde6b1f661a53152e5d0a6e88c9aaaa67607e Mon Sep 17 00:00:00 2001 From: Green Baneling Date: Thu, 30 May 2024 00:24:52 +0200 Subject: [PATCH] Removed dead code (#1913) Applied new clippy just to removed dead code. I don't want to increase the version of the used Rust, just small clean up. ### Before requesting review - [x] I have reviewed the code myself --- CHANGELOG.md | 3 ++ .../src/config/state/parquet/encode.rs | 23 ---------- crates/fuel-core/src/p2p_test_helpers.rs | 28 ++++++++++-- crates/services/importer/src/importer.rs | 14 ------ crates/services/p2p/src/p2p_service.rs | 4 +- .../p2p/src/peer_manager/heartbeat_data.rs | 2 +- crates/services/p2p/src/peer_report.rs | 43 ------------------- crates/services/p2p/src/service.rs | 28 ------------ crates/services/producer/src/mocks.rs | 17 -------- crates/services/relayer/src/service/state.rs | 4 -- crates/services/sync/src/tracing_helpers.rs | 33 -------------- .../txpool/src/containers/price_sort.rs | 4 -- crates/services/txpool/src/containers/sort.rs | 7 +-- .../txpool/src/containers/time_sort.rs | 4 -- .../txpool/src/service/update_sender.rs | 14 ------ .../update_sender/tests/test_permits.rs | 3 -- .../src/service/update_sender/tests/utils.rs | 4 -- .../upgradable-executor/src/executor.rs | 4 +- .../storage/src/structured_storage/state.rs | 2 +- 19 files changed, 33 insertions(+), 208 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c554a44f91..04b09469ea9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Removed +- [#1913](https://github.com/FuelLabs/fuel-core/pull/1913): Removed dead code from the project. + ## [Version 0.27.0] ### Added diff --git a/crates/chain-config/src/config/state/parquet/encode.rs b/crates/chain-config/src/config/state/parquet/encode.rs index b1d3e314f9d..d8a5657ed6d 100644 --- a/crates/chain-config/src/config/state/parquet/encode.rs +++ b/crates/chain-config/src/config/state/parquet/encode.rs @@ -19,10 +19,6 @@ use parquet::{ data_type::ByteArrayType, schema::types::Type, }; -use postcard::ser_flavors::{ - AllocVec, - Flavor, -}; pub struct Encoder where @@ -88,22 +84,3 @@ where Ok(()) } } - -pub trait Encode { - fn encode(data: &T) -> anyhow::Result>; -} - -pub struct PostcardEncode; - -impl Encode for PostcardEncode -where - T: serde::Serialize, -{ - fn encode(data: &T) -> anyhow::Result> { - let mut serializer = postcard::Serializer { - output: AllocVec::new(), - }; - data.serialize(&mut serializer)?; - Ok(serializer.output.finalize()?) - } -} diff --git a/crates/fuel-core/src/p2p_test_helpers.rs b/crates/fuel-core/src/p2p_test_helpers.rs index a3e1912171a..e9a3f1358de 100644 --- a/crates/fuel-core/src/p2p_test_helpers.rs +++ b/crates/fuel-core/src/p2p_test_helpers.rs @@ -299,10 +299,20 @@ pub async fn make_nodes( { match bootstrap_type { BootstrapType::BootstrapNodes => { - node_config.p2p.as_mut().unwrap().bootstrap_nodes = boots.clone(); + node_config + .p2p + .as_mut() + .unwrap() + .bootstrap_nodes + .clone_from(&boots); } BootstrapType::ReservedNodes => { - node_config.p2p.as_mut().unwrap().reserved_nodes = boots.clone(); + node_config + .p2p + .as_mut() + .unwrap() + .reserved_nodes + .clone_from(&boots); } } @@ -341,10 +351,20 @@ pub async fn make_nodes( match bootstrap_type { BootstrapType::BootstrapNodes => { - node_config.p2p.as_mut().unwrap().bootstrap_nodes = boots.clone(); + node_config + .p2p + .as_mut() + .unwrap() + .bootstrap_nodes + .clone_from(&boots); } BootstrapType::ReservedNodes => { - node_config.p2p.as_mut().unwrap().reserved_nodes = boots.clone(); + node_config + .p2p + .as_mut() + .unwrap() + .reserved_nodes + .clone_from(&boots); } } update_signing_key(&mut node_config, pub_key); diff --git a/crates/services/importer/src/importer.rs b/crates/services/importer/src/importer.rs index cef50bc30a2..17056db3b1c 100644 --- a/crates/services/importer/src/importer.rs +++ b/crates/services/importer/src/importer.rs @@ -474,20 +474,6 @@ where } } -trait ShouldBeUnique { - fn should_be_unique(&self, height: &BlockHeight) -> Result<(), Error>; -} - -impl ShouldBeUnique for Option { - fn should_be_unique(&self, height: &BlockHeight) -> Result<(), Error> { - if self.is_some() { - Err(Error::NotUnique(*height)) - } else { - Ok(()) - } - } -} - /// The wrapper around `ImportResult` to notify about the end of the processing of a new block. struct Awaiter { result: ImportResult, diff --git a/crates/services/p2p/src/p2p_service.rs b/crates/services/p2p/src/p2p_service.rs index e7f86bba9a4..a3da0ca0663 100644 --- a/crates/services/p2p/src/p2p_service.rs +++ b/crates/services/p2p/src/p2p_service.rs @@ -923,7 +923,7 @@ mod tests { let mut p2p_config = p2p_config.clone(); p2p_config.max_peers_connected = node_a_max_peers_allowed as u32; // it still tries to dial all nodes! - p2p_config.bootstrap_nodes = nodes_multiaddrs.clone(); + p2p_config.bootstrap_nodes.clone_from(&nodes_multiaddrs); build_service_from_config(p2p_config).await }; @@ -933,7 +933,7 @@ mod tests { let mut p2p_config = p2p_config.clone(); p2p_config.max_peers_connected = node_b_max_peers_allowed as u32; // it still tries to dial all nodes! - p2p_config.bootstrap_nodes = nodes_multiaddrs.clone(); + p2p_config.bootstrap_nodes.clone_from(&nodes_multiaddrs); build_service_from_config(p2p_config).await }; diff --git a/crates/services/p2p/src/peer_manager/heartbeat_data.rs b/crates/services/p2p/src/peer_manager/heartbeat_data.rs index 2e96c2eaa94..e4118b6a65d 100644 --- a/crates/services/p2p/src/peer_manager/heartbeat_data.rs +++ b/crates/services/p2p/src/peer_manager/heartbeat_data.rs @@ -65,9 +65,9 @@ impl HeartbeatData { } #[allow(clippy::cast_possible_truncation)] +#[allow(non_snake_case)] #[cfg(test)] mod tests { - #![allow(non_snake_case)] use super::*; #[tokio::test(start_paused = true)] diff --git a/crates/services/p2p/src/peer_report.rs b/crates/services/p2p/src/peer_report.rs index dd4436a145a..c8d09073fe8 100644 --- a/crates/services/p2p/src/peer_report.rs +++ b/crates/services/p2p/src/peer_report.rs @@ -2,7 +2,6 @@ use crate::config::Config; use libp2p::{ self, core::Endpoint, - identify, swarm::{ derive_prelude::{ ConnectionClosed, @@ -159,45 +158,3 @@ impl NetworkBehaviour for Behaviour { Poll::Pending } } - -trait FromAction: NetworkBehaviour { - fn convert_action( - &mut self, - action: ToSwarm>, - ) -> Option>>; -} - -impl FromSwarmEvent for Behaviour {} -impl FromSwarmEvent for identify::Behaviour {} - -trait FromSwarmEvent: NetworkBehaviour { - fn handle_swarm_event(&mut self, event: &FromSwarm) { - match event { - FromSwarm::NewListener(e) => { - self.on_swarm_event(FromSwarm::NewListener(*e)); - } - FromSwarm::ExpiredListenAddr(e) => { - self.on_swarm_event(FromSwarm::ExpiredListenAddr(*e)); - } - FromSwarm::ListenerError(e) => { - self.on_swarm_event(FromSwarm::ListenerError(*e)); - } - FromSwarm::ListenerClosed(e) => { - self.on_swarm_event(FromSwarm::ListenerClosed(*e)); - } - FromSwarm::NewExternalAddrCandidate(e) => { - self.on_swarm_event(FromSwarm::NewExternalAddrCandidate(*e)); - } - FromSwarm::ExternalAddrExpired(e) => { - self.on_swarm_event(FromSwarm::ExternalAddrExpired(*e)); - } - FromSwarm::NewListenAddr(e) => { - self.on_swarm_event(FromSwarm::NewListenAddr(*e)); - } - FromSwarm::AddressChange(e) => { - self.on_swarm_event(FromSwarm::AddressChange(*e)); - } - _ => {} - } - } -} diff --git a/crates/services/p2p/src/service.rs b/crates/services/p2p/src/service.rs index f9be6da2af2..f6a29e41579 100644 --- a/crates/services/p2p/src/service.rs +++ b/crates/services/p2p/src/service.rs @@ -89,8 +89,6 @@ pub type Service = ServiceRunner>; enum TaskRequest { // Broadcast requests to p2p network BroadcastTransaction(Arc), - // Request to get one-off data from p2p network - GetPeerIds(oneshot::Sender>), // Request to get information about all connected peers GetAllPeerInfo { channel: oneshot::Sender>, @@ -119,9 +117,6 @@ impl Debug for TaskRequest { TaskRequest::BroadcastTransaction(_) => { write!(f, "TaskRequest::BroadcastTransaction") } - TaskRequest::GetPeerIds(_) => { - write!(f, "TaskRequest::GetPeerIds") - } TaskRequest::GetSealedHeaders { .. } => { write!(f, "TaskRequest::GetSealedHeaders") } @@ -148,7 +143,6 @@ pub enum HeartBeatPeerReportReason { } pub trait TaskP2PService: Send { - fn get_peer_ids(&self) -> Vec; fn get_all_peer_info(&self) -> Vec<(&PeerId, &PeerInfo)>; fn get_peer_id_with_height(&self, height: &BlockHeight) -> Option; @@ -189,10 +183,6 @@ pub trait TaskP2PService: Send { } impl TaskP2PService for FuelP2PService { - fn get_peer_ids(&self) -> Vec { - self.get_peers_ids_iter().copied().collect() - } - fn get_all_peer_info(&self) -> Vec<(&PeerId, &PeerInfo)> { self.peer_manager().get_all_peers().collect() } @@ -527,10 +517,6 @@ where tracing::error!("Got an error during transaction {} broadcasting {}", tx_id, e); } } - Some(TaskRequest::GetPeerIds(channel)) => { - let peer_ids = self.p2p_service.get_peer_ids(); - let _ = channel.send(peer_ids); - } Some(TaskRequest::GetSealedHeaders { block_height_range, channel}) => { let channel = ResponseSender::SealedHeaders(channel); let request_msg = RequestMessage::SealedHeaders(block_height_range.clone()); @@ -756,16 +742,6 @@ impl SharedState { Ok(()) } - pub async fn get_peer_ids(&self) -> anyhow::Result> { - let (sender, receiver) = oneshot::channel(); - - self.request_sender - .send(TaskRequest::GetPeerIds(sender)) - .await?; - - receiver.await.map_err(|e| anyhow!("{}", e)) - } - pub async fn get_all_peers(&self) -> anyhow::Result> { let (sender, receiver) = oneshot::channel(); @@ -954,10 +930,6 @@ pub mod tests { } impl TaskP2PService for FakeP2PService { - fn get_peer_ids(&self) -> Vec { - todo!() - } - fn get_all_peer_info(&self) -> Vec<(&PeerId, &PeerInfo)> { self.peer_info.iter().map(|tup| (&tup.0, &tup.1)).collect() } diff --git a/crates/services/producer/src/mocks.rs b/crates/services/producer/src/mocks.rs index 9ab32391994..3c4a86f9855 100644 --- a/crates/services/producer/src/mocks.rs +++ b/crates/services/producer/src/mocks.rs @@ -95,23 +95,6 @@ impl TxPool for MockTxPool { #[derive(Default)] pub struct MockExecutor(pub MockDb); -#[derive(Debug)] -struct DatabaseTransaction { - database: MockDb, -} - -impl AsMut for DatabaseTransaction { - fn as_mut(&mut self) -> &mut MockDb { - &mut self.database - } -} - -impl AsRef for DatabaseTransaction { - fn as_ref(&self) -> &MockDb { - &self.database - } -} - impl AsMut for MockDb { fn as_mut(&mut self) -> &mut MockDb { self diff --git a/crates/services/relayer/src/service/state.rs b/crates/services/relayer/src/service/state.rs index 76b5db63f44..dc68342e3b1 100644 --- a/crates/services/relayer/src/service/state.rs +++ b/crates/services/relayer/src/service/state.rs @@ -20,10 +20,6 @@ pub struct EthState { type EthHeight = u64; -#[derive(Clone, Debug)] -/// Type for tracking block height ranges. -struct Heights(RangeInclusive); - #[derive(Clone, Debug)] /// The gap between the eth block height on /// the relayer and the Ethereum node. diff --git a/crates/services/sync/src/tracing_helpers.rs b/crates/services/sync/src/tracing_helpers.rs index 145b378b02f..53b4384cb64 100644 --- a/crates/services/sync/src/tracing_helpers.rs +++ b/crates/services/sync/src/tracing_helpers.rs @@ -4,27 +4,6 @@ pub trait TraceErr { fn trace_err(self, msg: &str) -> Self; } -pub trait TraceNone: Sized { - fn trace_none(self, f: F) -> Self - where - F: FnOnce(); - fn trace_none_error(self, msg: &str) -> Self { - self.trace_none(|| tracing::error!("{}", msg)) - } - fn trace_none_warn(self, msg: &str) -> Self { - self.trace_none(|| tracing::warn!("{}", msg)) - } - fn trace_none_info(self, msg: &str) -> Self { - self.trace_none(|| tracing::info!("{}", msg)) - } - fn trace_none_debug(self, msg: &str) -> Self { - self.trace_none(|| tracing::debug!("{}", msg)) - } - fn trace_none_trace(self, msg: &str) -> Self { - self.trace_none(|| tracing::trace!("{}", msg)) - } -} - impl TraceErr for Result where E: Display, @@ -36,15 +15,3 @@ where self } } - -impl TraceNone for Option { - fn trace_none(self, f: F) -> Self - where - F: FnOnce(), - { - if self.is_none() { - f(); - } - self - } -} diff --git a/crates/services/txpool/src/containers/price_sort.rs b/crates/services/txpool/src/containers/price_sort.rs index cc061d47f9a..d6c4706a661 100644 --- a/crates/services/txpool/src/containers/price_sort.rs +++ b/crates/services/txpool/src/containers/price_sort.rs @@ -30,10 +30,6 @@ impl SortableKey for TipSortKey { fn value(&self) -> &Self::Value { &self.tip } - - fn tx_id(&self) -> &TxId { - &self.tx_id - } } impl PartialEq for TipSortKey { diff --git a/crates/services/txpool/src/containers/sort.rs b/crates/services/txpool/src/containers/sort.rs index 7e3142d0eb1..beff2691071 100644 --- a/crates/services/txpool/src/containers/sort.rs +++ b/crates/services/txpool/src/containers/sort.rs @@ -1,7 +1,4 @@ -use crate::{ - types::*, - TxInfo, -}; +use crate::TxInfo; use fuel_core_types::services::txpool::ArcPoolTx; use std::collections::BTreeMap; @@ -51,6 +48,4 @@ pub trait SortableKey: Ord { fn new(info: &TxInfo) -> Self; fn value(&self) -> &Self::Value; - - fn tx_id(&self) -> &TxId; } diff --git a/crates/services/txpool/src/containers/time_sort.rs b/crates/services/txpool/src/containers/time_sort.rs index d4af6273bd8..8f8679b7d80 100644 --- a/crates/services/txpool/src/containers/time_sort.rs +++ b/crates/services/txpool/src/containers/time_sort.rs @@ -41,10 +41,6 @@ impl SortableKey for TimeSortKey { fn value(&self) -> &Self::Value { &self.time } - - fn tx_id(&self) -> &TxId { - &self.tx_id - } } impl PartialEq for TimeSortKey { diff --git a/crates/services/txpool/src/service/update_sender.rs b/crates/services/txpool/src/service/update_sender.rs index 588df172772..9362d934dd6 100644 --- a/crates/services/txpool/src/service/update_sender.rs +++ b/crates/services/txpool/src/service/update_sender.rs @@ -1,6 +1,5 @@ use std::{ collections::HashMap, - future::Future, pin::Pin, time::Duration, }; @@ -114,9 +113,6 @@ pub trait CreateChannel { trait Permits { /// Try to acquire a permit. fn try_acquire(self: Arc) -> Option; - - /// Wait for a permit to be available. - fn acquire(self: Arc) -> Pin + Send + Sync>>; } /// Combines `Permits` and `std::fmt::Debug`. @@ -142,16 +138,6 @@ impl Permits for Semaphore { b }) } - - fn acquire(self: Arc) -> Pin + Send + Sync>> { - Box::pin(async move { - let p = Semaphore::acquire_owned(self) - .await - .expect("Semaphore is not ever closed"); - let b: Permit = Box::new(p); - b - }) - } } impl PermitTrait for OwnedSemaphorePermit {} diff --git a/crates/services/txpool/src/service/update_sender/tests/test_permits.rs b/crates/services/txpool/src/service/update_sender/tests/test_permits.rs index e819a12083e..2b418818d92 100644 --- a/crates/services/txpool/src/service/update_sender/tests/test_permits.rs +++ b/crates/services/txpool/src/service/update_sender/tests/test_permits.rs @@ -22,9 +22,6 @@ impl Permits for Arc { p }) } - fn acquire(self: Arc) -> Pin + Send + Sync>> { - unimplemented!() - } } #[proptest] diff --git a/crates/services/txpool/src/service/update_sender/tests/utils.rs b/crates/services/txpool/src/service/update_sender/tests/utils.rs index 1f874a002d1..71c93859686 100644 --- a/crates/services/txpool/src/service/update_sender/tests/utils.rs +++ b/crates/services/txpool/src/service/update_sender/tests/utils.rs @@ -187,10 +187,6 @@ impl Permits for () { fn try_acquire(self: Arc) -> Option { Some(Permit::from(Box::new(()))) } - - fn acquire(self: Arc) -> Pin + Send + Sync>> { - Box::pin(async move { Permit::from(Box::new(())) }) - } } pub(super) struct MockCreateChannel; diff --git a/crates/services/upgradable-executor/src/executor.rs b/crates/services/upgradable-executor/src/executor.rs index 6137d3ba430..2e190113758 100644 --- a/crates/services/upgradable-executor/src/executor.rs +++ b/crates/services/upgradable-executor/src/executor.rs @@ -721,9 +721,7 @@ mod test { }) .collect::>(); - if let Some(expected_version) = - seen_crate_versions.get(&crate_version.to_string()) - { + if let Some(expected_version) = seen_crate_versions.get(crate_version) { assert_eq!( *expected_version, Executor::::VERSION, diff --git a/crates/storage/src/structured_storage/state.rs b/crates/storage/src/structured_storage/state.rs index 6fceb6b1d78..ca48a6e4eea 100644 --- a/crates/storage/src/structured_storage/state.rs +++ b/crates/storage/src/structured_storage/state.rs @@ -68,7 +68,7 @@ mod test { crate::basic_storage_tests!( ContractsState, ::Key::default(), - vec![0u8; 32], + [0u8; 32], vec![0u8; 32].into(), generate_key_for_same_contract );