Skip to content

Commit f2d340e

Browse files
committed
refactor: move Ext to trait
1 parent 2840b30 commit f2d340e

File tree

8 files changed

+66
-65
lines changed

8 files changed

+66
-65
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "trevm"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
rust-version = "1.79.0"
55
edition = "2021"
66
authors = ["init4"]

src/driver/alloy.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ impl<Db: Database> From<EVMError<Db::Error>> for AlloyBlockError<Db> {
6363
}
6464
}
6565

66-
impl<'b> BlockDriver<'b, Shanghai<'b>> for alloy_rpc_types_eth::Block<TxEnvelope> {
66+
impl<'b, Ext> BlockDriver<'b, Ext, Shanghai<'b>> for alloy_rpc_types_eth::Block<TxEnvelope> {
6767
type Block = alloy_rpc_types_eth::Header;
6868

69-
// TODO: Implement this
7069
type Error<Db: Database> = AlloyBlockError<Db>;
7170

7271
fn block(&self) -> &Self::Block {
@@ -77,7 +76,7 @@ impl<'b> BlockDriver<'b, Shanghai<'b>> for alloy_rpc_types_eth::Block<TxEnvelope
7776
self.withdrawals.as_ref().map(|w| Shanghai::new(w.as_slice())).unwrap_or_default()
7877
}
7978

80-
fn run_txns<'a, Ext, Db: Database + DatabaseCommit>(
79+
fn run_txns<'a, Db: Database + DatabaseCommit>(
8180
&self,
8281
mut trevm: EvmNeedsTx<'a, Ext, Db, Shanghai<'b>>,
8382
) -> RunTxResult<'a, 'b, Ext, Db, Shanghai<'b>, Self> {
@@ -91,7 +90,7 @@ impl<'b> BlockDriver<'b, Shanghai<'b>> for alloy_rpc_types_eth::Block<TxEnvelope
9190
Ok(trevm)
9291
}
9392

