Skip to content

Commit 19150df

Browse files
authored
p2p/dandelion-tower: enable workspace lints (#287)
* dandelion-tower: add/fix workspace lints * fmt * fixes * todos * fixes * fixes * expect reason
1 parent e7c6bba commit 19150df

File tree

8 files changed

+25
-22
lines changed

8 files changed

+25
-22
lines changed

p2p/dandelion-tower/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ thiserror = { workspace = true }
2424

2525
[dev-dependencies]
2626
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "sync"] }
27-
proptest = { workspace = true, features = ["default"] }
27+
proptest = { workspace = true, features = ["default"] }
28+
29+
[lints]
30+
workspace = true

p2p/dandelion-tower/src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{
88
/// (1 - ep) is the probability that a transaction travels for `k` hops before a nodes embargo timeout fires, this constant is (1 - ep).
99
const EMBARGO_FULL_TRAVEL_PROBABILITY: f64 = 0.90;
1010

11-
/// The graph type to use for dandelion routing, the dandelion paper recommends [Graph::FourRegular].
11+
/// The graph type to use for dandelion routing, the dandelion paper recommends [`Graph::FourRegular`].
1212
///
1313
/// The decision between line graphs and 4-regular graphs depend on the priorities of the system, if
1414
/// linkability of transactions is a first order concern then line graphs may be better, however 4-regular graphs
@@ -66,7 +66,7 @@ impl DandelionConfig {
6666
/// Returns the number of outbound peers to use to stem transactions.
6767
///
6868
/// This value depends on the [`Graph`] chosen.
69-
pub fn number_of_stems(&self) -> usize {
69+
pub const fn number_of_stems(&self) -> usize {
7070
match self.graph {
7171
Graph::Line => 1,
7272
Graph::FourRegular => 2,

p2p/dandelion-tower/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//! The diffuse service should have a request of [`DiffuseRequest`](traits::DiffuseRequest) and it's error
2727
//! should be [`tower::BoxError`].
2828
//!
29-
//! ## Outbound Peer TryStream
29+
//! ## Outbound Peer `TryStream`
3030
//!
3131
//! The outbound peer [`TryStream`](futures::TryStream) should provide a stream of randomly selected outbound
3232
//! peers, these peers will then be used to route stem txs to.
@@ -37,7 +37,7 @@
3737
//! ## Peer Service
3838
//!
3939
//! This service represents a connection to an individual peer, this should be returned from the Outbound Peer
40-
//! TryStream. This should immediately send the transaction to the peer when requested, it should _not_ set
40+
//! `TryStream`. This should immediately send the transaction to the peer when requested, it should _not_ set
4141
//! a timer.
4242
//!
4343
//! The peer service should have a request of [`StemRequest`](traits::StemRequest) and its error

p2p/dandelion-tower/src/pool/incoming_tx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct IncomingTxBuilder<const RS: bool, const DBS: bool, Tx, TxId, PeerId>
3030

3131
impl<Tx, TxId, PeerId> IncomingTxBuilder<false, false, Tx, TxId, PeerId> {
3232
/// Creates a new [`IncomingTxBuilder`].
33-
pub fn new(tx: Tx, tx_id: TxId) -> Self {
33+
pub const fn new(tx: Tx, tx_id: TxId) -> Self {
3434
Self {
3535
tx,
3636
tx_id,

p2p/dandelion-tower/src/pool/manager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ where
8888
.insert(peer.clone());
8989
}
9090

91-
let state = from
92-
.map(|from| TxState::Stem { from })
93-
.unwrap_or(TxState::Local);
91+
let state = from.map_or(TxState::Local, |from| TxState::Stem { from });
9492

9593
let fut = self
9694
.dandelion_router
@@ -280,13 +278,15 @@ where
280278
};
281279

282280
if let Err(e) = self.handle_incoming_tx(tx, routing_state, tx_id).await {
281+
#[expect(clippy::let_underscore_must_use, reason = "dropped receivers can be ignored")]
283282
let _ = res_tx.send(());
284283

285284
tracing::error!("Error handling transaction in dandelion pool: {e}");
286285
return;
287286
}
288-
let _ = res_tx.send(());
289287

288+
#[expect(clippy::let_underscore_must_use)]
289+
let _ = res_tx.send(());
290290
}
291291
}
292292
}

p2p/dandelion-tower/src/router.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ where
140140
State::Stem
141141
};
142142

143-
DandelionRouter {
143+
Self {
144144
outbound_peer_discover: Box::pin(outbound_peer_discover),
145145
broadcast_svc,
146146
current_state,
@@ -198,7 +198,7 @@ where
198198
fn stem_tx(
199199
&mut self,
200200
tx: Tx,
201-
from: Id,
201+
from: &Id,
202202
) -> BoxFuture<'static, Result<State, DandelionRouterError>> {
203203
if self.stem_peers.is_empty() {
204204
tracing::debug!("Stem peers are empty, fluffing stem transaction.");
@@ -216,7 +216,7 @@ where
216216
});
217217

218218
let Some(peer) = self.stem_peers.get_mut(stem_route) else {
219-
self.stem_routes.remove(&from);
219+
self.stem_routes.remove(from);
220220
continue;
221221
};
222222

@@ -302,7 +302,7 @@ where
302302
tracing::debug!(
303303
parent: span,
304304
"Peer returned an error on `poll_ready`: {e}, removing from router.",
305-
)
305+
);
306306
})
307307
.is_ok(),
308308
Poll::Pending => {
@@ -341,7 +341,7 @@ where
341341
State::Stem => {
342342
tracing::trace!(parent: &self.span, "Steming transaction");
343343

344-
self.stem_tx(req.tx, from)
344+
self.stem_tx(req.tx, &from)
345345
}
346346
},
347347
TxState::Local => {

p2p/dandelion-tower/src/tests/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
OutboundPeer, State,
1313
};
1414

15-
pub fn mock_discover_svc<Req: Send + 'static>() -> (
15+
pub(crate) fn mock_discover_svc<Req: Send + 'static>() -> (
1616
impl Stream<
1717
Item = Result<
1818
OutboundPeer<
@@ -49,7 +49,7 @@ pub fn mock_discover_svc<Req: Send + 'static>() -> (
4949
(discover, rx)
5050
}
5151

