Skip to content

Commit 9a79e24

Browse files
authored
fix: add inspector bounds and always inspect (#96)
* fix: add inspector bounds and always inspect * chore: version bump * fix: doclink
1 parent 3366506 commit 9a79e24

14 files changed

+259
-98
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.20.3"
3+
version = "0.20.4"
44
rust-version = "1.83.0"
55
edition = "2021"
66
authors = ["init4"]

src/builder.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{evm::Trevm, helpers::Ctx, states::EvmNeedsCfg};
22
use revm::{
3-
database::in_memory_db::InMemoryDB, primitives::hardfork::SpecId, Database, MainBuilder,
3+
database::in_memory_db::InMemoryDB, inspector::NoOpInspector, primitives::hardfork::SpecId,
4+
Database, Inspector, MainBuilder,
45
};
56

67
/// Error that can occur when building a Trevm instance.
@@ -20,11 +21,11 @@ pub struct TrevmBuilder<Db, Insp> {
2021
pub(crate) spec: SpecId,
2122
}
2223

23-
impl TrevmBuilder<InMemoryDB, ()> {
24+
impl TrevmBuilder<InMemoryDB, NoOpInspector> {
2425
/// Create a new builder with the default database and inspector.
2526
#[allow(clippy::new_without_default)] // default would make bad devex :(
2627
pub const fn new() -> Self {
27-
Self { db: None, insp: (), spec: SpecId::PRAGUE }
28+
Self { db: None, insp: NoOpInspector, spec: SpecId::PRAGUE }
2829
}
2930
}
3031

@@ -52,6 +53,7 @@ impl<Db, Insp> TrevmBuilder<Db, Insp> {
5253
pub fn build_trevm(self) -> Result<EvmNeedsCfg<Db, Insp>, TrevmBuilderError>
5354
where
5455
Db: Database,
56+
Insp: Inspector<Ctx<Db>>,
5557
{
5658
let db = self.db.ok_or(TrevmBuilderError::DatabaseNotSet)?;
5759
let ctx = Ctx::new(db, self.spec);

src/connect.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use crate::{
2-
Block, Cfg, EvmErrored, EvmNeedsBlock, EvmNeedsCfg, EvmNeedsTx, EvmReady, EvmTransacted, Tx,
2+
helpers::Ctx, Block, Cfg, EvmErrored, EvmNeedsBlock, EvmNeedsCfg, EvmNeedsTx, EvmReady,
3+
EvmTransacted, Tx,
34
};
45
use core::convert::Infallible;
56
use revm::{
67
context::result::{EVMError, ResultAndState},
7-
Database,
8+
Database, Inspector,
89
};
910
use std::format;
1011

@@ -55,7 +56,11 @@ where
5556
/// multiple threads.
5657
pub trait EvmFactory: DbConnect {
5758
/// The `Insp` type used in the resulting EVM.
58-
type Insp: Sync;
59+
///
60+
/// Recommend using [`NoOpInspector`] for most use cases.
61+
///
62+
/// [`NoOpInspector`]: revm::inspector::NoOpInspector
63+
type Insp: Sync + Inspector<Ctx<Self::Database>>;
5964

6065
/// Create a new EVM instance with the given database connection and
6166
/// extension.

src/driver/alloy.rs

+45-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{
2+
helpers::Ctx,
23
system::{MAX_BLOB_GAS_PER_BLOCK_CANCUN, MAX_BLOB_GAS_PER_BLOCK_PRAGUE},
34
trevm_bail, trevm_ensure, trevm_try, Block, BundleDriver, DriveBundleResult,
45
};
@@ -14,7 +15,7 @@ use alloy::{
1415
use revm::{
1516
context::result::{EVMError, ExecutionResult},
1617
primitives::hardfork::SpecId,
17-
Database, DatabaseCommit,
18+
Database, DatabaseCommit, Inspector,
1819
};
1920

2021
/// Possible errors that can occur while driving a bundle.
@@ -258,10 +259,14 @@ impl BundleProcessor<EthCallBundle, EthCallBundleResponse> {
258259
impl<Insp> BundleDriver<Insp> for BundleProcessor<EthCallBundle, EthCallBundleResponse> {
259260
type Error<Db: Database + DatabaseCommit> = BundleError<Db>;
260261

261-
fn run_bundle<Db: Database + DatabaseCommit>(
262+
fn run_bundle<Db>(
262263
&mut self,
263264
trevm: crate::EvmNeedsTx<Db, Insp>,
264-
) -> DriveBundleResult<Db, Insp, Self> {
265+
) -> DriveBundleResult<Db, Insp, Self>
266+
where
267+
Db: Database + DatabaseCommit,
268+
Insp: Inspector<Ctx<Db>>,
269+
{
265270
// Check if the block we're in is valid for this bundle. Both must match
266271
trevm_ensure!(
267272
trevm.inner().block.number == self.bundle.block_number,
@@ -383,21 +388,29 @@ impl<Insp> BundleDriver<Insp> for BundleProcessor<EthCallBundle, EthCallBundleRe
383388
}
384389
}
385390

386-
fn post_bundle<Db: Database + DatabaseCommit>(
391+
fn post_bundle<Db>(
387392
&mut self,
388393
_trevm: &crate::EvmNeedsTx<Db, Insp>,
389-
) -> Result<(), Self::Error<Db>> {
394+
) -> Result<(), Self::Error<Db>>
395+
where
396+
Db: Database + DatabaseCommit,
397+
Insp: Inspector<Ctx<Db>>,
398+
{
390399
Ok(())
391400
}
392401
}
393402

394403
impl<Insp> BundleDriver<Insp> for BundleProcessor<EthSendBundle, EthBundleHash> {
395404
type Error<Db: Database + DatabaseCommit> = BundleError<Db>;
396405

397-
fn run_bundle<Db: Database + DatabaseCommit>(
406+
fn run_bundle<Db>(
398407
&mut self,
399408
trevm: crate::EvmNeedsTx<Db, Insp>,
400-
) -> DriveBundleResult<Db, Insp, Self> {
409+
) -> DriveBundleResult<Db, Insp, Self>
410+
where
411+
Db: Database + DatabaseCommit,
412+
Insp: Inspector<Ctx<Db>>,
413+
{
401414
{
402415
// Check if the block we're in is valid for this bundle. Both must match
403416
trevm_ensure!(
@@ -470,10 +483,14 @@ impl<Insp> BundleDriver<Insp> for BundleProcessor<EthSendBundle, EthBundleHash>
470483
}
471484
}
472485

473-
fn post_bundle<Db: Database + DatabaseCommit>(
486+
fn post_bundle<Db>(
474487
&mut self,
475488
_trevm: &crate::EvmNeedsTx<Db, Insp>,
476-
) -> Result<(), Self::Error<Db>> {
489+
) -> Result<(), Self::Error<Db>>
490+
where
491+
Db: Database + DatabaseCommit,
492+
Insp: Inspector<Ctx<Db>>,
493+
{
477494
Ok(())
478495
}
479496
}
@@ -537,10 +554,14 @@ impl From<EthCallBundle> for BundleBlockFiller {
537554
impl<Insp> BundleDriver<Insp> for EthCallBundle {
538555
type Error<Db: Database + DatabaseCommit> = BundleError<Db>;
539556

540-
fn run_bundle<Db: Database + DatabaseCommit>(
557+
fn run_bundle<Db>(
541558
&mut self,
542559
trevm: crate::EvmNeedsTx<Db, Insp>,
543-
) -> DriveBundleResult<Db, Insp, Self> {
560+
) -> DriveBundleResult<Db, Insp, Self>
561+
where
562+
Db: Database + DatabaseCommit,
563+
Insp: Inspector<Ctx<Db>>,
564+
{
544565
// Check if the block we're in is valid for this bundle. Both must match
545566
trevm_ensure!(
546567
trevm.inner().block.number == self.block_number,
@@ -613,10 +634,14 @@ impl<Insp> BundleDriver<Insp> for EthCallBundle {
613634
}
614635
}
615636

616-
fn post_bundle<Db: Database + DatabaseCommit>(
637+
fn post_bundle<Db>(
617638
&mut self,
618639
_trevm: &crate::EvmNeedsTx<Db, Insp>,
619-
) -> Result<(), Self::Error<Db>> {
640+
) -> Result<(), Self::Error<Db>>
641+
where
642+
Db: Database + DatabaseCommit,
643+
Insp: Inspector<Ctx<Db>>,
644+
{
620645
Ok(())
621646
}
622647
}
@@ -633,6 +658,7 @@ impl<Insp> BundleDriver<Insp> for EthSendBundle {
633658
) -> DriveBundleResult<Db, Insp, Self>
634659
where
635660
Db: Database + DatabaseCommit,
661+
Insp: Inspector<Ctx<Db>>,
636662
{
637663
// Check if the block we're in is valid for this bundle. Both must match
638664
trevm_ensure!(
@@ -721,10 +747,14 @@ impl<Insp> BundleDriver<Insp> for EthSendBundle {
721747
Ok(t)
722748
}
723749

724-
fn post_bundle<Db: Database + DatabaseCommit>(
750+
fn post_bundle<Db>(
725751
&mut self,
726752
_trevm: &crate::EvmNeedsTx<Db, Insp>,
727-
) -> Result<(), Self::Error<Db>> {
753+
) -> Result<(), Self::Error<Db>>
754+
where
755+
Db: Database + DatabaseCommit,
756+
Insp: Inspector<Ctx<Db>>,
757+
{
728758
Ok(())
729759
}
730760
}

src/driver/block.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::{Block, EvmBlockDriverErrored, EvmNeedsBlock, EvmNeedsTx};
2-
use revm::{context::result::EVMError, Database, DatabaseCommit};
1+
use crate::{helpers::Ctx, Block, EvmBlockDriverErrored, EvmNeedsBlock, EvmNeedsTx};
2+
use revm::{context::result::EVMError, Database, DatabaseCommit, Inspector};
33

44
/// The result of running transactions for a block driver.
55
pub type RunTxResult<Db, Insp, T> =
@@ -23,14 +23,14 @@ pub trait BlockDriver<Insp> {
2323
fn block(&self) -> &Self::Block;
2424

2525
/// Run the transactions for the block.
26-
fn run_txns<Db: Database + DatabaseCommit>(
27-
&mut self,
28-
trevm: EvmNeedsTx<Db, Insp>,
29-
) -> RunTxResult<Db, Insp, Self>;
26+
fn run_txns<Db>(&mut self, trevm: EvmNeedsTx<Db, Insp>) -> RunTxResult<Db, Insp, Self>
27+
where
28+
Db: Database + DatabaseCommit,
29+
Insp: Inspector<Ctx<Db>>;
3030

3131
/// Run post
32-
fn post_block<Db: Database + DatabaseCommit>(
33-
&mut self,
34-
trevm: &EvmNeedsBlock<Db, Insp>,
35-
) -> Result<(), Self::Error<Db>>;
32+
fn post_block<Db>(&mut self, trevm: &EvmNeedsBlock<Db, Insp>) -> Result<(), Self::Error<Db>>
33+
where
34+
Db: Database + DatabaseCommit,
35+
Insp: Inspector<Ctx<Db>>;
3636
}

src/driver/bundle.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::{states::EvmBundleDriverErrored, EvmNeedsTx};
2-
use revm::{context::result::EVMError, Database, DatabaseCommit};
1+
use crate::{helpers::Ctx, states::EvmBundleDriverErrored, EvmNeedsTx};
2+
use revm::{context::result::EVMError, Database, DatabaseCommit, Inspector};
33

44
/// The result of driving a bundle to completion.
55
pub type DriveBundleResult<Db, Insp, T> =
@@ -14,10 +14,12 @@ pub trait BundleDriver<Insp> {
1414
/// Run the transactions contained in the bundle.
1515
fn run_bundle<Db>(&mut self, trevm: EvmNeedsTx<Db, Insp>) -> DriveBundleResult<Db, Insp, Self>
1616
where
17-
Db: Database + DatabaseCommit;
17+
Db: Database + DatabaseCommit,
18+
Insp: Inspector<Ctx<Db>>;
1819

1920
/// Run post
2021
fn post_bundle<Db>(&mut self, trevm: &EvmNeedsTx<Db, Insp>) -> Result<(), Self::Error<Db>>
2122
where
22-
Db: Database + DatabaseCommit;
23+
Db: Database + DatabaseCommit,
24+
Insp: Inspector<Ctx<Db>>;
2325
}

src/driver/chain.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
use crate::{BlockDriver, EvmChainDriverErrored, EvmNeedsBlock};
2-
use revm::{context::result::EVMError, primitives::hardfork::SpecId, Database, DatabaseCommit};
1+
use crate::{helpers::Ctx, BlockDriver, EvmChainDriverErrored, EvmNeedsBlock};
2+
use revm::{
3+
context::result::EVMError, primitives::hardfork::SpecId, Database, DatabaseCommit, Inspector,
4+
};
35

46
/// The result of driving a chain to completion.
57
pub type DriveChainResult<Db, Insp, D> =
@@ -26,9 +28,12 @@ pub trait ChainDriver<Insp> {
2628
/// or parent-child relationships.
2729
///
2830
/// The `idx` parameter is the index of the block in the chain.
29-
fn interblock<Db: Database + DatabaseCommit>(
31+
fn interblock<Db>(
3032
&mut self,
3133
trevm: &EvmNeedsBlock<Db, Insp>,
3234
idx: usize,
33-
) -> Result<(), Self::Error<Db>>;
35+
) -> Result<(), Self::Error<Db>>
36+
where
37+
Db: Database + DatabaseCommit,
38+
Insp: Inspector<Ctx<Db>>;
3439
}

0 commit comments

Comments
 (0)