Skip to content

Commit

Permalink
perf: warm transactions in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected committed Feb 2, 2025
1 parent d3acdda commit 0cc94b1
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 55 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 19 additions & 15 deletions crates/engine/local/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use reth_engine_tree::{
persistence::PersistenceHandle,
tree::{EngineApiTreeHandler, InvalidBlockHook, TreeConfig},
};
use reth_evm::execute::BlockExecutorProvider;
use reth_node_types::BlockTy;
use reth_evm::{execute::BlockExecutorProvider, ConfigureEvm};
use reth_node_types::{BlockTy, HeaderTy, TxTy};
use reth_payload_builder::PayloadBuilderHandle;
use reth_payload_primitives::{PayloadAttributesBuilder, PayloadTypes};
use reth_provider::{
Expand Down Expand Up @@ -65,7 +65,7 @@ where
{
/// Constructor for [`LocalEngineService`].
#[allow(clippy::too_many_arguments)]
pub fn new<B, V>(
pub fn new<B, V, C>(
consensus: Arc<dyn FullConsensus<N::Primitives, Error = ConsensusError>>,
executor_factory: impl BlockExecutorProvider<Primitives = N::Primitives>,
provider: ProviderFactory<N>,
Expand All @@ -80,10 +80,12 @@ where
from_engine: EngineMessageStream<N::Engine>,
mode: MiningMode,
payload_attributes_builder: B,
evm_config: C,
) -> Self
where
B: PayloadAttributesBuilder<<N::Engine as PayloadTypes>::PayloadAttributes>,
V: EngineValidator<N::Engine, Block = BlockTy<N>>,
C: ConfigureEvm<Header = HeaderTy<N>, Transaction = TxTy<N>>,
{
let chain_spec = provider.chain_spec();
let engine_kind =
Expand All @@ -93,18 +95,20 @@ where
PersistenceHandle::<N::Primitives>::spawn_service(provider, pruner, sync_metrics_tx);
let canonical_in_memory_state = blockchain_db.canonical_in_memory_state();

let (to_tree_tx, from_tree) = EngineApiTreeHandler::<N::Primitives, _, _, _, _>::spawn_new(
blockchain_db.clone(),
executor_factory,
consensus,
payload_validator,
persistence_handle,
payload_builder.clone(),
canonical_in_memory_state,
tree_config,
invalid_block_hook,
engine_kind,
);
let (to_tree_tx, from_tree) =
EngineApiTreeHandler::<N::Primitives, _, _, _, _, _>::spawn_new(
blockchain_db.clone(),
executor_factory,
consensus,
payload_validator,
persistence_handle,
payload_builder.clone(),
canonical_in_memory_state,
tree_config,
invalid_block_hook,
engine_kind,
evm_config,
);

let handler = EngineApiRequestHandler::new(to_tree_tx, from_tree);

Expand Down
38 changes: 22 additions & 16 deletions crates/engine/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ pub use reth_engine_tree::{
chain::{ChainEvent, ChainOrchestrator},
engine::EngineApiEvent,
};
use reth_evm::execute::BlockExecutorProvider;
use reth_evm::{execute::BlockExecutorProvider, ConfigureEvm};
use reth_network_p2p::BlockClient;
use reth_node_types::{BlockTy, NodeTypes, NodeTypesWithEngine};
use reth_node_types::{BlockTy, HeaderTy, NodeTypes, NodeTypesWithEngine, TxTy};
use reth_payload_builder::PayloadBuilderHandle;
use reth_primitives::EthPrimitives;
use reth_provider::{
Expand Down Expand Up @@ -73,7 +73,7 @@ where
{
/// Constructor for `EngineService`.
#[allow(clippy::too_many_arguments)]
pub fn new<V>(
pub fn new<V, C>(
consensus: Arc<dyn FullConsensus<N::Primitives, Error = ConsensusError>>,
executor_factory: E,
chain_spec: Arc<N::ChainSpec>,
Expand All @@ -89,9 +89,11 @@ where
tree_config: TreeConfig,
invalid_block_hook: Box<dyn InvalidBlockHook<N::Primitives>>,
sync_metrics_tx: MetricEventsSender,
evm_config: C,
) -> Self
where
V: EngineValidator<N::Engine, Block = BlockTy<N>>,
C: ConfigureEvm<Header = HeaderTy<N>, Transaction = TxTy<N>>,
{
let engine_kind =
if chain_spec.is_optimism() { EngineApiKind::OpStack } else { EngineApiKind::Ethereum };
Expand All @@ -103,18 +105,20 @@ where

let canonical_in_memory_state = blockchain_db.canonical_in_memory_state();

let (to_tree_tx, from_tree) = EngineApiTreeHandler::<N::Primitives, _, _, _, _>::spawn_new(
blockchain_db,
executor_factory,
consensus,
payload_validator,
persistence_handle,
payload_builder,
canonical_in_memory_state,
tree_config,
invalid_block_hook,
engine_kind,
);
let (to_tree_tx, from_tree) =
EngineApiTreeHandler::<N::Primitives, _, _, _, _, _>::spawn_new(
blockchain_db,
executor_factory,
consensus,
payload_validator,
persistence_handle,
payload_builder,
canonical_in_memory_state,
tree_config,
invalid_block_hook,
engine_kind,
evm_config,
);

let engine_handler = EngineApiRequestHandler::new(to_tree_tx, from_tree);
let handler = EngineHandler::new(engine_handler, downloader, incoming_requests);
Expand Down Expand Up @@ -160,7 +164,7 @@ mod tests {
use reth_engine_tree::{test_utils::TestPipelineBuilder, tree::NoopInvalidBlockHook};
use reth_ethereum_consensus::EthBeaconConsensus;
use reth_ethereum_engine_primitives::{EthEngineTypes, EthereumEngineValidator};
use reth_evm_ethereum::execute::EthExecutorProvider;
use reth_evm_ethereum::{execute::EthExecutorProvider, EthEvmConfig};
use reth_exex_types::FinishedExExHeight;
use reth_network_p2p::test_utils::TestFullBlockClient;
use reth_primitives::SealedHeader;
Expand Down Expand Up @@ -200,6 +204,7 @@ mod tests {
let engine_payload_validator = EthereumEngineValidator::new(chain_spec.clone());
let (_tx, rx) = watch::channel(FinishedExExHeight::NoExExs);
let pruner = Pruner::new_with_factory(provider_factory.clone(), vec![], 0, 0, None, rx);
let evm_config = EthEvmConfig::new(chain_spec.clone());

let (sync_metrics_tx, _sync_metrics_rx) = unbounded_channel();
let (tx, _rx) = unbounded_channel();
Expand All @@ -219,6 +224,7 @@ mod tests {
TreeConfig::default(),
Box::new(NoopInvalidBlockHook::default()),
sync_metrics_tx,
evm_config,
);
}
}
1 change: 1 addition & 0 deletions crates/engine/tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ reth-chain-state = { workspace = true, features = ["test-utils"] }
reth-chainspec.workspace = true
reth-ethereum-engine-primitives.workspace = true
reth-ethereum-consensus.workspace = true
reth-evm-ethereum.workspace = true
reth-evm = { workspace = true, features = ["test-utils"] }
reth-exex-types.workspace = true
reth-network-p2p = { workspace = true, features = ["test-utils"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/tree/src/tree/cached_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use reth_trie::{
};
use revm_primitives::map::DefaultHashBuilder;

type Cache<K, V> = moka::sync::Cache<K, V, alloy_primitives::map::DefaultHashBuilder>;
pub(crate) type Cache<K, V> = moka::sync::Cache<K, V, alloy_primitives::map::DefaultHashBuilder>;

/// A wrapper of a state provider and a shared cache.
pub(crate) struct CachedStateProvider<S> {
Expand Down
Loading

0 comments on commit 0cc94b1

Please sign in to comment.