Group PeerSet fields into themes (#4618)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
29e73b3f3e
commit
e5c92084ba
|
|
@ -170,14 +170,23 @@ where
|
||||||
D::Error: Into<BoxError>,
|
D::Error: Into<BoxError>,
|
||||||
C: ChainTip,
|
C: ChainTip,
|
||||||
{
|
{
|
||||||
|
// Peer Tracking: New Peers
|
||||||
|
//
|
||||||
/// Provides new and deleted peer [`Change`]s to the peer set,
|
/// Provides new and deleted peer [`Change`]s to the peer set,
|
||||||
/// via the [`Discover`] trait implementation.
|
/// via the [`Discover`] trait implementation.
|
||||||
discover: D,
|
discover: D,
|
||||||
|
|
||||||
|
/// A channel that asks the peer crawler task to connect to more peers.
|
||||||
|
demand_signal: mpsc::Sender<MorePeers>,
|
||||||
|
|
||||||
|
// Peer Tracking: Ready Peers
|
||||||
|
//
|
||||||
/// Connected peers that are ready to receive requests from Zebra,
|
/// Connected peers that are ready to receive requests from Zebra,
|
||||||
/// or send requests to Zebra.
|
/// or send requests to Zebra.
|
||||||
ready_services: HashMap<D::Key, D::Service>,
|
ready_services: HashMap<D::Key, D::Service>,
|
||||||
|
|
||||||
|
// Request Routing
|
||||||
|
//
|
||||||
/// A preselected ready service.
|
/// A preselected ready service.
|
||||||
///
|
///
|
||||||
/// # Correctness
|
/// # Correctness
|
||||||
|
|
@ -194,6 +203,8 @@ where
|
||||||
/// Used to route inventory requests to peers that are likely to have it.
|
/// Used to route inventory requests to peers that are likely to have it.
|
||||||
inventory_registry: InventoryRegistry,
|
inventory_registry: InventoryRegistry,
|
||||||
|
|
||||||
|
// Peer Tracking: Busy Peers
|
||||||
|
//
|
||||||
/// Connected peers that are handling a Zebra request,
|
/// Connected peers that are handling a Zebra request,
|
||||||
/// or Zebra is handling one of their requests.
|
/// or Zebra is handling one of their requests.
|
||||||
unready_services: FuturesUnordered<UnreadyService<D::Key, D::Service, Request>>,
|
unready_services: FuturesUnordered<UnreadyService<D::Key, D::Service, Request>>,
|
||||||
|
|
@ -201,9 +212,22 @@ where
|
||||||
/// Channels used to cancel the request that an unready service is doing.
|
/// Channels used to cancel the request that an unready service is doing.
|
||||||
cancel_handles: HashMap<D::Key, oneshot::Sender<CancelClientWork>>,
|
cancel_handles: HashMap<D::Key, oneshot::Sender<CancelClientWork>>,
|
||||||
|
|
||||||
/// A channel that asks the peer crawler task to connect to more peers.
|
// Peer Validation
|
||||||
demand_signal: mpsc::Sender<MorePeers>,
|
//
|
||||||
|
/// An endpoint to see the minimum peer protocol version in real time.
|
||||||
|
///
|
||||||
|
/// The minimum version depends on the block height, and [`MinimumPeerVersion`] listens for
|
||||||
|
/// height changes and determines the correct minimum version.
|
||||||
|
minimum_peer_version: MinimumPeerVersion<C>,
|
||||||
|
|
||||||
|
/// The configured limit for inbound and outbound connections.
|
||||||
|
///
|
||||||
|
/// The peer set panics if this size is exceeded.
|
||||||
|
/// If that happens, our connection limit code has a bug.
|
||||||
|
peerset_total_connection_limit: usize,
|
||||||
|
|
||||||
|
// Background Tasks
|
||||||
|
//
|
||||||
/// Channel for passing ownership of tokio JoinHandles from PeerSet's background tasks
|
/// Channel for passing ownership of tokio JoinHandles from PeerSet's background tasks
|
||||||
///
|
///
|
||||||
/// The join handles passed into the PeerSet are used populate the `guards` member
|
/// The join handles passed into the PeerSet are used populate the `guards` member
|
||||||
|
|
@ -215,6 +239,8 @@ where
|
||||||
/// the `PeerSet` propagate errors from background tasks back to the user
|
/// the `PeerSet` propagate errors from background tasks back to the user
|
||||||
guards: futures::stream::FuturesUnordered<JoinHandle<Result<(), BoxError>>>,
|
guards: futures::stream::FuturesUnordered<JoinHandle<Result<(), BoxError>>>,
|
||||||
|
|
||||||
|
// Metrics and Logging
|
||||||
|
//
|
||||||
/// Address book metrics watch channel.
|
/// Address book metrics watch channel.
|
||||||
///
|
///
|
||||||
/// Used for logging diagnostics.
|
/// Used for logging diagnostics.
|
||||||
|
|
@ -222,18 +248,6 @@ where
|
||||||
|
|
||||||
/// The last time we logged a message about the peer set size
|
/// The last time we logged a message about the peer set size
|
||||||
last_peer_log: Option<Instant>,
|
last_peer_log: Option<Instant>,
|
||||||
|
|
||||||
/// The configured limit for inbound and outbound connections.
|
|
||||||
///
|
|
||||||
/// The peer set panics if this size is exceeded.
|
|
||||||
/// If that happens, our connection limit code has a bug.
|
|
||||||
peerset_total_connection_limit: usize,
|
|
||||||
|
|
||||||
/// An endpoint to see the minimum peer protocol version in real time.
|
|
||||||
///
|
|
||||||
/// The minimum version depends on the block height, and [`MinimumPeerVersion`] listens for
|
|
||||||
/// height changes and determines the correct minimum version.
|
|
||||||
minimum_peer_version: MinimumPeerVersion<C>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D, C> Drop for PeerSet<D, C>
|
impl<D, C> Drop for PeerSet<D, C>
|
||||||
|
|
@ -275,16 +289,23 @@ where
|
||||||
minimum_peer_version: MinimumPeerVersion<C>,
|
minimum_peer_version: MinimumPeerVersion<C>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
// Ready peers
|
// New peers
|
||||||
discover,
|
discover,
|
||||||
|
demand_signal,
|
||||||
|
|
||||||
|
// Ready peers
|
||||||
ready_services: HashMap::new(),
|
ready_services: HashMap::new(),
|
||||||
|
// Request Routing
|
||||||
preselected_p2c_peer: None,
|
preselected_p2c_peer: None,
|
||||||
inventory_registry: InventoryRegistry::new(inv_stream),
|
inventory_registry: InventoryRegistry::new(inv_stream),
|
||||||
|
|
||||||
// Unready peers
|
// Busy peers
|
||||||
unready_services: FuturesUnordered::new(),
|
unready_services: FuturesUnordered::new(),
|
||||||
cancel_handles: HashMap::new(),
|
cancel_handles: HashMap::new(),
|
||||||
demand_signal,
|
|
||||||
|
// Peer validation
|
||||||
|
minimum_peer_version,
|
||||||
|
peerset_total_connection_limit: config.peerset_total_connection_limit(),
|
||||||
|
|
||||||
// Background tasks
|
// Background tasks
|
||||||
handle_rx,
|
handle_rx,
|
||||||
|
|
@ -293,10 +314,6 @@ where
|
||||||
// Metrics
|
// Metrics
|
||||||
last_peer_log: None,
|
last_peer_log: None,
|
||||||
address_metrics,
|
address_metrics,
|
||||||
peerset_total_connection_limit: config.peerset_total_connection_limit(),
|
|
||||||
|
|
||||||
// Real-time parameters
|
|
||||||
minimum_peer_version,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
//! Peer set unit tests, and test setup code.
|
||||||
|
|
||||||
use std::{net::SocketAddr, sync::Arc};
|
use std::{net::SocketAddr, sync::Arc};
|
||||||
|
|
||||||
use futures::{channel::mpsc, stream, Stream, StreamExt};
|
use futures::{channel::mpsc, stream, Stream, StreamExt};
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
//! Randomised property tests for the peer set.
|
||||||
|
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue