mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore(net): move reth_network::BlockDownloaderProvider to reth-network-api (#10003)
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -7558,7 +7558,9 @@ dependencies = [
|
|||||||
"alloy-rpc-types-admin",
|
"alloy-rpc-types-admin",
|
||||||
"auto_impl",
|
"auto_impl",
|
||||||
"enr",
|
"enr",
|
||||||
|
"futures",
|
||||||
"reth-eth-wire",
|
"reth-eth-wire",
|
||||||
|
"reth-network-p2p",
|
||||||
"reth-network-peers",
|
"reth-network-peers",
|
||||||
"reth-network-types",
|
"reth-network-types",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@ -17,6 +17,7 @@ reth-eth-wire.workspace = true
|
|||||||
alloy-rpc-types-admin.workspace = true
|
alloy-rpc-types-admin.workspace = true
|
||||||
reth-network-peers.workspace = true
|
reth-network-peers.workspace = true
|
||||||
reth-network-types.workspace = true
|
reth-network-types.workspace = true
|
||||||
|
reth-network-p2p.workspace = true
|
||||||
|
|
||||||
# ethereum
|
# ethereum
|
||||||
alloy-primitives.workspace = true
|
alloy-primitives.workspace = true
|
||||||
@ -24,6 +25,9 @@ alloy-primitives.workspace = true
|
|||||||
# eth
|
# eth
|
||||||
enr = { workspace = true, default-features = false, features = ["rust-secp256k1"] }
|
enr = { workspace = true, default-features = false, features = ["rust-secp256k1"] }
|
||||||
|
|
||||||
|
# async
|
||||||
|
futures.workspace = true
|
||||||
|
|
||||||
# misc
|
# misc
|
||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
serde = { workspace = true, features = ["derive"], optional = true }
|
serde = { workspace = true, features = ["derive"], optional = true }
|
||||||
|
|||||||
16
crates/net/network-api/src/downloaders.rs
Normal file
16
crates/net/network-api/src/downloaders.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
//! API related to syncing blocks.
|
||||||
|
|
||||||
|
use futures::Future;
|
||||||
|
use reth_network_p2p::BlockClient;
|
||||||
|
use tokio::sync::oneshot;
|
||||||
|
|
||||||
|
/// Provides client for downloading blocks.
|
||||||
|
#[auto_impl::auto_impl(&, Arc)]
|
||||||
|
pub trait BlockDownloaderProvider {
|
||||||
|
/// Returns a new [`BlockClient`], used for fetching blocks from peers.
|
||||||
|
///
|
||||||
|
/// The client is the entrypoint for sending block requests to the network.
|
||||||
|
fn fetch_client(
|
||||||
|
&self,
|
||||||
|
) -> impl Future<Output = Result<impl BlockClient + 'static, oneshot::error::RecvError>> + Send;
|
||||||
|
}
|
||||||
@ -13,15 +13,19 @@
|
|||||||
)]
|
)]
|
||||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||||
|
|
||||||
|
pub mod downloaders;
|
||||||
/// Network Error
|
/// Network Error
|
||||||
pub mod error;
|
pub mod error;
|
||||||
/// Implementation of network traits for that does nothing.
|
/// Implementation of network traits for that does nothing.
|
||||||
pub mod noop;
|
pub mod noop;
|
||||||
|
|
||||||
pub use alloy_rpc_types_admin::EthProtocolInfo;
|
pub use alloy_rpc_types_admin::EthProtocolInfo;
|
||||||
pub use error::NetworkError;
|
pub use reth_network_p2p::BlockClient;
|
||||||
pub use reth_network_types::{PeerKind, PeersHandle, Reputation, ReputationChangeKind};
|
pub use reth_network_types::{PeerKind, PeersHandle, Reputation, ReputationChangeKind};
|
||||||
|
|
||||||
|
pub use downloaders::BlockDownloaderProvider;
|
||||||
|
pub use error::NetworkError;
|
||||||
|
|
||||||
use std::{future::Future, net::SocketAddr, sync::Arc, time::Instant};
|
use std::{future::Future, net::SocketAddr, sync::Arc, time::Instant};
|
||||||
|
|
||||||
use reth_eth_wire::{capability::Capabilities, DisconnectReason, EthVersion, Status};
|
use reth_eth_wire::{capability::Capabilities, DisconnectReason, EthVersion, Status};
|
||||||
|
|||||||
@ -138,7 +138,9 @@ mod state;
|
|||||||
mod swarm;
|
mod swarm;
|
||||||
|
|
||||||
pub use reth_eth_wire::{DisconnectReason, HelloMessageWithProtocols};
|
pub use reth_eth_wire::{DisconnectReason, HelloMessageWithProtocols};
|
||||||
pub use reth_network_api::{NetworkInfo, Peers, PeersHandleProvider, PeersInfo};
|
pub use reth_network_api::{
|
||||||
|
BlockDownloaderProvider, NetworkInfo, Peers, PeersHandleProvider, PeersInfo,
|
||||||
|
};
|
||||||
pub use reth_network_p2p::sync::{NetworkSyncUpdater, SyncState};
|
pub use reth_network_p2p::sync::{NetworkSyncUpdater, SyncState};
|
||||||
pub use reth_network_types::{PeersConfig, SessionsConfig};
|
pub use reth_network_types::{PeersConfig, SessionsConfig};
|
||||||
pub use session::{
|
pub use session::{
|
||||||
@ -155,8 +157,6 @@ pub use flattened_response::FlattenedResponse;
|
|||||||
pub use manager::{DiscoveredEvent, NetworkEvent, NetworkManager};
|
pub use manager::{DiscoveredEvent, NetworkEvent, NetworkManager};
|
||||||
pub use message::PeerRequest;
|
pub use message::PeerRequest;
|
||||||
pub use metrics::TxTypesCounter;
|
pub use metrics::TxTypesCounter;
|
||||||
pub use network::{
|
pub use network::{FullNetwork, NetworkEvents, NetworkHandle, NetworkProtocols};
|
||||||
BlockDownloaderProvider, FullNetwork, NetworkEvents, NetworkHandle, NetworkProtocols,
|
|
||||||
};
|
|
||||||
pub use swarm::NetworkConnectionState;
|
pub use swarm::NetworkConnectionState;
|
||||||
pub use transactions::{FilterAnnouncement, MessageFilter, ValidateTx68};
|
pub use transactions::{FilterAnnouncement, MessageFilter, ValidateTx68};
|
||||||
|
|||||||
@ -7,14 +7,17 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use enr::Enr;
|
use enr::Enr;
|
||||||
use futures::Future;
|
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use reth_discv4::Discv4;
|
use reth_discv4::Discv4;
|
||||||
use reth_eth_wire::{DisconnectReason, NewBlock, NewPooledTransactionHashes, SharedTransactions};
|
use reth_eth_wire::{DisconnectReason, NewBlock, NewPooledTransactionHashes, SharedTransactions};
|
||||||
use reth_network_api::{
|
use reth_network_api::{
|
||||||
NetworkError, NetworkInfo, NetworkStatus, PeerInfo, Peers, PeersHandleProvider, PeersInfo,
|
BlockDownloaderProvider, NetworkError, NetworkInfo, NetworkStatus, PeerInfo, Peers,
|
||||||
|
PeersHandleProvider, PeersInfo,
|
||||||
|
};
|
||||||
|
use reth_network_p2p::{
|
||||||
|
sync::{NetworkSyncUpdater, SyncState, SyncStateProvider},
|
||||||
|
BlockClient,
|
||||||
};
|
};
|
||||||
use reth_network_p2p::sync::{NetworkSyncUpdater, SyncState, SyncStateProvider};
|
|
||||||
use reth_network_peers::{NodeRecord, PeerId};
|
use reth_network_peers::{NodeRecord, PeerId};
|
||||||
use reth_network_types::{PeerAddr, PeerKind, PeersHandle, Reputation, ReputationChangeKind};
|
use reth_network_types::{PeerAddr, PeerKind, PeersHandle, Reputation, ReputationChangeKind};
|
||||||
use reth_primitives::{Head, TransactionSigned, B256};
|
use reth_primitives::{Head, TransactionSigned, B256};
|
||||||
@ -393,19 +396,8 @@ impl NetworkSyncUpdater for NetworkHandle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Provides [`FetchClient`] for downloading blocks.
|
|
||||||
#[auto_impl::auto_impl(&, Arc)]
|
|
||||||
pub trait BlockDownloaderProvider {
|
|
||||||
/// Returns a new [`FetchClient`] that can be cloned and shared.
|
|
||||||
///
|
|
||||||
/// The [`FetchClient`] is the entrypoint for sending requests to the network.
|
|
||||||
fn fetch_client(
|
|
||||||
&self,
|
|
||||||
) -> impl Future<Output = Result<FetchClient, oneshot::error::RecvError>> + Send;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BlockDownloaderProvider for NetworkHandle {
|
impl BlockDownloaderProvider for NetworkHandle {
|
||||||
async fn fetch_client(&self) -> Result<FetchClient, oneshot::error::RecvError> {
|
async fn fetch_client(&self) -> Result<impl BlockClient + 'static, oneshot::error::RecvError> {
|
||||||
let (tx, rx) = oneshot::channel();
|
let (tx, rx) = oneshot::channel();
|
||||||
let _ = self.manager().send(NetworkHandleMessage::FetchClient(tx));
|
let _ = self.manager().send(NetworkHandleMessage::FetchClient(tx));
|
||||||
rx.await
|
rx.await
|
||||||
|
|||||||
@ -47,4 +47,11 @@ pub mod test_utils;
|
|||||||
|
|
||||||
pub mod reputation;
|
pub mod reputation;
|
||||||
|
|
||||||
|
pub use bodies::client::BodiesClient;
|
||||||
|
pub use headers::client::HeadersClient;
|
||||||
pub use reputation::{Reputation, ReputationChange, ReputationChangeKind, ReputationChangeWeights};
|
pub use reputation::{Reputation, ReputationChange, ReputationChangeKind, ReputationChangeWeights};
|
||||||
|
|
||||||
|
/// Helper trait that unifies network behaviour needed for fetching blocks.
|
||||||
|
pub trait BlockClient: HeadersClient + BodiesClient + Unpin + Clone {}
|
||||||
|
|
||||||
|
impl<T> BlockClient for T where T: HeadersClient + BodiesClient + Unpin + Clone {}
|
||||||
|
|||||||
Reference in New Issue
Block a user