Skip to content

Commit d2502d6

Browse files
optimize prefetch
1 parent 498d69b commit d2502d6

File tree

15 files changed

+102
-80
lines changed

15 files changed

+102
-80
lines changed

Cargo.lock

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bsc/evm/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ reth-prune-types.workspace = true
2121
reth-revm.workspace = true
2222
reth-provider.workspace = true
2323
reth-bsc-consensus.workspace = true
24-
reth-trie.workspace = true
2524

2625
# Revm
2726
revm-primitives.workspace = true

crates/bsc/evm/src/execute.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ use reth_revm::{
2828
db::states::bundle_state::BundleRetention,
2929
Evm, State,
3030
};
31-
use reth_trie::HashedPostState;
3231
use revm_primitives::{
3332
db::{Database, DatabaseCommit},
34-
BlockEnv, CfgEnvWithHandlerCfg, EVMError, EnvWithHandlerCfg, ResultAndState, TransactTo,
33+
BlockEnv, CfgEnvWithHandlerCfg, EVMError, EnvWithHandlerCfg, EvmState, ResultAndState,
34+
TransactTo,
3535
};
3636
use std::{collections::HashMap, num::NonZeroUsize, sync::Arc, time::Instant};
3737
use tokio::sync::mpsc::UnboundedSender;
@@ -85,7 +85,7 @@ where
8585
fn bsc_executor<DB>(
8686
&self,
8787
db: DB,
88-
prefetch_tx: Option<UnboundedSender<HashedPostState>>,
88+
prefetch_tx: Option<UnboundedSender<EvmState>>,
8989
) -> BscBlockExecutor<EvmConfig, DB, P>
9090
where
9191
DB: Database<Error: Into<ProviderError> + std::fmt::Display>,
@@ -133,7 +133,7 @@ where
133133
fn executor<DB>(
134134
&self,
135135
db: DB,
136-
prefetch_tx: Option<UnboundedSender<HashedPostState>>,
136+
prefetch_tx: Option<UnboundedSender<EvmState>>,
137137
) -> Self::Executor<DB>
138138
where
139139
DB: Database<Error: Into<ProviderError> + std::fmt::Display>,
@@ -187,7 +187,7 @@ where
187187
&self,
188188
block: &BlockWithSenders,
189189
mut evm: Evm<'_, Ext, &mut State<DB>>,
190-
tx: Option<UnboundedSender<HashedPostState>>,
190+
tx: Option<UnboundedSender<EvmState>>,
191191
) -> Result<(Vec<TransactionSigned>, Vec<Receipt>, u64), BlockExecutionError>
192192
where
193193
DB: Database<Error: Into<ProviderError> + std::fmt::Display>,
@@ -241,8 +241,8 @@ where
241241
})?;
242242

