diff --git a/p2p/dandelion-tower/Cargo.toml b/p2p/dandelion-tower/Cargo.toml index 976dad6..92e4915 100644 --- a/p2p/dandelion-tower/Cargo.toml +++ b/p2p/dandelion-tower/Cargo.toml @@ -24,4 +24,7 @@ thiserror = { workspace = true } [dev-dependencies] tokio = { workspace = true, features = ["rt-multi-thread", "macros", "sync"] } -proptest = { workspace = true, features = ["default"] } \ No newline at end of file +proptest = { workspace = true, features = ["default"] } + +[lints] +workspace = true \ No newline at end of file diff --git a/p2p/dandelion-tower/src/config.rs b/p2p/dandelion-tower/src/config.rs index 6266d60..46c780a 100644 --- a/p2p/dandelion-tower/src/config.rs +++ b/p2p/dandelion-tower/src/config.rs @@ -8,7 +8,7 @@ use std::{ /// (1 - ep) is the probability that a transaction travels for `k` hops before a nodes embargo timeout fires, this constant is (1 - ep). const EMBARGO_FULL_TRAVEL_PROBABILITY: f64 = 0.90; -/// The graph type to use for dandelion routing, the dandelion paper recommends [Graph::FourRegular]. +/// The graph type to use for dandelion routing, the dandelion paper recommends [`Graph::FourRegular`]. /// /// The decision between line graphs and 4-regular graphs depend on the priorities of the system, if /// linkability of transactions is a first order concern then line graphs may be better, however 4-regular graphs @@ -66,7 +66,7 @@ impl DandelionConfig { /// Returns the number of outbound peers to use to stem transactions. /// /// This value depends on the [`Graph`] chosen. - pub fn number_of_stems(&self) -> usize { + pub const fn number_of_stems(&self) -> usize { match self.graph { Graph::Line => 1, Graph::FourRegular => 2, diff --git a/p2p/dandelion-tower/src/lib.rs b/p2p/dandelion-tower/src/lib.rs index 60b5ea5..2c8de71 100644 --- a/p2p/dandelion-tower/src/lib.rs +++ b/p2p/dandelion-tower/src/lib.rs @@ -26,7 +26,7 @@ //! The diffuse service should have a request of [`DiffuseRequest`](traits::DiffuseRequest) and it's error //! should be [`tower::BoxError`]. //! -//! ## Outbound Peer TryStream +//! ## Outbound Peer `TryStream` //! //! The outbound peer [`TryStream`](futures::TryStream) should provide a stream of randomly selected outbound //! peers, these peers will then be used to route stem txs to. @@ -37,7 +37,7 @@ //! ## Peer Service //! //! This service represents a connection to an individual peer, this should be returned from the Outbound Peer -//! TryStream. This should immediately send the transaction to the peer when requested, it should _not_ set +//! `TryStream`. This should immediately send the transaction to the peer when requested, it should _not_ set //! a timer. //! //! The peer service should have a request of [`StemRequest`](traits::StemRequest) and its error diff --git a/p2p/dandelion-tower/src/pool/incoming_tx.rs b/p2p/dandelion-tower/src/pool/incoming_tx.rs index c9a30de..13cdffe 100644 --- a/p2p/dandelion-tower/src/pool/incoming_tx.rs +++ b/p2p/dandelion-tower/src/pool/incoming_tx.rs @@ -30,7 +30,7 @@ pub struct IncomingTxBuilder impl IncomingTxBuilder { /// Creates a new [`IncomingTxBuilder`]. - pub fn new(tx: Tx, tx_id: TxId) -> Self { + pub const fn new(tx: Tx, tx_id: TxId) -> Self { Self { tx, tx_id, diff --git a/p2p/dandelion-tower/src/pool/manager.rs b/p2p/dandelion-tower/src/pool/manager.rs index 9e1572e..2ac3302 100644 --- a/p2p/dandelion-tower/src/pool/manager.rs +++ b/p2p/dandelion-tower/src/pool/manager.rs @@ -88,9 +88,7 @@ where .insert(peer.clone()); } - let state = from - .map(|from| TxState::Stem { from }) - .unwrap_or(TxState::Local); + let state = from.map_or(TxState::Local, |from| TxState::Stem { from }); let fut = self .dandelion_router @@ -280,13 +278,15 @@ where }; if let Err(e) = self.handle_incoming_tx(tx, routing_state, tx_id).await { + #[expect(clippy::let_underscore_must_use, reason = "dropped receivers can be ignored")] let _ = res_tx.send(()); tracing::error!("Error handling transaction in dandelion pool: {e}"); return; } - let _ = res_tx.send(()); + #[expect(clippy::let_underscore_must_use)] + let _ = res_tx.send(()); } } } diff --git a/p2p/dandelion-tower/src/router.rs b/p2p/dandelion-tower/src/router.rs index edeccae..88702be 100644 --- a/p2p/dandelion-tower/src/router.rs +++ b/p2p/dandelion-tower/src/router.rs @@ -140,7 +140,7 @@ where State::Stem }; - DandelionRouter { + Self { outbound_peer_discover: Box::pin(outbound_peer_discover), broadcast_svc, current_state, @@ -198,7 +198,7 @@ where fn stem_tx( &mut self, tx: Tx, - from: Id, + from: &Id, ) -> BoxFuture<'static, Result> { if self.stem_peers.is_empty() { tracing::debug!("Stem peers are empty, fluffing stem transaction."); @@ -216,7 +216,7 @@ where }); let Some(peer) = self.stem_peers.get_mut(stem_route) else { - self.stem_routes.remove(&from); + self.stem_routes.remove(from); continue; }; @@ -302,7 +302,7 @@ where tracing::debug!( parent: span, "Peer returned an error on `poll_ready`: {e}, removing from router.", - ) + ); }) .is_ok(), Poll::Pending => { @@ -341,7 +341,7 @@ where State::Stem => { tracing::trace!(parent: &self.span, "Steming transaction"); - self.stem_tx(req.tx, from) + self.stem_tx(req.tx, &from) } }, TxState::Local => { diff --git a/p2p/dandelion-tower/src/tests/mod.rs b/p2p/dandelion-tower/src/tests/mod.rs index 1c6a3e0..601ee25 100644 --- a/p2p/dandelion-tower/src/tests/mod.rs +++ b/p2p/dandelion-tower/src/tests/mod.rs @@ -12,7 +12,7 @@ use crate::{ OutboundPeer, State, }; -pub fn mock_discover_svc() -> ( +pub(crate) fn mock_discover_svc() -> ( impl Stream< Item = Result< OutboundPeer< @@ -49,7 +49,7 @@ pub fn mock_discover_svc() -> ( (discover, rx) } -pub fn mock_broadcast_svc() -> ( +pub(crate) fn mock_broadcast_svc() -> ( impl Service< Req, Future = impl Future> + Send + 'static, @@ -70,8 +70,8 @@ pub fn mock_broadcast_svc() -> ( ) } -#[allow(clippy::type_complexity)] // just test code. -pub fn mock_in_memory_backing_pool< +#[expect(clippy::type_complexity, reason = "just test code.")] +pub(crate) fn mock_in_memory_backing_pool< Tx: Clone + Send + 'static, TxID: Clone + Hash + Eq + Send + 'static, >() -> ( @@ -85,11 +85,11 @@ pub fn mock_in_memory_backing_pool< Arc>>, ) { let txs = Arc::new(std::sync::Mutex::new(HashMap::new())); - let txs_2 = txs.clone(); + let txs_2 = Arc::clone(&txs); ( service_fn(move |req: TxStoreRequest| { - let txs = txs.clone(); + let txs = Arc::clone(&txs); async move { match req { TxStoreRequest::Get(tx_id) => { diff --git a/p2p/dandelion-tower/src/tests/pool.rs b/p2p/dandelion-tower/src/tests/pool.rs index b7fa55e..70f642a 100644 --- a/p2p/dandelion-tower/src/tests/pool.rs +++ b/p2p/dandelion-tower/src/tests/pool.rs @@ -39,5 +39,5 @@ async fn basic_functionality() { // TODO: the DandelionPoolManager doesn't handle adding txs to the pool, add more tests here to test // all functionality. //assert!(pool.lock().unwrap().contains_key(&1)); - assert!(broadcast_rx.try_recv().is_ok()) + assert!(broadcast_rx.try_recv().is_ok()); }