52-
pub fn mock_broadcast_svc<Req: Send + 'static>() -> (
52+
pub(crate) fn mock_broadcast_svc<Req: Send + 'static>() -> (
5353
impl Service<
5454
Req,
5555
Future = impl Future<Output = Result<(), tower::BoxError>> + Send + 'static,
@@ -70,8 +70,8 @@ pub fn mock_broadcast_svc<Req: Send + 'static>() -> (
7070
)
7171
}
7272

73-
#[allow(clippy::type_complexity)] // just test code.
74-
pub fn mock_in_memory_backing_pool<
73+
#[expect(clippy::type_complexity, reason = "just test code.")]
74+
pub(crate) fn mock_in_memory_backing_pool<
7575
Tx: Clone + Send + 'static,
7676
TxID: Clone + Hash + Eq + Send + 'static,
7777
>() -> (
@@ -85,11 +85,11 @@ pub fn mock_in_memory_backing_pool<
8585
Arc<std::sync::Mutex<HashMap<TxID, (Tx, State)>>>,
8686
) {
8787
let txs = Arc::new(std::sync::Mutex::new(HashMap::new()));
88-
let txs_2 = txs.clone();
88+
let txs_2 = Arc::clone(&txs);
8989

9090
(
9191
service_fn(move |req: TxStoreRequest<TxID>| {
92-
let txs = txs.clone();
92+
let txs = Arc::clone(&txs);
9393
async move {
9494
match req {
9595
TxStoreRequest::Get(tx_id) => {

p2p/dandelion-tower/src/tests/pool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ async fn basic_functionality() {
3939
// TODO: the DandelionPoolManager doesn't handle adding txs to the pool, add more tests here to test
4040
// all functionality.
4141
//assert!(pool.lock().unwrap().contains_key(&1));
42-
assert!(broadcast_rx.try_recv().is_ok())
42+
assert!(broadcast_rx.try_recv().is_ok());
4343
}

0 commit comments

Comments
 (0)