Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bound most NetworkBuilder methods by NetworkPrimitives generic #13119

Merged
merged 1 commit into from
Dec 4, 2024
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
4 changes: 2 additions & 2 deletions crates/net/eth-wire/tests/pooled_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use alloy_eips::eip2718::Decodable2718;
use alloy_primitives::hex;
use alloy_rlp::{Decodable, Encodable};
use reth_eth_wire::{EthVersion, PooledTransactions, ProtocolMessage};
use reth_eth_wire::{EthNetworkPrimitives, EthVersion, PooledTransactions, ProtocolMessage};
use reth_primitives::PooledTransactionsElement;
use std::{fs, path::PathBuf};
use test_fuzz::test_fuzz;
Expand Down Expand Up @@ -51,7 +51,7 @@ fn decode_request_pair_pooled_blob_transactions() {
.join("testdata/request_pair_pooled_blob_transactions");
let data = fs::read_to_string(network_data_path).expect("Unable to read file");
let hex_data = hex::decode(data.trim()).unwrap();
let _txs: ProtocolMessage =
let _txs: ProtocolMessage<EthNetworkPrimitives> =
ProtocolMessage::decode_message(EthVersion::Eth68, &mut &hex_data[..]).unwrap();
}

Expand Down
40 changes: 21 additions & 19 deletions crates/net/network/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,50 @@ pub struct NetworkBuilder<Tx, Eth, N: NetworkPrimitives = EthNetworkPrimitives>

// === impl NetworkBuilder ===

impl<Tx, Eth> NetworkBuilder<Tx, Eth> {
impl<Tx, Eth, N: NetworkPrimitives> NetworkBuilder<Tx, Eth, N> {
/// Consumes the type and returns all fields.
pub fn split(self) -> (NetworkManager, Tx, Eth) {
pub fn split(self) -> (NetworkManager<N>, Tx, Eth) {
let Self { network, transactions, request_handler } = self;
(network, transactions, request_handler)
}

/// Returns the network manager.
pub const fn network(&self) -> &NetworkManager {
pub const fn network(&self) -> &NetworkManager<N> {
&self.network
}

/// Returns the mutable network manager.
pub fn network_mut(&mut self) -> &mut NetworkManager {
pub fn network_mut(&mut self) -> &mut NetworkManager<N> {
&mut self.network
}

/// Returns the handle to the network.
pub fn handle(&self) -> NetworkHandle {
pub fn handle(&self) -> NetworkHandle<N> {
self.network.handle().clone()
}

/// Consumes the type and returns all fields and also return a [`NetworkHandle`].
pub fn split_with_handle(self) -> (NetworkHandle, NetworkManager, Tx, Eth) {
pub fn split_with_handle(self) -> (NetworkHandle<N>, NetworkManager<N>, Tx, Eth) {
let Self { network, transactions, request_handler } = self;
let handle = network.handle().clone();
(handle, network, transactions, request_handler)
}

/// Creates a new [`EthRequestHandler`] and wires it to the network.
pub fn request_handler<Client>(
self,
client: Client,
) -> NetworkBuilder<Tx, EthRequestHandler<Client, N>, N> {
let Self { mut network, transactions, .. } = self;
let (tx, rx) = mpsc::channel(ETH_REQUEST_CHANNEL_CAPACITY);
network.set_eth_request_handler(tx);
let peers = network.handle().peers_handle().clone();
let request_handler = EthRequestHandler::new(client, peers, rx);
NetworkBuilder { network, request_handler, transactions }
}
}

impl<Tx, Eth> NetworkBuilder<Tx, Eth> {
/// Creates a new [`TransactionsManager`] and wires it to the network.
pub fn transactions<Pool: TransactionPool>(
self,
Expand All @@ -66,17 +81,4 @@ impl<Tx, Eth> NetworkBuilder<Tx, Eth> {
let transactions = TransactionsManager::new(handle, pool, rx, transactions_manager_config);
NetworkBuilder { network, request_handler, transactions }
}

/// Creates a new [`EthRequestHandler`] and wires it to the network.
pub fn request_handler<Client>(
self,
client: Client,
) -> NetworkBuilder<Tx, EthRequestHandler<Client>> {
let Self { mut network, transactions, .. } = self;
let (tx, rx) = mpsc::channel(ETH_REQUEST_CHANNEL_CAPACITY);
network.set_eth_request_handler(tx);
let peers = network.handle().peers_handle().clone();
let request_handler = EthRequestHandler::new(client, peers, rx);
NetworkBuilder { network, request_handler, transactions }
}
}
2 changes: 1 addition & 1 deletion crates/net/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<N: NetworkPrimitives> NetworkConfig<(), N> {
}

/// Convenience method for creating the corresponding builder type with a random secret key.
pub fn builder_with_rng_secret_key() -> NetworkConfigBuilder {
pub fn builder_with_rng_secret_key() -> NetworkConfigBuilder<N> {
NetworkConfigBuilder::with_rng_secret_key()
}
}
Expand Down
Loading