mirror of
https://github.com/Cuprate/cuprate.git
synced 2024-11-16 15:58:17 +00:00
p2p/dandelion-tower: enable workspace lints (#287)
* dandelion-tower: add/fix workspace lints * fmt * fixes * todos * fixes * fixes * expect reason
This commit is contained in:
parent
e7c6bba63d
commit
19150df355
8 changed files with 25 additions and 22 deletions
|
@ -24,4 +24,7 @@ thiserror = { workspace = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "sync"] }
|
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "sync"] }
|
||||||
proptest = { workspace = true, features = ["default"] }
|
proptest = { workspace = true, features = ["default"] }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
|
@ -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).
|
/// (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;
|
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
|
/// 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
|
/// 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.
|
/// Returns the number of outbound peers to use to stem transactions.
|
||||||
///
|
///
|
||||||
/// This value depends on the [`Graph`] chosen.
|
/// 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 {
|
match self.graph {
|
||||||
Graph::Line => 1,
|
Graph::Line => 1,
|
||||||
Graph::FourRegular => 2,
|
Graph::FourRegular => 2,
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
//! The diffuse service should have a request of [`DiffuseRequest`](traits::DiffuseRequest) and it's error
|
//! The diffuse service should have a request of [`DiffuseRequest`](traits::DiffuseRequest) and it's error
|
||||||
//! should be [`tower::BoxError`].
|
//! should be [`tower::BoxError`].
|
||||||
//!
|
//!
|
||||||
//! ## Outbound Peer TryStream
|
//! ## Outbound Peer `TryStream`
|
||||||
//!
|
//!
|
||||||
//! The outbound peer [`TryStream`](futures::TryStream) should provide a stream of randomly selected outbound
|
//! 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.
|
//! peers, these peers will then be used to route stem txs to.
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
//! ## Peer Service
|
//! ## Peer Service
|
||||||
//!
|
//!
|
||||||
//! This service represents a connection to an individual peer, this should be returned from the Outbound Peer
|
//! 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.
|
//! a timer.
|
||||||
//!
|
//!
|
||||||
//! The peer service should have a request of [`StemRequest`](traits::StemRequest) and its error
|
//! The peer service should have a request of [`StemRequest`](traits::StemRequest) and its error
|
||||||
|
|
|
@ -30,7 +30,7 @@ pub struct IncomingTxBuilder<const RS: bool, const DBS: bool, Tx, TxId, PeerId>
|
||||||
|
|
||||||
impl<Tx, TxId, PeerId> IncomingTxBuilder<false, false, Tx, TxId, PeerId> {
|
impl<Tx, TxId, PeerId> IncomingTxBuilder<false, false, Tx, TxId, PeerId> {
|
||||||
/// Creates a new [`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 {
|
Self {
|
||||||
tx,
|
tx,
|
||||||
tx_id,
|
tx_id,
|
||||||
|
|
|
@ -88,9 +88,7 @@ where
|
||||||
.insert(peer.clone());
|
.insert(peer.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
let state = from
|
let state = from.map_or(TxState::Local, |from| TxState::Stem { from });
|
||||||
.map(|from| TxState::Stem { from })
|
|
||||||
.unwrap_or(TxState::Local);
|
|
||||||
|
|
||||||
let fut = self
|
let fut = self
|
||||||
.dandelion_router
|
.dandelion_router
|
||||||
|
@ -280,13 +278,15 @@ where
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = self.handle_incoming_tx(tx, routing_state, tx_id).await {
|
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(());
|
let _ = res_tx.send(());
|
||||||
|
|
||||||
tracing::error!("Error handling transaction in dandelion pool: {e}");
|
tracing::error!("Error handling transaction in dandelion pool: {e}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let _ = res_tx.send(());
|
|
||||||
|
|
||||||
|
#[expect(clippy::let_underscore_must_use)]
|
||||||
|
let _ = res_tx.send(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ where
|
||||||
State::Stem
|
State::Stem
|
||||||
};
|
};
|
||||||
|
|
||||||
DandelionRouter {
|
Self {
|
||||||
outbound_peer_discover: Box::pin(outbound_peer_discover),
|
outbound_peer_discover: Box::pin(outbound_peer_discover),
|
||||||
broadcast_svc,
|
broadcast_svc,
|
||||||
current_state,
|
current_state,
|
||||||
|
@ -198,7 +198,7 @@ where
|
||||||
fn stem_tx(
|
fn stem_tx(
|
||||||
&mut self,
|
&mut self,
|
||||||
tx: Tx,
|
tx: Tx,
|
||||||
from: Id,
|
from: &Id,
|
||||||
) -> BoxFuture<'static, Result<State, DandelionRouterError>> {
|
) -> BoxFuture<'static, Result<State, DandelionRouterError>> {
|
||||||
if self.stem_peers.is_empty() {
|
if self.stem_peers.is_empty() {
|
||||||
tracing::debug!("Stem peers are empty, fluffing stem transaction.");
|
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 {
|
let Some(peer) = self.stem_peers.get_mut(stem_route) else {
|
||||||
self.stem_routes.remove(&from);
|
self.stem_routes.remove(from);
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ where
|
||||||
tracing::debug!(
|
tracing::debug!(
|
||||||
parent: span,
|
parent: span,
|
||||||
"Peer returned an error on `poll_ready`: {e}, removing from router.",
|
"Peer returned an error on `poll_ready`: {e}, removing from router.",
|
||||||
)
|
);
|
||||||
})
|
})
|
||||||
.is_ok(),
|
.is_ok(),
|
||||||
Poll::Pending => {
|
Poll::Pending => {
|
||||||
|
@ -341,7 +341,7 @@ where
|
||||||
State::Stem => {
|
State::Stem => {
|
||||||
tracing::trace!(parent: &self.span, "Steming transaction");
|
tracing::trace!(parent: &self.span, "Steming transaction");
|
||||||
|
|
||||||
self.stem_tx(req.tx, from)
|
self.stem_tx(req.tx, &from)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
TxState::Local => {
|
TxState::Local => {
|
||||||
|
|
|
@ -12,7 +12,7 @@ use crate::{
|
||||||
OutboundPeer, State,
|
OutboundPeer, State,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn mock_discover_svc<Req: Send + 'static>() -> (
|
pub(crate) fn mock_discover_svc<Req: Send + 'static>() -> (
|
||||||
impl Stream<
|
impl Stream<
|
||||||
Item = Result<
|
Item = Result<
|
||||||
OutboundPeer<
|
OutboundPeer<
|
||||||
|
@ -49,7 +49,7 @@ pub fn mock_discover_svc<Req: Send + 'static>() -> (
|
||||||
(discover, rx)
|
(discover, rx)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mock_broadcast_svc<Req: Send + 'static>() -> (
|
pub(crate) fn mock_broadcast_svc<Req: Send + 'static>() -> (
|
||||||
impl Service<
|
impl Service<
|
||||||
Req,
|
Req,
|
||||||
Future = impl Future<Output = Result<(), tower::BoxError>> + Send + 'static,
|
Future = impl Future<Output = Result<(), tower::BoxError>> + Send + 'static,
|
||||||
|
@ -70,8 +70,8 @@ pub fn mock_broadcast_svc<Req: Send + 'static>() -> (
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)] // just test code.
|
#[expect(clippy::type_complexity, reason = "just test code.")]
|
||||||
pub fn mock_in_memory_backing_pool<
|
pub(crate) fn mock_in_memory_backing_pool<
|
||||||
Tx: Clone + Send + 'static,
|
Tx: Clone + Send + 'static,
|
||||||
TxID: Clone + Hash + Eq + Send + 'static,
|
TxID: Clone + Hash + Eq + Send + 'static,
|
||||||
>() -> (
|
>() -> (
|
||||||
|
@ -85,11 +85,11 @@ pub fn mock_in_memory_backing_pool<
|
||||||
Arc<std::sync::Mutex<HashMap<TxID, (Tx, State)>>>,
|
Arc<std::sync::Mutex<HashMap<TxID, (Tx, State)>>>,
|
||||||
) {
|
) {
|
||||||
let txs = Arc::new(std::sync::Mutex::new(HashMap::new()));
|
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<TxID>| {
|
service_fn(move |req: TxStoreRequest<TxID>| {
|
||||||
let txs = txs.clone();
|
let txs = Arc::clone(&txs);
|
||||||
async move {
|
async move {
|
||||||
match req {
|
match req {
|
||||||
TxStoreRequest::Get(tx_id) => {
|
TxStoreRequest::Get(tx_id) => {
|
||||||
|
|
|
@ -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
|
// TODO: the DandelionPoolManager doesn't handle adding txs to the pool, add more tests here to test
|
||||||
// all functionality.
|
// all functionality.
|
||||||
//assert!(pool.lock().unwrap().contains_key(&1));
|
//assert!(pool.lock().unwrap().contains_key(&1));
|
||||||
assert!(broadcast_rx.try_recv().is_ok())
|
assert!(broadcast_rx.try_recv().is_ok());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue