Skip to content

Commit 85a19c6

Browse files
authored
refactor: remove block context (#31)
* refactor: remove block context * lint: clippy * chore: name and doc cleanups in evm
1 parent b7c55e3 commit 85a19c6

28 files changed

+997
-1771
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "trevm"
3-
version = "0.3.1"
3+
version = "0.4.0"
44
rust-version = "1.79.0"
55
edition = "2021"
66
authors = ["init4"]
@@ -33,7 +33,6 @@ alloy-primitives = "0.7.6"
3333
alloy-rpc-types-eth = "0.2.0"
3434
alloy-sol-types = "0.7.7"
3535
revm = { version = "12.0.0", default-features = false, features = ["std"] }
36-
thiserror = "1.0.63"
3736
zenith-types = "0.3"
3837

3938
[dev-dependencies]

examples/basic_transact.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use revm::{
77
primitives::{hex, AccountInfo, Address, Bytecode, TransactTo, U256},
88
EvmBuilder, InMemoryDB,
99
};
10-
use trevm::{trevm_aliases, NoopBlock, NoopCfg, Shanghai, TrevmBuilder, Tx};
10+
use trevm::{trevm_aliases, NoopBlock, NoopCfg, TrevmBuilder, Tx};
1111

1212
/// Foundry's default Counter.sol contract bytecode.
1313
const CONTRACT_BYTECODE: &str = "0x6080604052348015600f57600080fd5b5060043610603c5760003560e01c80633fb5c1cb1460415780638381f58a146053578063d09de08a14606d575b600080fd5b6051604c3660046083565b600055565b005b605b60005481565b60405190815260200160405180910390f35b6051600080549080607c83609b565b9190505550565b600060208284031215609457600080fd5b5035919050565b60006001820160ba57634e487b7160e01b600052601160045260246000fd5b506001019056fea2646970667358221220091e48831e9eee32d4571d6291233a4fdaaa34b7dced8770f36f5368be825c5264736f6c63430008190033";
@@ -51,8 +51,7 @@ fn main() {
5151
.append_handler_register(inspector_handle_register)
5252
.build_trevm()
5353
.fill_cfg(&NoopCfg)
54-
.open_block(&NoopBlock, Shanghai::default())
55-
.unwrap();
54+
.fill_block(&NoopBlock);
5655

5756
let account = evm.read_account_ref(CONTRACT_ADDR).unwrap();
5857
println!("account: {account:?}");

examples/fork_ref_transact.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use revm::{
1010
primitives::{address, TxKind, U256},
1111
Evm,
1212
};
13-
use trevm::{NoopBlock, NoopCfg, Shanghai, TrevmBuilder, Tx};
13+
use trevm::{NoopBlock, NoopCfg, TrevmBuilder, Tx};
1414

1515
sol! {
1616
#[allow(missing_docs)]
@@ -63,8 +63,7 @@ async fn main() -> eyre::Result<()> {
6363
.with_db(cache_db)
6464
.build_trevm()
6565
.fill_cfg(&NoopCfg)
66-
.open_block(&NoopBlock, Shanghai::default())
67-
.unwrap()
66+
.fill_block(&NoopBlock)
6867
.fill_tx(&GetReservesFiller)
6968
.run()
7069
.inspect_err(|e| panic!("Execution error {e:?}"))

src/driver/alloy.rs

Lines changed: 0 additions & 100 deletions
This file was deleted.

src/driver/block.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,36 @@
1-
use crate::{Block, BlockContext, EvmBlockComplete, EvmBlockDriverErrored, EvmNeedsTx};
1+
use crate::{Block, EvmBlockDriverErrored, EvmNeedsBlock, EvmNeedsTx};
22
use revm::{primitives::EVMError, Database, DatabaseCommit};
33

44
/// The result of running transactions for a block driver.
5-
pub type RunTxResult<'a, 'b, Ext, Db, C, T> =
6-
Result<EvmNeedsTx<'a, Ext, Db, C>, EvmBlockDriverErrored<'a, 'b, Ext, Db, C, T>>;
5+
pub type RunTxResult<'a, Ext, Db, T> =
6+
Result<EvmNeedsTx<'a, Ext, Db>, EvmBlockDriverErrored<'a, Ext, Db, T>>;
77

88
/// The result of driving a block to completion.
9-
pub type DriveBlockResult<'a, 'b, Ext, Db, C, T> =
10-
Result<EvmBlockComplete<'a, Ext, Db, C>, EvmBlockDriverErrored<'a, 'b, Ext, Db, C, T>>;
9+
pub type DriveBlockResult<'a, Ext, Db, T> =
10+
Result<EvmNeedsBlock<'a, Ext, Db>, EvmBlockDriverErrored<'a, Ext, Db, T>>;
1111

1212
/// Driver for a single trevm block. This trait allows a type to specify the
1313
/// entire lifecycle of a trevm block, from opening the block to driving the
1414
/// trevm to completion.
15-
pub trait BlockDriver<'b, Ext, C: BlockContext<Ext>>
16-
where
17-
Self: 'b,
18-
{
15+
pub trait BlockDriver<Ext> {
1916
/// The [`Block`] filler for this driver.
2017
type Block: Block;
2118

2219
/// An error type for this driver.
23-
type Error<Db: Database>: std::error::Error
24-
+ From<EVMError<Db::Error>>
25-
+ From<<C as BlockContext<Ext>>::Error<Db>>;
20+
type Error<Db: Database>: std::error::Error + From<EVMError<Db::Error>>;
2621

2722
/// Get a reference to the block filler for this driver.
2823
fn block(&self) -> &Self::Block;
2924

30-
/// Get the context for this block.
31-
fn context(&'b self) -> C;
32-
3325
/// Run the transactions for the block.
3426
fn run_txns<'a, Db: Database + DatabaseCommit>(
35-
&self,
36-
trevm: EvmNeedsTx<'a, Ext, Db, C>,
37-
) -> RunTxResult<'a, 'b, Ext, Db, C, Self>;
27+
&mut self,
28+
trevm: EvmNeedsTx<'a, Ext, Db>,
29+
) -> RunTxResult<'a, Ext, Db, Self>;
3830

3931
/// Run post
40-
fn post_block_checks<Db: Database + DatabaseCommit>(
41-
&self,
42-
trevm: &EvmBlockComplete<'_, Ext, Db, C>,
32+
fn post_block<Db: Database + DatabaseCommit>(
33+
&mut self,
34+
trevm: &EvmNeedsBlock<'_, Ext, Db>,
4335
) -> Result<(), Self::Error<Db>>;
4436
}

src/driver/chain.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,37 @@
1-
use crate::{BlockContext, BlockDriver, EvmBlockComplete, EvmChainDriverErrored, EvmNeedsBlock};
1+
use crate::{BlockDriver, EvmChainDriverErrored, EvmNeedsBlock};
22
use revm::{
33
primitives::{EVMError, SpecId},
44
Database, DatabaseCommit,
55
};
66

77
/// The result of driving a chain to completion.
8-
pub type DriveChainResult<'a, 'b, Ext, Db, C, D> =
9-
Result<(Vec<C>, EvmNeedsBlock<'a, Ext, Db>), EvmChainDriverErrored<'a, 'b, Ext, Db, C, D>>;
8+
pub type DriveChainResult<'a, Ext, Db, D> =
9+
Result<EvmNeedsBlock<'a, Ext, Db>, EvmChainDriverErrored<'a, Ext, Db, D>>;
1010

1111
/// Driver for a chain of blocks.
12-
pub trait ChainDriver<'b, Ext, C: BlockContext<Ext>> {
12+
pub trait ChainDriver<Ext> {
1313
/// The block driver for this chain.
14-
type BlockDriver: BlockDriver<'b, Ext, C>;
14+
type BlockDriver: BlockDriver<Ext>;
1515

1616
/// An error type for this driver.
1717
type Error<Db: Database>: std::error::Error
1818
+ From<EVMError<Db::Error>>
19-
+ From<<C as BlockContext<Ext>>::Error<Db>>
20-
+ From<<Self::BlockDriver as BlockDriver<'b, Ext, C>>::Error<Db>>;
19+
+ From<<Self::BlockDriver as BlockDriver<Ext>>::Error<Db>>;
2120

2221
/// Get the spec id for a block.
23-
fn spec_id_for(&self, block: &<Self::BlockDriver as BlockDriver<'b, Ext, C>>::Block) -> SpecId;
22+
fn spec_id_for(&self, block: &<Self::BlockDriver as BlockDriver<Ext>>::Block) -> SpecId;
2423

2524
/// Get the blocks in this chain. The blocks should be in order, and this
2625
/// function MUST NOT return an empty slice.
27-
fn blocks(&self) -> &[Self::BlockDriver];
26+
fn blocks(&mut self) -> &mut [Self::BlockDriver];
2827

2928
/// Checks that run between blocks, e.g. 1559 base fee calculation,
3029
/// or parent-child relationships.
3130
///
3231
/// The `idx` parameter is the index of the block in the chain.
33-
fn check_interblock<Db: Database + DatabaseCommit>(
34-
&self,
35-
trevm: &EvmBlockComplete<'_, Ext, Db, C>,
32+
fn interblock<Db: Database + DatabaseCommit>(
33+
&mut self,
34+
trevm: &EvmNeedsBlock<'_, Ext, Db>,
3635
idx: usize,
3736
) -> Result<(), Self::Error<Db>>;
3837
}

src/driver/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
mod alloy;
2-
pub use alloy::AlloyBlockError;
3-
41
mod block;
52
pub use block::{BlockDriver, DriveBlockResult, RunTxResult};
63

0 commit comments

Comments
 (0)