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

feat(examples): evm execution exex #8092

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ members = [
"examples/txpool-tracing/",
"examples/polygon-p2p/",
"examples/custom-inspector/",
"examples/exex/evm/",
"examples/exex/minimal/",
"examples/exex/op-bridge/",
"examples/exex/rollup/",
Expand Down
21 changes: 21 additions & 0 deletions examples/exex/evm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "exex-evm"
version = "0.0.0"
publish = false
edition.workspace = true
license.workspace = true

[dependencies]
reth.workspace = true
reth-evm.workspace = true
reth-evm-ethereum.workspace = true
reth-exex.workspace = true
reth-node-api.workspace = true
reth-node-core.workspace = true
reth-node-ethereum.workspace = true
reth-primitives.workspace = true
reth-tracing.workspace = true

eyre.workspace = true
tokio.workspace = true
futures.workspace = true
62 changes: 62 additions & 0 deletions examples/exex/evm/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use eyre::OptionExt;
use reth::{
providers::{DatabaseProviderFactory, HistoricalStateProviderRef},
revm::database::StateProviderDatabase,
};
use reth_evm::execute::{BatchExecutor, BlockExecutorProvider};
use reth_evm_ethereum::EthEvmConfig;
use reth_exex::{ExExContext, ExExEvent};
use reth_node_api::FullNodeComponents;
use reth_node_ethereum::{EthExecutorProvider, EthereumNode};
use reth_tracing::tracing::info;

async fn exex<Node: FullNodeComponents>(mut ctx: ExExContext<Node>) -> eyre::Result<()> {
while let Some(notification) = ctx.notifications.recv().await {
if let Some(chain) = notification.committed_chain() {
// TODO(alexey): use custom EVM config with tracer
let evm_config = EthEvmConfig::default();
let executor_provider = EthExecutorProvider::new(ctx.config.chain.clone(), evm_config);

let database_provider = ctx.provider().database_provider_ro()?;
let db = StateProviderDatabase::new(HistoricalStateProviderRef::new(
database_provider.tx_ref(),
chain.first().number.checked_sub(1).ok_or_eyre("block number underflow")?,
database_provider.static_file_provider().clone(),
));

let mut executor = executor_provider.batch_executor(
db,
ctx.config.prune_config().map(|config| config.segments).unwrap_or_default(),
);

for block in chain.blocks_iter() {
let td = block.header().difficulty;
executor.execute_one((&block.clone().unseal(), td).into())?;
}

let output = executor.finalize();

let same_state = chain.state() == &output.into();
info!(
chain = ?chain.range(),
%same_state,
"Executed chain"
);

ctx.events.send(ExExEvent::FinishedHeight(chain.tip().number))?;
}
}
Ok(())
}

fn main() -> eyre::Result<()> {
reth::cli::Cli::parse_args().run(|builder, _| async move {
let handle = builder
.node(EthereumNode::default())
.install_exex("EVM", |ctx| async move { Ok(exex(ctx)) })
.launch()
.await?;

handle.wait_for_node_exit().await
})
}