243243
if let Some(tx) = tx.as_ref() {
244-
let post_state = HashedPostState::from_state(state.clone());
245-
tx.send(post_state).unwrap_or_else(|err| {
244+
// let post_state = HashedPostState::from_state(state.clone());
245+
tx.send(state.clone()).unwrap_or_else(|err| {
246246
debug!(target: "evm_executor", ?err, "Failed to send post state to prefetch channel")
247247
});
248248
}
@@ -288,7 +288,7 @@ pub struct BscBlockExecutor<EvmConfig, DB, P> {
288288
/// Parlia consensus instance
289289
pub(crate) parlia: Arc<Parlia>,
290290
/// Prefetch channel
291-
prefetch_tx: Option<UnboundedSender<HashedPostState>>,
291+
prefetch_tx: Option<UnboundedSender<EvmState>>,
292292
}
293293

294294
impl<EvmConfig, DB, P> BscBlockExecutor<EvmConfig, DB, P> {
@@ -318,7 +318,7 @@ impl<EvmConfig, DB, P> BscBlockExecutor<EvmConfig, DB, P> {
318318
parlia_config: ParliaConfig,
319319
state: State<DB>,
320320
provider: P,
321-
tx: UnboundedSender<HashedPostState>,
321+
tx: UnboundedSender<EvmState>,
322322
) -> Self {
323323
let parlia = Arc::new(Parlia::new(Arc::clone(&chain_spec), parlia_config));
324324
let shared_provider = Arc::new(provider);

crates/bsc/evm/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
// TODO: doc
44
#![allow(missing_docs)]
5+
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
56
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
67
// The `bsc` feature must be enabled to use this crate.
78
#![cfg(feature = "bsc")]

crates/ethereum/evm/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ reth-revm.workspace = true
2020
reth-ethereum-consensus.workspace = true
2121
reth-prune-types.workspace = true
2222
reth-execution-types.workspace = true
23-
reth-trie.workspace = true
2423

2524
# Ethereum
2625
revm-primitives.workspace = true

crates/ethereum/evm/src/execute.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ use reth_revm::{
2828
state_change::{apply_blockhashes_update, post_block_balance_increments},
2929
Evm, State,
3030
};
31-
use reth_trie::HashedPostState;
3231
use revm_primitives::{
3332
db::{Database, DatabaseCommit},
34-
BlockEnv, CfgEnvWithHandlerCfg, EVMError, EnvWithHandlerCfg, ResultAndState,
33+
BlockEnv, CfgEnvWithHandlerCfg, EVMError, EnvWithHandlerCfg, EvmState, ResultAndState,
3534
};
3635
use tokio::sync::mpsc::UnboundedSender;
3736
use tracing::debug;
@@ -71,7 +70,7 @@ where
7170
fn eth_executor<DB>(
7271
&self,
7372
db: DB,
74-
prefetch_tx: Option<UnboundedSender<HashedPostState>>,
73+
prefetch_tx: Option<UnboundedSender<EvmState>>,
7574
) -> EthBlockExecutor<EvmConfig, DB>
7675
where
7776
DB: Database<Error: Into<ProviderError>>,
@@ -114,7 +113,7 @@ where
114113
fn executor<DB>(
115114
&self,
116115
db: DB,
117-
prefetch_tx: Option<UnboundedSender<HashedPostState>>,
116+
prefetch_tx: Option<UnboundedSender<EvmState>>,
118117
) -> Self::Executor<DB>
119118
where
120119
DB: Database<Error: Into<ProviderError> + Display>,
@@ -170,7 +169,7 @@ where
170169
&self,
171170
block: &BlockWithSenders,
172171
mut evm: Evm<'_, Ext, &mut State<DB>>,
173-
tx: Option<UnboundedSender<HashedPostState>>,
172+
tx: Option<UnboundedSender<EvmState>>,
174173
) -> Result<EthExecuteOutput, BlockExecutionError>
175174
where
176175
DB: Database,
@@ -227,8 +226,7 @@ where
227226
})?;
228227

229228
if let Some(tx) = tx.as_ref() {
230-
let post_state = HashedPostState::from_state(state.clone());
231-
tx.send(post_state).unwrap_or_else(|err| {
229+
tx.send(state.clone()).unwrap_or_else(|err| {
232230
debug!(target: "evm_executor", ?err, "Failed to send post state to prefetch channel")
233231
});
234232
}
@@ -288,7 +286,7 @@ pub struct EthBlockExecutor<EvmConfig, DB> {
288286
/// The state to use for execution
289287
state: State<DB>,
290288
/// Prefetch channel
291-
prefetch_tx: Option<UnboundedSender<HashedPostState>>,
289+
prefetch_tx: Option<UnboundedSender<EvmState>>,
292290
}
293291

294292
impl<EvmConfig, DB> EthBlockExecutor<EvmConfig, DB> {
@@ -302,7 +300,7 @@ impl<EvmConfig, DB> EthBlockExecutor<EvmConfig, DB> {
302300
chain_spec: Arc<ChainSpec>,
303301
evm_config: EvmConfig,
304302
state: State<DB>,
305-
tx: UnboundedSender<HashedPostState>,
303+
tx: UnboundedSender<EvmState>,
306304
) -> Self {
307305
Self { executor: EthEvmExecutor { chain_spec, evm_config }, state, prefetch_tx: Some(tx) }
308306
}

crates/evm/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ revm-primitives.workspace = true
1919
reth-prune-types.workspace = true
2020
reth-storage-errors.workspace = true
2121
reth-execution-types.workspace = true
22-
reth-trie.workspace = true
2322

2423
revm.workspace = true
2524
alloy-eips.workspace = true

crates/evm/src/either.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ use reth_execution_types::ExecutionOutcome;
1010
use reth_primitives::{BlockNumber, BlockWithSenders, Header, Receipt};
1111
use reth_prune_types::PruneModes;
1212
use reth_storage_errors::provider::ProviderError;
13-
use revm_primitives::db::Database;
13+
use revm_primitives::{db::Database, EvmState};
14+
use tokio::sync::mpsc::UnboundedSender;
1415

1516
// re-export Either
1617
pub use futures_util::future::Either;
17-
use reth_trie::HashedPostState;
18-
use tokio::sync::mpsc::UnboundedSender;
1918

2019
impl<A, B> BlockExecutorProvider for Either<A, B>
2120
where
@@ -31,7 +30,7 @@ where
3130
fn executor<DB>(
3231
&self,
3332
db: DB,
34-
prefetch_tx: Option<UnboundedSender<HashedPostState>>,
33+
prefetch_tx: Option<UnboundedSender<EvmState>>,
3534
) -> Self::Executor<DB>
3635
where
3736
DB: Database<Error: Into<ProviderError> + Display>,

crates/evm/src/execute.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ use reth_primitives::{
55
parlia::Snapshot, BlockNumber, BlockWithSenders, Header, Receipt, Request, B256, U256,
66
};
77
use reth_prune_types::PruneModes;
8-
use reth_trie::HashedPostState;
98
use revm::db::BundleState;
109
use revm_primitives::db::Database;
1110
use std::fmt::Display;
1211
use tokio::sync::mpsc::UnboundedSender;
1312

1413
#[cfg(not(feature = "std"))]
1514
use alloc::vec::Vec;
16-
use std::collections::HashMap;
17-
1815
pub use reth_execution_errors::{BlockExecutionError, BlockValidationError};
1916
pub use reth_storage_errors::provider::ProviderError;
17+
use revm_primitives::EvmState;
18+
use std::collections::HashMap;
2019

2120
/// A general purpose executor trait that executes an input (e.g. block) and produces an output
2221
/// (e.g. state changes and receipts).
@@ -192,7 +191,7 @@ pub trait BlockExecutorProvider: Send + Sync + Clone + Unpin + 'static {
192191
fn executor<DB>(
193192
&self,
194193
db: DB,
195-
prefetch_rx: Option<UnboundedSender<HashedPostState>>,
194+
prefetch_rx: Option<UnboundedSender<EvmState>>,
196195
) -> Self::Executor<DB>
197196
where
198197
DB: Database<Error: Into<ProviderError> + Display>;
@@ -223,7 +222,7 @@ mod tests {
223222
fn executor<DB>(
224223
&self,
225224
_db: DB,
226-
_prefetch_tx: Option<UnboundedSender<HashedPostState>>,
225+
_prefetch_tx: Option<UnboundedSender<EvmState>>,
227226
) -> Self::Executor<DB>
228227
where
229228
DB: Database<Error: Into<ProviderError> + Display>,

crates/evm/src/noop.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use reth_execution_types::ExecutionOutcome;
77
use reth_primitives::{BlockNumber, BlockWithSenders, Header, Receipt};
88
use reth_prune_types::PruneModes;
99
use reth_storage_errors::provider::ProviderError;
10-
use reth_trie::HashedPostState;
11-
use revm_primitives::db::Database;
10+
use revm_primitives::{db::Database, EvmState};
1211
use tokio::sync::mpsc::UnboundedSender;
1312

1413
use crate::execute::{
@@ -27,7 +26,7 @@ impl BlockExecutorProvider for NoopBlockExecutorProvider {
2726

2827
type BatchExecutor<DB: Database<Error: Into<ProviderError> + Display>> = Self;
2928

30-
fn executor<DB>(&self, _: DB, _: Option<UnboundedSender<HashedPostState>>) -> Self::Executor<DB>
29+
fn executor<DB>(&self, _: DB, _: Option<UnboundedSender<EvmState>>) -> Self::Executor<DB>
3130
where
3231
DB: Database<Error: Into<ProviderError> + Display>,
3332
{

0 commit comments

Comments
 (0)