Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trevm"
version = "0.20.3"
version = "0.20.4"
rust-version = "1.83.0"
edition = "2021"
authors = ["init4"]
Expand Down
8 changes: 5 additions & 3 deletions src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{evm::Trevm, helpers::Ctx, states::EvmNeedsCfg};
use revm::{
database::in_memory_db::InMemoryDB, primitives::hardfork::SpecId, Database, MainBuilder,
database::in_memory_db::InMemoryDB, inspector::NoOpInspector, primitives::hardfork::SpecId,
Database, Inspector, MainBuilder,
};

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

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

Expand Down Expand Up @@ -52,6 +53,7 @@ impl<Db, Insp> TrevmBuilder<Db, Insp> {
pub fn build_trevm(self) -> Result<EvmNeedsCfg<Db, Insp>, TrevmBuilderError>
where
Db: Database,
Insp: Inspector<Ctx<Db>>,
{
let db = self.db.ok_or(TrevmBuilderError::DatabaseNotSet)?;
let ctx = Ctx::new(db, self.spec);
Expand Down
11 changes: 8 additions & 3 deletions src/connect.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::{
Block, Cfg, EvmErrored, EvmNeedsBlock, EvmNeedsCfg, EvmNeedsTx, EvmReady, EvmTransacted, Tx,
helpers::Ctx, Block, Cfg, EvmErrored, EvmNeedsBlock, EvmNeedsCfg, EvmNeedsTx, EvmReady,
EvmTransacted, Tx,
};
use core::convert::Infallible;
use revm::{
context::result::{EVMError, ResultAndState},
Database,
Database, Inspector,
};
use std::format;

Expand Down Expand Up @@ -55,7 +56,11 @@ where
/// multiple threads.
pub trait EvmFactory: DbConnect {
/// The `Insp` type used in the resulting EVM.
type Insp: Sync;
///
/// Recommend using [`NoOpInspector`] for most use cases.
///
/// [`NoOpInspector`]: revm::inspector::NoOpInspector
type Insp: Sync + Inspector<Ctx<Self::Database>>;

/// Create a new EVM instance with the given database connection and
/// extension.
Expand Down
60 changes: 45 additions & 15 deletions src/driver/alloy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{
helpers::Ctx,
system::{MAX_BLOB_GAS_PER_BLOCK_CANCUN, MAX_BLOB_GAS_PER_BLOCK_PRAGUE},
trevm_bail, trevm_ensure, trevm_try, Block, BundleDriver, DriveBundleResult,
};
Expand All @@ -14,7 +15,7 @@ use alloy::{
use revm::{
context::result::{EVMError, ExecutionResult},
primitives::hardfork::SpecId,
Database, DatabaseCommit,
Database, DatabaseCommit, Inspector,
};

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

fn run_bundle<Db: Database + DatabaseCommit>(
fn run_bundle<Db>(
&mut self,
trevm: crate::EvmNeedsTx<Db, Insp>,
) -> DriveBundleResult<Db, Insp, Self> {
) -> DriveBundleResult<Db, Insp, Self>
where
Db: Database + DatabaseCommit,
Insp: Inspector<Ctx<Db>>,
{
// Check if the block we're in is valid for this bundle. Both must match
trevm_ensure!(
trevm.inner().block.number == self.bundle.block_number,
Expand Down Expand Up @@ -383,21 +388,29 @@ impl<Insp> BundleDriver<Insp> for BundleProcessor<EthCallBundle, EthCallBundleRe
}
}

fn post_bundle<Db: Database + DatabaseCommit>(
fn post_bundle<Db>(
&mut self,
_trevm: &crate::EvmNeedsTx<Db, Insp>,
) -> Result<(), Self::Error<Db>> {
) -> Result<(), Self::Error<Db>>
where
Db: Database + DatabaseCommit,
Insp: Inspector<Ctx<Db>>,
{
Ok(())
}
}

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

fn run_bundle<Db: Database + DatabaseCommit>(
fn run_bundle<Db>(
&mut self,
trevm: crate::EvmNeedsTx<Db, Insp>,
) -> DriveBundleResult<Db, Insp, Self> {
) -> DriveBundleResult<Db, Insp, Self>
where
Db: Database + DatabaseCommit,
Insp: Inspector<Ctx<Db>>,
{
{
// Check if the block we're in is valid for this bundle. Both must match
trevm_ensure!(
Expand Down Expand Up @@ -470,10 +483,14 @@ impl<Insp> BundleDriver<Insp> for BundleProcessor<EthSendBundle, EthBundleHash>
}
}

fn post_bundle<Db: Database + DatabaseCommit>(
fn post_bundle<Db>(
&mut self,
_trevm: &crate::EvmNeedsTx<Db, Insp>,
) -> Result<(), Self::Error<Db>> {
) -> Result<(), Self::Error<Db>>
where
Db: Database + DatabaseCommit,
Insp: Inspector<Ctx<Db>>,
{
Ok(())
}
}
Expand Down Expand Up @@ -537,10 +554,14 @@ impl From<EthCallBundle> for BundleBlockFiller {
impl<Insp> BundleDriver<Insp> for EthCallBundle {
type Error<Db: Database + DatabaseCommit> = BundleError<Db>;

fn run_bundle<Db: Database + DatabaseCommit>(
fn run_bundle<Db>(
&mut self,
trevm: crate::EvmNeedsTx<Db, Insp>,
) -> DriveBundleResult<Db, Insp, Self> {
) -> DriveBundleResult<Db, Insp, Self>
where
Db: Database + DatabaseCommit,
Insp: Inspector<Ctx<Db>>,
{
// Check if the block we're in is valid for this bundle. Both must match
trevm_ensure!(
trevm.inner().block.number == self.block_number,
Expand Down Expand Up @@ -613,10 +634,14 @@ impl<Insp> BundleDriver<Insp> for EthCallBundle {
}
}

fn post_bundle<Db: Database + DatabaseCommit>(
fn post_bundle<Db>(
&mut self,
_trevm: &crate::EvmNeedsTx<Db, Insp>,
) -> Result<(), Self::Error<Db>> {
) -> Result<(), Self::Error<Db>>
where
Db: Database + DatabaseCommit,
Insp: Inspector<Ctx<Db>>,
{
Ok(())
}
}
Expand All @@ -633,6 +658,7 @@ impl<Insp> BundleDriver<Insp> for EthSendBundle {
) -> DriveBundleResult<Db, Insp, Self>
where
Db: Database + DatabaseCommit,
Insp: Inspector<Ctx<Db>>,
{
// Check if the block we're in is valid for this bundle. Both must match
trevm_ensure!(
Expand Down Expand Up @@ -721,10 +747,14 @@ impl<Insp> BundleDriver<Insp> for EthSendBundle {
Ok(t)
}

fn post_bundle<Db: Database + DatabaseCommit>(
fn post_bundle<Db>(
&mut self,
_trevm: &crate::EvmNeedsTx<Db, Insp>,
) -> Result<(), Self::Error<Db>> {
) -> Result<(), Self::Error<Db>>
where
Db: Database + DatabaseCommit,
Insp: Inspector<Ctx<Db>>,
{
Ok(())
}
}
20 changes: 10 additions & 10 deletions src/driver/block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{Block, EvmBlockDriverErrored, EvmNeedsBlock, EvmNeedsTx};
use revm::{context::result::EVMError, Database, DatabaseCommit};
use crate::{helpers::Ctx, Block, EvmBlockDriverErrored, EvmNeedsBlock, EvmNeedsTx};
use revm::{context::result::EVMError, Database, DatabaseCommit, Inspector};

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

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

/// Run post
fn post_block<Db: Database + DatabaseCommit>(
&mut self,
trevm: &EvmNeedsBlock<Db, Insp>,
) -> Result<(), Self::Error<Db>>;
fn post_block<Db>(&mut self, trevm: &EvmNeedsBlock<Db, Insp>) -> Result<(), Self::Error<Db>>
where
Db: Database + DatabaseCommit,
Insp: Inspector<Ctx<Db>>;
}
10 changes: 6 additions & 4 deletions src/driver/bundle.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{states::EvmBundleDriverErrored, EvmNeedsTx};
use revm::{context::result::EVMError, Database, DatabaseCommit};
use crate::{helpers::Ctx, states::EvmBundleDriverErrored, EvmNeedsTx};
use revm::{context::result::EVMError, Database, DatabaseCommit, Inspector};

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

/// Run post
fn post_bundle<Db>(&mut self, trevm: &EvmNeedsTx<Db, Insp>) -> Result<(), Self::Error<Db>>
where
Db: Database + DatabaseCommit;
Db: Database + DatabaseCommit,
Insp: Inspector<Ctx<Db>>;
}
13 changes: 9 additions & 4 deletions src/driver/chain.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::{BlockDriver, EvmChainDriverErrored, EvmNeedsBlock};
use revm::{context::result::EVMError, primitives::hardfork::SpecId, Database, DatabaseCommit};
use crate::{helpers::Ctx, BlockDriver, EvmChainDriverErrored, EvmNeedsBlock};
use revm::{
context::result::EVMError, primitives::hardfork::SpecId, Database, DatabaseCommit, Inspector,
};

/// The result of driving a chain to completion.
pub type DriveChainResult<Db, Insp, D> =
Expand All @@ -26,9 +28,12 @@ pub trait ChainDriver<Insp> {
/// or parent-child relationships.
///
/// The `idx` parameter is the index of the block in the chain.
fn interblock<Db: Database + DatabaseCommit>(
fn interblock<Db>(
&mut self,
trevm: &EvmNeedsBlock<Db, Insp>,
idx: usize,
) -> Result<(), Self::Error<Db>>;
) -> Result<(), Self::Error<Db>>
where
Db: Database + DatabaseCommit,
Insp: Inspector<Ctx<Db>>;
}
Loading