94-
fn post_block_checks<Ext, Db: Database + DatabaseCommit>(
93+
fn post_block_checks<Db: Database + DatabaseCommit>(
9594
&self,
9695
_trevm: &crate::EvmBlockComplete<'_, Ext, Db, Shanghai<'b>>,
9796
) -> Result<(), Self::Error<Db>> {

src/driver/block.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub type DriveBlockResult<'a, 'b, Ext, Db, C, T> =
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, C: BlockContext>
15+
pub trait BlockDriver<'b, Ext, C: BlockContext<Ext>>
1616
where
1717
Self: 'b,
1818
{
@@ -22,7 +22,7 @@ where
2222
/// An error type for this driver.
2323
type Error<Db: Database>: std::error::Error
2424
+ From<EVMError<Db::Error>>
25-
+ From<<C as BlockContext>::Error<Db>>;
25+
+ From<<C as BlockContext<Ext>>::Error<Db>>;
2626

2727
/// Get a reference to the block filler for this driver.
2828
fn block(&self) -> &Self::Block;
@@ -31,13 +31,13 @@ where
3131
fn context(&'b self) -> C;
3232

3333
/// Run the transactions for the block.
34-
fn run_txns<'a, Ext, Db: Database + DatabaseCommit>(
34+
fn run_txns<'a, Db: Database + DatabaseCommit>(
3535
&self,
3636
trevm: EvmNeedsTx<'a, Ext, Db, C>,
3737
) -> RunTxResult<'a, 'b, Ext, Db, C, Self>;
3838

3939
/// Run post
40-
fn post_block_checks<Ext, Db: Database + DatabaseCommit>(
40+
fn post_block_checks<Db: Database + DatabaseCommit>(
4141
&self,
4242
trevm: &EvmBlockComplete<'_, Ext, Db, C>,
4343
) -> Result<(), Self::Error<Db>>;

src/driver/chain.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ pub type DriveChainResult<'a, 'b, Ext, Db, C, D> =
99
Result<(Vec<C>, EvmNeedsBlock<'a, Ext, Db>), EvmChainDriverErrored<'a, 'b, Ext, Db, C, D>>;
1010

1111
/// Driver for a chain of blocks.
12-
pub trait ChainDriver<'b, C: BlockContext> {
12+
pub trait ChainDriver<'b, Ext, C: BlockContext<Ext>> {
1313
/// The block driver for this chain.
14-
type BlockDriver: BlockDriver<'b, C>;
14+
type BlockDriver: BlockDriver<'b, Ext, C>;
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>::Error<Db>>
20-
+ From<<Self::BlockDriver as BlockDriver<'b, C>>::Error<Db>>;
19+
+ From<<C as BlockContext<Ext>>::Error<Db>>
20+
+ From<<Self::BlockDriver as BlockDriver<'b, Ext, C>>::Error<Db>>;
2121

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

2525
/// Get the blocks in this chain. The blocks should be in order, and this
2626
/// function MUST NOT return an empty slice.
@@ -30,7 +30,7 @@ pub trait ChainDriver<'b, C: BlockContext> {
3030
/// or parent-child relationships.
3131
///
3232
/// The `idx` parameter is the index of the block in the chain.
33-
fn check_interblock<Ext, Db: Database + DatabaseCommit>(
33+
fn check_interblock<Db: Database + DatabaseCommit>(
3434
&self,
3535
trevm: &EvmBlockComplete<'_, Ext, Db, C>,
3636
idx: usize,

src/evm.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ impl<'a, Ext, Db: Database + DatabaseCommit> EvmNeedsBlock<'a, Ext, Db> {
759759
) -> Result<EvmNeedsTx<'a, Ext, Db, C>, EvmErrored<'a, Ext, Db, C>>
760760
where
761761
B: Block,
762-
C: BlockContext,
762+
C: BlockContext<Ext>,
763763
Db: Database + DatabaseCommit,
764764
{
765765
let res = context.open_block(self.inner_mut_unchecked(), filler);
@@ -774,12 +774,12 @@ impl<'a, Ext, Db: Database + DatabaseCommit> EvmNeedsBlock<'a, Ext, Db> {
774774
/// block.
775775
pub fn drive_block<'b, B, C>(self, driver: &'b B) -> DriveBlockResult<'a, 'b, Ext, Db, C, B>
776776
where
777-
C: BlockContext,
778-
B: BlockDriver<'b, C>,
777+
C: BlockContext<Ext>,
778+
B: BlockDriver<'b, Ext, C>,
779779
{
780780
let trevm = self
781781
.open_block(driver.block(), driver.context())
782-
.map_err(EvmErrored::err_into::<<B as BlockDriver<'b, C>>::Error<Db>>)?;
782+
.map_err(EvmErrored::err_into::<<B as BlockDriver<'b, Ext, C>>::Error<Db>>)?;
783783
let trevm = driver.run_txns(trevm)?;
784784

785785
let trevm = trevm.close_block().map_err(EvmErrored::err_into)?;
@@ -798,15 +798,15 @@ impl<'a, Ext, Db: Database + DatabaseCommit> EvmNeedsBlock<'a, Ext, Db> {
798798
/// If the driver contains no blocks.
799799
pub fn drive_chain<'b, D, C>(self, driver: &'b mut D) -> DriveChainResult<'a, 'b, Ext, Db, C, D>
800800
where
801-
D: ChainDriver<'b, C>,
802-
C: BlockContext,
801+
D: ChainDriver<'b, Ext, C>,
802+
C: BlockContext<Ext>,
803803
{
804804
let block_count = driver.blocks().len();
805805
let mut contexts = Vec::with_capacity(block_count);
806806

807807
let trevm = self
808808
.drive_block(&driver.blocks()[0])
809-
.map_err(EvmErrored::err_into::<<D as ChainDriver<'b, C>>::Error<Db>>)?;
809+
.map_err(EvmErrored::err_into::<<D as ChainDriver<'b, Ext, C>>::Error<Db>>)?;
810810

811811
if let Err(e) = driver.check_interblock(&trevm, 0) {
812812
return Err(trevm.errored(e));
@@ -820,7 +820,7 @@ impl<'a, Ext, Db: Database + DatabaseCommit> EvmNeedsBlock<'a, Ext, Db> {
820820
(context, trevm) = {
821821
let trevm = trevm
822822
.drive_block(&driver.blocks()[i])
823-
.map_err(EvmErrored::err_into::<<D as ChainDriver<'b, C>>::Error<Db>>)?;
823+
.map_err(EvmErrored::err_into::<<D as ChainDriver<'b, Ext, C>>::Error<Db>>)?;
824824
if let Err(e) = driver.check_interblock(&trevm, i) {
825825
return Err(trevm.errored(e));
826826
}
@@ -936,7 +936,7 @@ impl<'a, Ext, Db: Database + DatabaseCommit, TrevmState: HasContext>
936936
error: E,
937937
) -> EvmErrored<'a, Ext, Db, <TrevmState as HasContext>::Context, E>
938938
where
939-
<TrevmState as HasContext>::Context: BlockContext,
939+
<TrevmState as HasContext>::Context: BlockContext<Ext>,
940940
{
941941
EvmErrored {
942942
inner: self.inner,
@@ -947,7 +947,7 @@ impl<'a, Ext, Db: Database + DatabaseCommit, TrevmState: HasContext>
947947

948948
// --- NEEDS TX
949949

950-
impl<'a, Ext, Db: Database + DatabaseCommit, C: BlockContext> EvmNeedsTx<'a, Ext, Db, C> {
950+
impl<'a, Ext, Db: Database + DatabaseCommit, C: BlockContext<Ext>> EvmNeedsTx<'a, Ext, Db, C> {
951951
/// Close the current block, applying some logic, and returning the EVM
952952
/// ready for the next block.
953953
///
@@ -1015,7 +1015,7 @@ impl<'a, Ext, Db: Database + DatabaseCommit, TrevmState: HasTx> Trevm<'a, Ext, D
10151015

10161016
// --- READY
10171017

1018-
impl<'a, Ext, Db: Database + DatabaseCommit, C: BlockContext> EvmReady<'a, Ext, Db, C> {
1018+
impl<'a, Ext, Db: Database + DatabaseCommit, C: BlockContext<Ext>> EvmReady<'a, Ext, Db, C> {
10191019
/// Clear the current transaction environment.
10201020
pub fn clear_tx(self) -> EvmNeedsTx<'a, Ext, Db, C> {
10211021
// NB: we do not clear the tx env here, as we may read it during `BlockContext::post_tx`
@@ -1047,7 +1047,9 @@ impl<'a, Ext, Db: Database + DatabaseCommit, C: BlockContext> EvmReady<'a, Ext,
10471047

10481048
// --- ERRORED
10491049

1050-
impl<'a, Ext, Db: Database + DatabaseCommit, C: BlockContext, E> EvmErrored<'a, Ext, Db, C, E> {
1050+
impl<'a, Ext, Db: Database + DatabaseCommit, C: BlockContext<Ext>, E>
1051+
EvmErrored<'a, Ext, Db, C, E>
1052+
{
10511053
/// Get a reference to the error.
10521054
pub const fn error(&self) -> &E {
10531055
&self.state.error
@@ -1095,7 +1097,7 @@ impl<'a, Ext, Db: Database + DatabaseCommit, C: BlockContext, E> EvmErrored<'a,
10951097
}
10961098
}
10971099

1098-
impl<'a, Ext, Db: Database + DatabaseCommit, C: BlockContext>
1100+
impl<'a, Ext, Db: Database + DatabaseCommit, C: BlockContext<Ext>>
10991101
EvmErrored<'a, Ext, Db, C, EVMError<Db::Error>>
11001102
{
11011103
/// Check if the error is a transaction error. This is provided as a
@@ -1126,23 +1128,23 @@ impl<'a, Ext, Db: Database + DatabaseCommit, C: BlockContext>
11261128

11271129
// --- TRANSACTED
11281130

1129-
impl<'a, Ext, Db: Database + DatabaseCommit, C: BlockContext> AsRef<ResultAndState>
1131+
impl<'a, Ext, Db: Database + DatabaseCommit, C: BlockContext<Ext>> AsRef<ResultAndState>
11301132
for EvmTransacted<'a, Ext, Db, C>
11311133
{
11321134
fn as_ref(&self) -> &ResultAndState {
11331135
&self.state.result
11341136
}
11351137
}
11361138

1137-
impl<'a, Ext, Db: Database + DatabaseCommit, C: BlockContext> AsRef<ExecutionResult>
1139+
impl<'a, Ext, Db: Database + DatabaseCommit, C: BlockContext<Ext>> AsRef<ExecutionResult>
11381140
for EvmTransacted<'a, Ext, Db, C>
11391141
{
11401142
fn as_ref(&self) -> &ExecutionResult {
11411143
&self.state.result.result
11421144
}
11431145
}
11441146

1145-
impl<'a, Ext, Db: Database + DatabaseCommit, C: BlockContext> EvmTransacted<'a, Ext, Db, C> {
1147+
impl<'a, Ext, Db: Database + DatabaseCommit, C: BlockContext<Ext>> EvmTransacted<'a, Ext, Db, C> {
11461148
/// Get a reference to the result.
11471149
pub fn result(&self) -> &ExecutionResult {
11481150
self.as_ref()

0 commit comments

Comments
 (0)