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: add helper trait for BlockReader tied to NetworkPrimitives #13449

Merged
merged 1 commit into from
Dec 19, 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
10 changes: 4 additions & 6 deletions crates/node/builder/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
components::NodeComponentsBuilder,
node::FullNode,
rpc::{RethRpcAddOns, RethRpcServerHandles, RpcContext},
DefaultNodeLauncher, LaunchNode, Node, NodeHandle,
BlockReaderFor, DefaultNodeLauncher, LaunchNode, Node, NodeHandle,
};
use alloy_eips::eip4844::env_settings::EnvKzgSettings;
use futures::Future;
Expand Down Expand Up @@ -35,7 +35,7 @@ use reth_node_core::{
};
use reth_provider::{
providers::{BlockchainProvider, NodeTypesForProvider},
BlockReader, ChainSpecProvider, FullProvider,
ChainSpecProvider, FullProvider,
};
use reth_tasks::TaskExecutor;
use reth_transaction_pool::{PoolConfig, PoolTransaction, TransactionPool};
Expand Down Expand Up @@ -662,8 +662,7 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
>,
> + Unpin
+ 'static,
Node::Provider:
BlockReader<Receipt = N::Receipt, Block = N::Block, Header = N::BlockHeader>,
Node::Provider: BlockReaderFor<N>,
{
self.start_network_with(builder, pool, Default::default())
}
Expand All @@ -689,8 +688,7 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
>,
> + Unpin
+ 'static,
Node::Provider:
BlockReader<Receipt = N::Receipt, Block = N::Block, Header = N::BlockHeader>,
Node::Provider: BlockReaderFor<N>,
{
let (handle, network, txpool, eth) = builder
.transactions(pool, tx_config)
Expand Down
29 changes: 27 additions & 2 deletions crates/node/builder/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ use std::{
sync::Arc,
};

use reth_node_api::{EngineTypes, FullNodeComponents};
use reth_network::NetworkPrimitives;
use reth_node_api::{BlockBody, EngineTypes, FullNodeComponents};
use reth_node_core::{
dirs::{ChainPath, DataDirPath},
node_config::NodeConfig,
};
use reth_payload_builder::PayloadBuilderHandle;
use reth_provider::ChainSpecProvider;
use reth_provider::{BlockReader, ChainSpecProvider};
use reth_rpc_api::EngineApiClient;
use reth_rpc_builder::{auth::AuthServerHandle, RpcServerHandle};
use reth_tasks::TaskExecutor;
Expand Down Expand Up @@ -210,3 +211,27 @@ impl<Node: FullNodeComponents, AddOns: NodeAddOns<Node>> DerefMut for FullNode<N
&mut self.add_ons_handle
}
}

/// This is a type alias to make type bounds simpler, when we have a [`NetworkPrimitives`] and need
/// a [`BlockReader`] whose associated types match the [`NetworkPrimitives`] associated types.
pub trait BlockReaderFor<N: NetworkPrimitives>:
BlockReader<
Block = N::Block,
Header = N::BlockHeader,
Transaction = <N::BlockBody as BlockBody>::Transaction,
Receipt = N::Receipt,
>
{
}

impl<N, T> BlockReaderFor<N> for T
where
N: NetworkPrimitives,
T: BlockReader<
Block = N::Block,
Header = N::BlockHeader,
Transaction = <N::BlockBody as BlockBody>::Transaction,
Receipt = N::Receipt,
>,
{
}
Loading