Skip to content

Commit

Permalink
feat(storage): replace Tree generic with Arc<dyn TreeViewer> (paradig…
Browse files Browse the repository at this point in the history
…mxyz#7810)

Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
KyrylR and mattsse authored Apr 23, 2024
1 parent a8a434d commit c659e28
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 113 deletions.
2 changes: 1 addition & 1 deletion bin/reth/src/commands/debug_cmd/build_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl Command {
EvmProcessorFactory::new(self.chain.clone(), evm_config),
);
let tree = BlockchainTree::new(tree_externals, BlockchainTreeConfig::default(), None)?;
let blockchain_tree = ShareableBlockchainTree::new(tree);
let blockchain_tree = Arc::new(ShareableBlockchainTree::new(tree));

// fetch the best block from the database
let best_block =
Expand Down
5 changes: 2 additions & 3 deletions bin/reth/src/commands/debug_cmd/replay_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,10 @@ impl Command {
EvmProcessorFactory::new(self.chain.clone(), evm_config),
);
let tree = BlockchainTree::new(tree_externals, BlockchainTreeConfig::default(), None)?;
let blockchain_tree = ShareableBlockchainTree::new(tree);
let blockchain_tree = Arc::new(ShareableBlockchainTree::new(tree));

// Set up the blockchain provider
let blockchain_db =
BlockchainProvider::new(provider_factory.clone(), blockchain_tree.clone())?;
let blockchain_db = BlockchainProvider::new(provider_factory.clone(), blockchain_tree)?;

// Set up network
let network_secret_path =
Expand Down
12 changes: 3 additions & 9 deletions crates/consensus/beacon/src/engine/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,7 @@ type DatabaseEnv = TempDatabase<DE>;

type TestBeaconConsensusEngine<Client> = BeaconConsensusEngine<
Arc<DatabaseEnv>,
BlockchainProvider<
Arc<DatabaseEnv>,
ShareableBlockchainTree<
Arc<DatabaseEnv>,
EitherExecutorFactory<TestExecutorFactory, EvmProcessorFactory<EthEvmConfig>>,
>,
>,
BlockchainProvider<Arc<DatabaseEnv>>,
Arc<EitherDownloader<Client, NoopFullBlockClient>>,
EthEngineTypes,
>;
Expand Down Expand Up @@ -423,9 +417,9 @@ where
// Setup blockchain tree
let externals = TreeExternals::new(provider_factory.clone(), consensus, executor_factory);
let config = BlockchainTreeConfig::new(1, 2, 3, 2);
let tree = ShareableBlockchainTree::new(
let tree = Arc::new(ShareableBlockchainTree::new(
BlockchainTree::new(externals, config, None).expect("failed to create tree"),
);
));
let latest = self.base_config.chain_spec.genesis_header().seal_slow();
let blockchain_provider =
BlockchainProvider::with_latest(provider_factory.clone(), tree, latest);
Expand Down
8 changes: 2 additions & 6 deletions crates/e2e-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use node::NodeHelper;
use reth::{
args::{DiscoveryArgs, NetworkArgs, RpcServerArgs},
blockchain_tree::ShareableBlockchainTree,
builder::{NodeBuilder, NodeConfig, NodeHandle},
revm::EvmProcessorFactory,
tasks::TaskManager,
};
use reth_db::{test_utils::TempDatabase, DatabaseEnv};
use reth_node_builder::{
components::{NetworkBuilder, PayloadServiceBuilder, PoolBuilder},
FullNodeComponentsAdapter, FullNodeTypesAdapter, NodeTypes,
FullNodeComponentsAdapter, FullNodeTypesAdapter,
};
use reth_primitives::ChainSpec;
use reth_provider::providers::BlockchainProvider;
Expand Down Expand Up @@ -100,12 +98,10 @@ where
// Type aliases

type TmpDB = Arc<TempDatabase<DatabaseEnv>>;
type EvmType<N> = EvmProcessorFactory<<N as NodeTypes>::Evm>;
type RethProvider<N> = BlockchainProvider<TmpDB, ShareableBlockchainTree<TmpDB, EvmType<N>>>;
type TmpPool<N> = <<N as reth_node_builder::Node<TmpNodeAdapter<N>>>::PoolBuilder as PoolBuilder<
TmpNodeAdapter<N>,
>>::Pool;
type TmpNodeAdapter<N> = FullNodeTypesAdapter<N, TmpDB, RethProvider<N>>;
type TmpNodeAdapter<N> = FullNodeTypesAdapter<N, TmpDB, BlockchainProvider<TmpDB>>;

/// Type alias for a type of NodeHelper
pub type NodeHelperType<N> = NodeHelper<FullNodeComponentsAdapter<TmpNodeAdapter<N>, TmpPool<N>>>;
67 changes: 29 additions & 38 deletions crates/node-builder/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,9 @@ use tokio::sync::{mpsc::unbounded_channel, oneshot};

/// The builtin provider type of the reth node.
// Note: we need to hardcode this because custom components might depend on it in associated types.
type RethFullProviderType<DB, Evm> =
BlockchainProvider<DB, ShareableBlockchainTree<DB, EvmProcessorFactory<Evm>>>;
type RethFullProviderType<DB> = BlockchainProvider<DB>;

type RethFullAdapter<DB, N> =
FullNodeTypesAdapter<N, DB, RethFullProviderType<DB, <N as NodeTypes>::Evm>>;
type RethFullAdapter<DB, N> = FullNodeTypesAdapter<N, DB, RethFullProviderType<DB>>;

#[cfg_attr(doc, aquamarine::aquamarine)]
/// Declaratively construct a node.
Expand Down Expand Up @@ -278,7 +276,7 @@ where
>,
>
where
N: Node<FullNodeTypesAdapter<N, DB, RethFullProviderType<DB, <N as NodeTypes>::Evm>>>,
N: Node<FullNodeTypesAdapter<N, DB, RethFullProviderType<DB>>>,
N::PoolBuilder: PoolBuilder<RethFullAdapter<DB, N>>,
N::NetworkBuilder: crate::components::NetworkBuilder<
RethFullAdapter<DB, N>,
Expand Down Expand Up @@ -308,15 +306,14 @@ where
Types,
Components,
FullNodeComponentsAdapter<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>,
Components::Pool,
>,
>,
>
where
Components: NodeComponentsBuilder<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
>,
Components:
NodeComponentsBuilder<FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>>,
{
NodeBuilder {
config: self.config,
Expand All @@ -339,17 +336,15 @@ impl<DB, Types, Components>
Types,
Components,
FullNodeComponentsAdapter<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>,
Components::Pool,
>,
>,
>
where
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
Types: NodeTypes,
Components: NodeComponentsBuilder<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
>,
Components: NodeComponentsBuilder<FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>>,
{
/// Apply a function to the components builder.
pub fn map_components(self, f: impl FnOnce(Components) -> Components) -> Self {
Expand All @@ -371,7 +366,7 @@ where
where
F: Fn(
FullNodeComponentsAdapter<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>,
Components::Pool,
>,
) -> eyre::Result<()>
Expand All @@ -388,7 +383,7 @@ where
F: Fn(
FullNode<
FullNodeComponentsAdapter<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>,
Components::Pool,
>,
>,
Expand All @@ -407,7 +402,7 @@ where
RpcContext<
'_,
FullNodeComponentsAdapter<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>,
Components::Pool,
>,
>,
Expand All @@ -427,7 +422,7 @@ where
RpcContext<
'_,
FullNodeComponentsAdapter<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>,
Components::Pool,
>,
>,
Expand All @@ -449,7 +444,7 @@ where
F: Fn(
ExExContext<
FullNodeComponentsAdapter<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>,
Components::Pool,
>,
>,
Expand All @@ -476,7 +471,7 @@ where
) -> eyre::Result<
NodeHandle<
FullNodeComponentsAdapter<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>,
Components::Pool,
>,
>,
Expand Down Expand Up @@ -556,7 +551,7 @@ where
.with_sync_metrics_tx(sync_metrics_tx.clone());

let canon_state_notification_sender = tree.canon_state_notification_sender();
let blockchain_tree = ShareableBlockchainTree::new(tree);
let blockchain_tree = Arc::new(ShareableBlockchainTree::new(tree));
debug!(target: "reth::cli", "configured blockchain tree");

// fetch the head block from the database
Expand Down Expand Up @@ -995,7 +990,7 @@ where
>,
>
where
N: Node<FullNodeTypesAdapter<N, DB, RethFullProviderType<DB, <N as NodeTypes>::Evm>>>,
N: Node<FullNodeTypesAdapter<N, DB, RethFullProviderType<DB>>>,
N::PoolBuilder: PoolBuilder<RethFullAdapter<DB, N>>,
N::NetworkBuilder: crate::components::NetworkBuilder<
RethFullAdapter<DB, N>,
Expand Down Expand Up @@ -1032,7 +1027,7 @@ where
>,
>
where
N: Node<FullNodeTypesAdapter<N, DB, RethFullProviderType<DB, <N as NodeTypes>::Evm>>>,
N: Node<FullNodeTypesAdapter<N, DB, RethFullProviderType<DB>>>,
N::PoolBuilder: PoolBuilder<RethFullAdapter<DB, N>>,
N::NetworkBuilder: crate::components::NetworkBuilder<
RethFullAdapter<DB, N>,
Expand Down Expand Up @@ -1065,15 +1060,14 @@ where
Types,
Components,
FullNodeComponentsAdapter<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>,
Components::Pool,
>,
>,
>
where
Components: NodeComponentsBuilder<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
>,
Components:
NodeComponentsBuilder<FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>>,
{
WithLaunchContext {
builder: self.builder.with_components(components_builder),
Expand All @@ -1090,17 +1084,15 @@ impl<DB, Types, Components>
Types,
Components,
FullNodeComponentsAdapter<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>,
Components::Pool,
>,
>,
>
where
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
Types: NodeTypes,
Components: NodeComponentsBuilder<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
>,
Components: NodeComponentsBuilder<FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>>,
{
/// Apply a function to the components builder.
pub fn map_components(self, f: impl FnOnce(Components) -> Components) -> Self {
Expand All @@ -1116,7 +1108,7 @@ where
where
F: Fn(
FullNodeComponentsAdapter<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>,
Components::Pool,
>,
) -> eyre::Result<()>
Expand All @@ -1133,7 +1125,7 @@ where
F: Fn(
FullNode<
FullNodeComponentsAdapter<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>,
Components::Pool,
>,
>,
Expand All @@ -1152,7 +1144,7 @@ where
RpcContext<
'_,
FullNodeComponentsAdapter<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>,
Components::Pool,
>,
>,
Expand All @@ -1172,7 +1164,7 @@ where
RpcContext<
'_,
FullNodeComponentsAdapter<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>,
Components::Pool,
>,
>,
Expand All @@ -1190,7 +1182,7 @@ where
F: Fn(
ExExContext<
FullNodeComponentsAdapter<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>,
Components::Pool,
>,
>,
Expand All @@ -1210,7 +1202,7 @@ where
) -> eyre::Result<
NodeHandle<
FullNodeComponentsAdapter<
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>,
Components::Pool,
>,
>,
Expand Down Expand Up @@ -1391,13 +1383,12 @@ impl<Node: FullNodeTypes> std::fmt::Debug for BuilderContext<Node> {
pub struct InitState;

/// The state after all types of the node have been configured.
#[derive(Debug)]
pub struct TypesState<Types, DB>
where
DB: Database + Clone + 'static,
Types: NodeTypes,
{
adapter: FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB, Types::Evm>>,
adapter: FullNodeTypesAdapter<Types, DB, RethFullProviderType<DB>>,
}

/// The state of the node builder process after the node's components have been configured.
Expand Down
Loading

0 comments on commit c659e28

Please sign in to comment.