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]
|
||||
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).
|
||||
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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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> {
|
||||
/// 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,
|
||||
|
|
|
@ -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(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<State, DandelionRouterError>> {
|
||||
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 => {
|
||||
|
|
|
@ -12,7 +12,7 @@ use crate::{
|
|||
OutboundPeer, State,
|
||||
};
|
||||
|
||||
pub fn mock_discover_svc<Req: Send + 'static>() -> (
|
||||
pub(crate) fn mock_discover_svc<Req: Send + 'static>() -> (
|
||||
impl Stream<
|
||||
Item = Result<
|
||||
OutboundPeer<
|
||||
|
@ -49,7 +49,7 @@ pub fn mock_discover_svc<Req: Send + 'static>() -> (
|
|||
(discover, rx)
|
||||
}
|
||||
|
||||
pub fn mock_broadcast_svc<Req: Send + 'static>() -> (
|
||||
pub(crate) fn mock_broadcast_svc<Req: Send + 'static>() -> (
|
||||
impl Service<
|
||||
Req,
|
||||
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.
|
||||
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<std::sync::Mutex<HashMap<TxID, (Tx, State)>>>,
|
||||
) {
|
||||
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>| {
|
||||
let txs = txs.clone();
|
||||
let txs = Arc::clone(&txs);
|
||||
async move {
|
||||
match req {
|
||||
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
|
||||
// all functionality.
|
||||
//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