Skip to content

Commit 2c2eb72

Browse files
committed
fix: db in driver traits again
1 parent f7252a1 commit 2c2eb72

File tree

6 files changed

+71
-103
lines changed

6 files changed

+71
-103
lines changed

src/driver/alloy.rs

Lines changed: 36 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -256,17 +256,17 @@ impl BundleProcessor<EthCallBundle, EthCallBundleResponse> {
256256
}
257257
}
258258

259-
impl<Insp> BundleDriver<Insp> for BundleProcessor<EthCallBundle, EthCallBundleResponse> {
260-
type Error<Db: Database + DatabaseCommit> = BundleError<Db>;
259+
impl<Db, Insp> BundleDriver<Db, Insp> for BundleProcessor<EthCallBundle, EthCallBundleResponse>
260+
where
261+
Db: Database + DatabaseCommit,
262+
Insp: Inspector<Ctx<Db>>,
263+
{
264+
type Error = BundleError<Db>;
261265

262-
fn run_bundle<Db>(
266+
fn run_bundle(
263267
&mut self,
264268
trevm: crate::EvmNeedsTx<Db, Insp>,
265-
) -> DriveBundleResult<Db, Insp, Self>
266-
where
267-
Db: Database + DatabaseCommit,
268-
Insp: Inspector<Ctx<Db>>,
269-
{
269+
) -> DriveBundleResult<Db, Insp, Self> {
270270
// Check if the block we're in is valid for this bundle. Both must match
271271
trevm_ensure!(
272272
trevm.inner().block.number == self.bundle.block_number,
@@ -388,29 +388,22 @@ impl<Insp> BundleDriver<Insp> for BundleProcessor<EthCallBundle, EthCallBundleRe
388388
}
389389
}
390390

391-
fn post_bundle<Db>(
392-
&mut self,
393-
_trevm: &crate::EvmNeedsTx<Db, Insp>,
394-
) -> Result<(), Self::Error<Db>>
395-
where
396-
Db: Database + DatabaseCommit,
397-
Insp: Inspector<Ctx<Db>>,
398-
{
391+
fn post_bundle(&mut self, _trevm: &crate::EvmNeedsTx<Db, Insp>) -> Result<(), Self::Error> {
399392
Ok(())
400393
}
401394
}
402395

403-
impl<Insp> BundleDriver<Insp> for BundleProcessor<EthSendBundle, EthBundleHash> {
404-
type Error<Db: Database + DatabaseCommit> = BundleError<Db>;
396+
impl<Db, Insp> BundleDriver<Db, Insp> for BundleProcessor<EthSendBundle, EthBundleHash>
397+
where
398+
Db: Database + DatabaseCommit,
399+
Insp: Inspector<Ctx<Db>>,
400+
{
401+
type Error = BundleError<Db>;
405402

406-
fn run_bundle<Db>(
403+
fn run_bundle(
407404
&mut self,
408405
trevm: crate::EvmNeedsTx<Db, Insp>,
409-
) -> DriveBundleResult<Db, Insp, Self>
410-
where
411-
Db: Database + DatabaseCommit,
412-
Insp: Inspector<Ctx<Db>>,
413-
{
406+
) -> DriveBundleResult<Db, Insp, Self> {
414407
{
415408
// Check if the block we're in is valid for this bundle. Both must match
416409
trevm_ensure!(
@@ -483,14 +476,7 @@ impl<Insp> BundleDriver<Insp> for BundleProcessor<EthSendBundle, EthBundleHash>
483476
}
484477
}
485478

486-
fn post_bundle<Db>(
487-
&mut self,
488-
_trevm: &crate::EvmNeedsTx<Db, Insp>,
489-
) -> Result<(), Self::Error<Db>>
490-
where
491-
Db: Database + DatabaseCommit,
492-
Insp: Inspector<Ctx<Db>>,
493-
{
479+
fn post_bundle(&mut self, _trevm: &crate::EvmNeedsTx<Db, Insp>) -> Result<(), Self::Error> {
494480
Ok(())
495481
}
496482
}
@@ -551,17 +537,17 @@ impl From<EthCallBundle> for BundleBlockFiller {
551537
}
552538
}
553539

554-
impl<Insp> BundleDriver<Insp> for EthCallBundle {
555-
type Error<Db: Database + DatabaseCommit> = BundleError<Db>;
540+
impl<Db, Insp> BundleDriver<Db, Insp> for EthCallBundle
541+
where
542+
Db: Database + DatabaseCommit,
543+
Insp: Inspector<Ctx<Db>>,
544+
{
545+
type Error = BundleError<Db>;
556546

557-
fn run_bundle<Db>(
547+
fn run_bundle(
558548
&mut self,
559549
trevm: crate::EvmNeedsTx<Db, Insp>,
560-
) -> DriveBundleResult<Db, Insp, Self>
561-
where
562-
Db: Database + DatabaseCommit,
563-
Insp: Inspector<Ctx<Db>>,
564-
{
550+
) -> DriveBundleResult<Db, Insp, Self> {
565551
// Check if the block we're in is valid for this bundle. Both must match
566552
trevm_ensure!(
567553
trevm.inner().block.number == self.block_number,
@@ -634,32 +620,25 @@ impl<Insp> BundleDriver<Insp> for EthCallBundle {
634620
}
635621
}
636622

637-
fn post_bundle<Db>(
638-
&mut self,
639-
_trevm: &crate::EvmNeedsTx<Db, Insp>,
640-
) -> Result<(), Self::Error<Db>>
641-
where
642-
Db: Database + DatabaseCommit,
643-
Insp: Inspector<Ctx<Db>>,
644-
{
623+
fn post_bundle(&mut self, _trevm: &crate::EvmNeedsTx<Db, Insp>) -> Result<(), Self::Error> {
645624
Ok(())
646625
}
647626
}
648627

649628
/// An implementation of [BundleDriver] for [EthSendBundle].
650629
/// This allows us to drive a bundle of transactions and accumulate the resulting state in the EVM.
651630
/// Allows to simply take an [EthSendBundle] and get the resulting EVM state.
652-
impl<Insp> BundleDriver<Insp> for EthSendBundle {
653-
type Error<Db: Database + DatabaseCommit> = BundleError<Db>;
631+
impl<Db, Insp> BundleDriver<Db, Insp> for EthSendBundle
632+
where
633+
Db: Database + DatabaseCommit,
634+
Insp: Inspector<Ctx<Db>>,
635+
{
636+
type Error = BundleError<Db>;
654637

655-
fn run_bundle<Db>(
638+
fn run_bundle(
656639
&mut self,
657640
trevm: crate::EvmNeedsTx<Db, Insp>,
658-
) -> DriveBundleResult<Db, Insp, Self>
659-
where
660-
Db: Database + DatabaseCommit,
661-
Insp: Inspector<Ctx<Db>>,
662-
{
641+
) -> DriveBundleResult<Db, Insp, Self> {
663642
// Check if the block we're in is valid for this bundle. Both must match
664643
trevm_ensure!(
665644
trevm.inner().block.number == self.block_number,
@@ -747,14 +726,7 @@ impl<Insp> BundleDriver<Insp> for EthSendBundle {
747726
Ok(t)
748727
}
749728

750-
fn post_bundle<Db>(
751-
&mut self,
752-
_trevm: &crate::EvmNeedsTx<Db, Insp>,
753-
) -> Result<(), Self::Error<Db>>
754-
where
755-
Db: Database + DatabaseCommit,
756-
Insp: Inspector<Ctx<Db>>,
757-
{
729+
fn post_bundle(&mut self, _trevm: &crate::EvmNeedsTx<Db, Insp>) -> Result<(), Self::Error> {
758730
Ok(())
759731
}
760732
}

src/driver/block.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,22 @@ pub type DriveBlockResult<Db, Insp, 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<Insp> {
15+
pub trait BlockDriver<Db, Insp>
16+
where
17+
Db: Database + DatabaseCommit,
18+
Insp: Inspector<Ctx<Db>>,
19+
{
1620
/// The [`Block`] filler for this driver.
1721
type Block: Block;
1822

1923
/// An error type for this driver.
20-
type Error<Db: Database + DatabaseCommit>: core::error::Error + From<EVMError<Db::Error>>;
24+
type Error: core::error::Error + From<EVMError<Db::Error>>;
2125

2226
/// Get a reference to the block filler for this driver.
2327
fn block(&self) -> &Self::Block;
2428

2529
/// Run the transactions for the block.
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>>;
30-
30+
fn run_txns(&mut self, trevm: EvmNeedsTx<Db, Insp>) -> RunTxResult<Db, Insp, Self>;
3131
/// Run post
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>>;
32+
fn post_block(&mut self, trevm: &EvmNeedsBlock<Db, Insp>) -> Result<(), Self::Error>;
3633
}

src/driver/bundle.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ pub type DriveBundleResult<Db, Insp, T> =
77

88
/// Driver for a bundle of transactions. This trait allows a type to specify the
99
/// entire lifecycle of a bundle, simulating the entire list of transactions.
10-
pub trait BundleDriver<Insp> {
10+
pub trait BundleDriver<Db, Insp>
11+
where
12+
Db: Database + DatabaseCommit,
13+
Insp: Inspector<Ctx<Db>>,
14+
{
1115
/// An error type for this driver.
12-
type Error<Db: Database + DatabaseCommit>: core::error::Error + From<EVMError<Db::Error>>;
16+
type Error: core::error::Error + From<EVMError<Db::Error>>;
1317

1418
/// Run the transactions contained in the bundle.
15-
fn run_bundle<Db>(&mut self, trevm: EvmNeedsTx<Db, Insp>) -> DriveBundleResult<Db, Insp, Self>
16-
where
17-
Db: Database + DatabaseCommit,
18-
Insp: Inspector<Ctx<Db>>;
19+
fn run_bundle(&mut self, trevm: EvmNeedsTx<Db, Insp>) -> DriveBundleResult<Db, Insp, Self>;
1920

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

src/driver/chain.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@ pub type DriveChainResult<Db, Insp, D> =
88
Result<EvmNeedsBlock<Db, Insp>, EvmChainDriverErrored<Db, Insp, D>>;
99

1010
/// Driver for a chain of blocks.
11-
pub trait ChainDriver<Insp> {
11+
pub trait ChainDriver<Db, Insp>
12+
where
13+
Db: Database + DatabaseCommit,
14+
Insp: Inspector<Ctx<Db>>,
15+
{
1216
/// The block driver for this chain.
13-
type BlockDriver: BlockDriver<Insp>;
17+
type BlockDriver: BlockDriver<Db, Insp>;
1418

1519
/// An error type for this driver.
16-
type Error<Db: Database + DatabaseCommit>: core::error::Error
20+
type Error: core::error::Error
1721
+ From<EVMError<Db::Error>>
18-
+ From<<Self::BlockDriver as BlockDriver<Insp>>::Error<Db>>;
22+
+ From<<Self::BlockDriver as BlockDriver<Db, Insp>>::Error>;
1923

2024
/// Get the spec id for a block.
21-
fn spec_id_for(&self, block: &<Self::BlockDriver as BlockDriver<Insp>>::Block) -> SpecId;
25+
fn spec_id_for(&self, block: &<Self::BlockDriver as BlockDriver<Db, Insp>>::Block) -> SpecId;
2226

2327
/// Get the blocks in this chain. The blocks should be in order, and this
2428
/// function MUST NOT return an empty slice.
@@ -28,12 +32,9 @@ pub trait ChainDriver<Insp> {
2832
/// or parent-child relationships.
2933
///
3034
/// The `idx` parameter is the index of the block in the chain.
31-
fn interblock<Db>(
35+
fn interblock(
3236
&mut self,
3337
trevm: &EvmNeedsBlock<Db, Insp>,
3438
idx: usize,
35-
) -> Result<(), Self::Error<Db>>
36-
where
37-
Db: Database + DatabaseCommit,
38-
Insp: Inspector<Ctx<Db>>;
39+
) -> Result<(), Self::Error>;
3940
}

src/evm.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ where
977977
/// block.
978978
pub fn drive_block<D>(self, driver: &mut D) -> DriveBlockResult<Db, Insp, D>
979979
where
980-
D: BlockDriver<Insp>,
980+
D: BlockDriver<Db, Insp>,
981981
Db: DatabaseCommit,
982982
{
983983
let trevm = self.fill_block(driver.block());
@@ -998,14 +998,14 @@ where
998998
/// If the driver contains no blocks.
999999
pub fn drive_chain<D>(self, driver: &mut D) -> DriveChainResult<Db, Insp, D>
10001000
where
1001-
D: ChainDriver<Insp>,
1001+
D: ChainDriver<Db, Insp>,
10021002
Db: DatabaseCommit,
10031003
{
10041004
let block_count = driver.blocks().len();
10051005

10061006
let mut trevm = self
10071007
.drive_block(&mut driver.blocks()[0])
1008-
.map_err(EvmErrored::err_into::<<D as ChainDriver<Insp>>::Error<Db>>)?;
1008+
.map_err(EvmErrored::err_into::<<D as ChainDriver<Db, Insp>>::Error>)?;
10091009

10101010
if let Err(e) = driver.interblock(&trevm, 0) {
10111011
return Err(trevm.errored(e));
@@ -1015,7 +1015,7 @@ where
10151015
trevm = {
10161016
let trevm = trevm
10171017
.drive_block(&mut driver.blocks()[i])
1018-
.map_err(EvmErrored::err_into::<<D as ChainDriver<Insp>>::Error<Db>>)?;
1018+
.map_err(EvmErrored::err_into::<<D as ChainDriver<Db, Insp>>::Error>)?;
10191019
if let Err(e) = driver.interblock(&trevm, i) {
10201020
return Err(trevm.errored(e));
10211021
}
@@ -1184,7 +1184,7 @@ where
11841184
/// EVM ready for the next bundle or tx.
11851185
pub fn drive_bundle<D>(self, driver: &mut D) -> DriveBundleResult<Db, Insp, D>
11861186
where
1187-
D: BundleDriver<Insp>,
1187+
D: BundleDriver<Db, Insp>,
11881188
Db: DatabaseCommit,
11891189
{
11901190
let trevm = driver.run_bundle(self)?;

src/states.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ pub type EvmErrored<Db, Insp, E = EVMError<<Db as Database>::Error>> =
5757
///
5858
/// This is an [`EvmErrored`] parameterized with the driver's error type.
5959
pub type EvmBlockDriverErrored<Db, Insp, T> =
60-
EvmErrored<Db, Insp, <T as BlockDriver<Insp>>::Error<Db>>;
60+
EvmErrored<Db, Insp, <T as BlockDriver<Db, Insp>>::Error>;
6161

6262
/// A [`Trevm`] that encountered an error during [`ChainDriver`] execution.
6363
///
6464
/// This is an [`EvmErrored`] parameterized with the driver's error type.
6565
pub type EvmChainDriverErrored<Db, Insp, T> =
66-
EvmErrored<Db, Insp, <T as ChainDriver<Insp>>::Error<Db>>;
66+
EvmErrored<Db, Insp, <T as ChainDriver<Db, Insp>>::Error>;
6767

6868
/// A [`Trevm`] that encountered an error during [`BundleDriver`] execution.
6969
///
7070
/// This is an [`EvmErrored`] parameterized with the driver's error type.
7171
pub type EvmBundleDriverErrored<Db, Insp, T> =
72-
EvmErrored<Db, Insp, <T as BundleDriver<Insp>>::Error<Db>>;
72+
EvmErrored<Db, Insp, <T as BundleDriver<Db, Insp>>::Error>;
7373

7474
#[allow(unnameable_types, dead_code, unreachable_pub)]
7575
pub(crate) mod sealed {

0 commit comments

Comments
 (0)