feat: relax chainspec bounds on NodeBuilder and rpc types (#11160)

This commit is contained in:
Arsenii Kulikov
2024-09-24 20:47:04 +03:00
committed by GitHub
parent d3114b4eec
commit ae3d279cc3
38 changed files with 222 additions and 157 deletions

View File

@@ -10,7 +10,7 @@ pub use states::*;
use std::sync::Arc;
use futures::Future;
use reth_chainspec::{ChainSpec, EthChainSpec};
use reth_chainspec::{ChainSpec, EthChainSpec, EthereumHardforks};
use reth_cli_util::get_secret_key;
use reth_db_api::{
database::Database,
@@ -209,9 +209,10 @@ impl<DB, ChainSpec: EthChainSpec> NodeBuilder<DB, ChainSpec> {
}
}
impl<DB> NodeBuilder<DB, ChainSpec>
impl<DB, ChainSpec> NodeBuilder<DB, ChainSpec>
where
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
ChainSpec: EthChainSpec + EthereumHardforks,
{
/// Configures the types of the node.
pub fn with_types<T>(self) -> NodeBuilderWithTypes<RethFullAdapter<DB, T>>
@@ -269,9 +270,10 @@ impl<DB, ChainSpec> WithLaunchContext<NodeBuilder<DB, ChainSpec>> {
}
}
impl<DB> WithLaunchContext<NodeBuilder<DB, ChainSpec>>
impl<DB, ChainSpec> WithLaunchContext<NodeBuilder<DB, ChainSpec>>
where
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
ChainSpec: EthChainSpec + EthereumHardforks,
{
/// Configures the types of the node.
pub fn with_types<T>(self) -> WithLaunchContext<NodeBuilderWithTypes<RethFullAdapter<DB, T>>>
@@ -483,7 +485,7 @@ where
impl<T, DB, CB, AO> WithLaunchContext<NodeBuilderWithComponents<RethFullAdapter<DB, T>, CB, AO>>
where
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
T: NodeTypesWithEngine<ChainSpec = ChainSpec>,
T: NodeTypesWithEngine<ChainSpec: EthereumHardforks + EthChainSpec>,
CB: NodeComponentsBuilder<RethFullAdapter<DB, T>>,
AO: NodeAddOns<
NodeAdapter<RethFullAdapter<DB, T>, CB::Components>,

View File

@@ -39,7 +39,7 @@ use reth_node_metrics::{
};
use reth_primitives::Head;
use reth_provider::{
providers::{BlockchainProvider, BlockchainProvider2, StaticFileProvider},
providers::{BlockchainProvider, BlockchainProvider2, ProviderNodeTypes, StaticFileProvider},
BlockHashReader, CanonStateNotificationSender, ChainSpecProvider, ProviderFactory,
ProviderResult, StageCheckpointReader, StateProviderFactory, StaticFileProviderFactory,
TreeViewer,
@@ -483,7 +483,7 @@ where
impl<T> LaunchContextWith<Attached<WithConfigs<T::ChainSpec>, ProviderFactory<T>>>
where
T: NodeTypesWithDB<ChainSpec = ChainSpec>,
T: NodeTypesWithDB<ChainSpec: EthereumHardforks + EthChainSpec>,
{
/// Returns access to the underlying database.
pub const fn database(&self) -> &T::DB {
@@ -523,7 +523,7 @@ where
target_triple: VERGEN_CARGO_TARGET_TRIPLE,
build_profile: BUILD_PROFILE_NAME,
},
ChainSpecInfo { name: self.left().config.chain.chain.to_string() },
ChainSpecInfo { name: self.left().config.chain.chain().to_string() },
self.task_executor().clone(),
Hooks::new(self.database().clone(), self.static_file_provider()),
);
@@ -621,7 +621,7 @@ impl<T>
Attached<WithConfigs<<T::Types as NodeTypes>::ChainSpec>, WithMeteredProviders<T>>,
>
where
T: FullNodeTypes<Types: NodeTypesWithDB<ChainSpec = ChainSpec>, Provider: WithTree>,
T: FullNodeTypes<Types: ProviderNodeTypes, Provider: WithTree>,
{
/// Returns access to the underlying database.
pub const fn database(&self) -> &<T::Types as NodeTypesWithDB>::DB {
@@ -746,7 +746,10 @@ impl<T, CB>
Attached<WithConfigs<<T::Types as NodeTypes>::ChainSpec>, WithComponents<T, CB>>,
>
where
T: FullNodeTypes<Provider: WithTree, Types: NodeTypes<ChainSpec = ChainSpec>>,
T: FullNodeTypes<
Provider: WithTree,
Types: NodeTypes<ChainSpec: EthChainSpec + EthereumHardforks>,
>,
CB: NodeComponentsBuilder<T>,
{
/// Returns the configured `ProviderFactory`.

View File

@@ -18,7 +18,7 @@ use reth_beacon_consensus::{
BeaconConsensusEngine,
};
use reth_blockchain_tree::{noop::NoopBlockchainTree, BlockchainTreeConfig};
use reth_chainspec::ChainSpec;
use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_consensus_debug_client::{DebugConsensusClient, EtherscanBlockProvider, RpcBlockProvider};
use reth_engine_util::EngineMessageStreamExt;
use reth_exex::ExExManagerHandle;
@@ -106,7 +106,7 @@ impl DefaultNodeLauncher {
impl<Types, T, CB, AO> LaunchNode<NodeBuilderWithComponents<T, CB, AO>> for DefaultNodeLauncher
where
Types: NodeTypesWithDB<ChainSpec = ChainSpec> + NodeTypesWithEngine,
Types: NodeTypesWithDB<ChainSpec: EthereumHardforks + EthChainSpec> + NodeTypesWithEngine,
T: FullNodeTypes<Provider = BlockchainProvider<Types>, Types = Types>,
CB: NodeComponentsBuilder<T>,
AO: NodeAddOns<
@@ -165,7 +165,7 @@ where
debug!(target: "reth::cli", chain=%this.chain_id(), genesis=?this.genesis_hash(), "Initializing genesis");
})
.with_genesis()?
.inspect(|this: &LaunchContextWith<Attached<WithConfigs<ChainSpec>, _>>| {
.inspect(|this: &LaunchContextWith<Attached<WithConfigs<Types::ChainSpec>, _>>| {
info!(target: "reth::cli", "\n{}", this.chain_spec().display_hardforks());
})
.with_metrics_task()
@@ -223,7 +223,7 @@ where
let (pipeline, client) = if ctx.is_dev() {
info!(target: "reth::cli", "Starting Reth in dev mode");
for (idx, (address, alloc)) in ctx.chain_spec().genesis.alloc.iter().enumerate() {
for (idx, (address, alloc)) in ctx.chain_spec().genesis().alloc.iter().enumerate() {
info!(target: "reth::cli", "Allocated Genesis Account: {:02}. {} ({} ETH)", idx, address.to_string(), format_ether(alloc.balance));
}
@@ -384,7 +384,7 @@ where
if let Some(maybe_custom_etherscan_url) = ctx.node_config().debug.etherscan.clone() {
info!(target: "reth::cli", "Using etherscan as consensus client");
let chain = ctx.node_config().chain.chain;
let chain = ctx.node_config().chain.chain();
let etherscan_url = maybe_custom_etherscan_url.map(Ok).unwrap_or_else(|| {
// If URL isn't provided, use default Etherscan URL for the chain if it is known
chain

View File

@@ -6,10 +6,7 @@ use std::{
};
use futures::TryFutureExt;
use reth_chainspec::ChainSpec;
use reth_node_api::{
BuilderProvider, FullNodeComponents, NodeTypes, NodeTypesWithDB, NodeTypesWithEngine,
};
use reth_node_api::{BuilderProvider, FullNodeComponents, NodeTypes, NodeTypesWithEngine};
use reth_node_core::{
node_config::NodeConfig,
rpc::{
@@ -18,6 +15,7 @@ use reth_node_core::{
},
};
use reth_payload_builder::PayloadBuilderHandle;
use reth_provider::providers::ProviderNodeTypes;
use reth_rpc_builder::{
auth::{AuthRpcModule, AuthServerHandle},
config::RethRpcServerConfig,
@@ -298,12 +296,12 @@ where
pub async fn launch_rpc_servers<Node, Engine, EthApi>(
node: Node,
engine_api: Engine,
config: &NodeConfig<ChainSpec>,
config: &NodeConfig<<Node::Types as NodeTypes>::ChainSpec>,
jwt_secret: JwtSecret,
add_ons: RpcAddOns<Node, EthApi>,
) -> eyre::Result<(RethRpcServerHandles, RpcRegistry<Node, EthApi>)>
where
Node: FullNodeComponents<Types: NodeTypesWithDB<ChainSpec = ChainSpec>> + Clone,
Node: FullNodeComponents<Types: ProviderNodeTypes> + Clone,
Engine: EngineApiServer<<Node::Types as NodeTypesWithEngine>::Engine>,
EthApi: EthApiBuilderProvider<Node> + FullEthApiServer,
{