Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions crates/net/network-api/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use reth_primitives_traits::Block;
use alloy_primitives::B256;
use reth_tokio_util::EventStream;
use tokio::sync::oneshot;

Expand All @@ -13,14 +13,14 @@ pub struct NewBlockWithPeer<B> {
}

/// Provides a listener for new blocks on the eth wire protocol.
pub trait EthWireBlockListenerProvider {
/// The network primitives.
type Block: Block;

pub trait EthWireProvider<N: NetworkPrimitives> {
/// Create a new eth wire block listener.
fn eth_wire_block_listener(
&self,
) -> impl Future<
Output = Result<EventStream<NewBlockWithPeer<Self::Block>>, oneshot::error::RecvError>,
Output = Result<EventStream<NewBlockWithPeer<N::Block>>, oneshot::error::RecvError>,
> + Send;

/// Announce a new block to the network over the eth wire protocol.
fn eth_wire_announce_block(&self, block: N::NewBlockPayload, hash: B256);
}
6 changes: 3 additions & 3 deletions crates/net/network-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub mod noop;
pub mod block;

pub mod test_utils;
use block::EthWireBlockListenerProvider;
use block::EthWireProvider;
use test_utils::PeersHandleProvider;

pub use alloy_rpc_types_admin::EthProtocolInfo;
Expand Down Expand Up @@ -58,7 +58,7 @@ pub trait FullNetwork:
+ NetworkEventListenerProvider
+ Peers
+ PeersHandleProvider
+ EthWireBlockListenerProvider<Block = <Self::Primitives as NetworkPrimitives>::Block>
+ EthWireProvider<Self::Primitives>
+ Clone
+ Unpin
+ 'static
Expand All @@ -73,7 +73,7 @@ impl<T> FullNetwork for T where
+ NetworkEventListenerProvider
+ Peers
+ PeersHandleProvider
+ EthWireBlockListenerProvider<Block = <Self::Primitives as NetworkPrimitives>::Block>
+ EthWireProvider<Self::Primitives>
+ Clone
+ Unpin
+ 'static
Expand Down
16 changes: 11 additions & 5 deletions crates/net/network-api/src/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use core::{fmt, marker::PhantomData};
use std::net::{IpAddr, SocketAddr};

use crate::{
block::{EthWireBlockListenerProvider, NewBlockWithPeer},
block::{EthWireProvider, NewBlockWithPeer},
events::{NetworkPeersEvents, PeerEventStream},
test_utils::{PeersHandle, PeersHandleProvider},
BlockDownloaderProvider, DiscoveryEvent, NetworkError, NetworkEvent,
Expand Down Expand Up @@ -201,12 +201,18 @@ where
}
}

impl<N: NetworkPrimitives> EthWireBlockListenerProvider for NoopNetwork<N> {
type Block = N::Block;

impl<N: NetworkPrimitives> EthWireProvider<N> for NoopNetwork<N> {
async fn eth_wire_block_listener(
&self,
) -> Result<EventStream<NewBlockWithPeer<Self::Block>>, RecvError> {
) -> Result<EventStream<NewBlockWithPeer<N::Block>>, RecvError> {
unreachable!()
}

fn eth_wire_announce_block(
&self,
_block: <N as NetworkPrimitives>::NewBlockPayload,
_hash: alloy_primitives::B256,
) {
unreachable!()
}
}
Expand Down
12 changes: 7 additions & 5 deletions crates/net/network/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use reth_eth_wire::{
};
use reth_ethereum_forks::Head;
use reth_network_api::{
block::{EthWireBlockListenerProvider, NewBlockWithPeer},
block::{EthWireProvider, NewBlockWithPeer},
events::{NetworkPeersEvents, PeerEvent, PeerEventStream},
test_utils::{PeersHandle, PeersHandleProvider},
BlockDownloaderProvider, DiscoveryEvent, NetworkError, NetworkEvent,
Expand Down Expand Up @@ -225,16 +225,18 @@ impl<N: NetworkPrimitives> NetworkEventListenerProvider for NetworkHandle<N> {
}
}

impl<N: NetworkPrimitives> EthWireBlockListenerProvider for NetworkHandle<N> {
type Block = <N as NetworkPrimitives>::Block;

impl<N: NetworkPrimitives> EthWireProvider<N> for NetworkHandle<N> {
async fn eth_wire_block_listener(
&self,
) -> Result<EventStream<NewBlockWithPeer<Self::Block>>, oneshot::error::RecvError> {
) -> Result<EventStream<NewBlockWithPeer<N::Block>>, oneshot::error::RecvError> {
let (tx, rx) = oneshot::channel();
self.send_message(NetworkHandleMessage::EthWireBlockListener(tx));
rx.await
}

fn eth_wire_announce_block(&self, block: N::NewBlockPayload, hash: B256) {
self.announce_block(block, hash)
}
}

impl<N: NetworkPrimitives> NetworkProtocols for NetworkHandle<N> {
Expand Down