Skip to content

Commit 15aff7a

Browse files
authoredApr 4, 2025··
fix: db in driver traits again (#100)
* fix: db in driver traits again * chore: clippy * chore: bump version to 0.20.6
1 parent f7252a1 commit 15aff7a

File tree

13 files changed

+88
-116
lines changed

13 files changed

+88
-116
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.5"
3+
version = "0.20.6"
44
rust-version = "1.83.0"
55
edition = "2021"
66
authors = ["init4"]

‎src/db/sync/cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl ConcurrentCacheState {
5959
}
6060

6161
/// Set state clear flag. EIP-161.
62-
pub fn set_state_clear_flag(&mut self, has_state_clear: bool) {
62+
pub const fn set_state_clear_flag(&mut self, has_state_clear: bool) {
6363
self.has_state_clear = has_state_clear;
6464
}
6565

‎src/db/sync/state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<Db> ConcurrentState<Db> {
6060
}
6161

6262
/// State clear EIP-161 is enabled in Spurious Dragon hardfork.
63-
pub fn set_state_clear_flag(&mut self, has_state_clear: bool) {
63+
pub const fn set_state_clear_flag(&mut self, has_state_clear: bool) {
6464
self.info.cache.set_state_clear_flag(has_state_clear);
6565
}
6666

‎src/driver/alloy.rs

+36-64
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

+8-11
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

+8-10
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

+11-10
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/est.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl EstimationResult {
240240
}
241241

242242
/// Adjust the binary search range based on the estimation outcome.
243-
pub(crate) fn adjust_binary_search_range(
243+
pub(crate) const fn adjust_binary_search_range(
244244
&self,
245245
limit: u64,
246246
range: &mut SearchRange,

‎src/evm.rs

+8-8
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)?;
@@ -1935,7 +1935,7 @@ where
19351935
/// This is primarily intended for use in [`SystemTx`] execution.
19361936
///
19371937
/// [`SystemTx`]: crate::system::SystemTx
1938-
pub fn result_mut_unchecked(&mut self) -> &mut ExecutionResult {
1938+
pub const fn result_mut_unchecked(&mut self) -> &mut ExecutionResult {
19391939
&mut self.state.result.result
19401940
}
19411941

@@ -1946,7 +1946,7 @@ where
19461946

19471947
/// Get a mutable reference to the state. Modification of the state is
19481948
/// discouraged, as it may lead to inconsistent state.
1949-
pub fn state_mut_unchecked(&mut self) -> &mut EvmState {
1949+
pub const fn state_mut_unchecked(&mut self) -> &mut EvmState {
19501950
&mut self.state.result.state
19511951
}
19521952

@@ -1961,7 +1961,7 @@ where
19611961
/// This is primarily intended for use in [`SystemTx`] execution.
19621962
///
19631963
/// [`SystemTx`]: crate::system::SystemTx
1964-
pub fn result_and_state_mut_unchecked(&mut self) -> &mut ResultAndState {
1964+
pub const fn result_and_state_mut_unchecked(&mut self) -> &mut ResultAndState {
19651965
&mut self.state.result
19661966
}
19671967

‎src/inspectors/layer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<Outer, Inner> Layered<Outer, Inner> {
4848
}
4949

5050
/// Get a mutable reference to the current inspector.
51-
pub fn outer_mut(&mut self) -> &mut Outer {
51+
pub const fn outer_mut(&mut self) -> &mut Outer {
5252
&mut self.outer
5353
}
5454

@@ -58,7 +58,7 @@ impl<Outer, Inner> Layered<Outer, Inner> {
5858
}
5959

6060
/// Get a mutable reference to the inner inspector.
61-
pub fn inner_mut(&mut self) -> &mut Inner {
61+
pub const fn inner_mut(&mut self) -> &mut Inner {
6262
&mut self.inner
6363
}
6464
}

‎src/journal/index.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ pub enum InfoOutcome<'a> {
3838
impl InfoOutcome<'_> {
3939
/// Get the original account info. This is `None` if the account was
4040
/// created.
41-
pub fn original(&self) -> Option<Cow<'_, AccountInfo>> {
41+
pub const fn original(&self) -> Option<Cow<'_, AccountInfo>> {
4242
match self {
4343
Self::Created(_) => None,
44-
Self::Diff { old, .. } => Some(Cow::Borrowed(old)),
45-
Self::Destroyed(info) => Some(Cow::Borrowed(info)),
44+
Self::Diff { old: Cow::Owned(old), .. } => Some(Cow::Borrowed(old)),
45+
Self::Diff { old: Cow::Borrowed(old), .. } => Some(Cow::Borrowed(*old)),
46+
Self::Destroyed(Cow::Owned(old)) => Some(Cow::Borrowed(old)),
47+
Self::Destroyed(Cow::Borrowed(old)) => Some(Cow::Borrowed(*old)),
4648
}
4749
}
4850

@@ -96,7 +98,7 @@ pub struct AcctDiff<'a> {
9698
impl AcctDiff<'_> {
9799
/// Get the original account info. This is `None` if the account was
98100
/// created.
99-
pub fn original(&self) -> Option<Cow<'_, AccountInfo>> {
101+
pub const fn original(&self) -> Option<Cow<'_, AccountInfo>> {
100102
self.outcome.original()
101103
}
102104

‎src/lifecycle/output.rs

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ impl<T: TxReceipt<Log = alloy::primitives::Log>> BlockOutput<T> {
5858
}
5959

6060
/// Get a reference to the receipts of the transactions in the block.
61+
#[allow(clippy::missing_const_for_fn)] // false positive
6162
pub fn receipts(&self) -> &[T] {
6263
&self.receipts
6364
}
@@ -74,6 +75,7 @@ impl<T: TxReceipt<Log = alloy::primitives::Log>> BlockOutput<T> {
7475
}
7576

7677
/// Get a reference the senders of the transactions in the block.
78+
#[allow(clippy::missing_const_for_fn)] // false positive
7779
pub fn senders(&self) -> &[Address] {
7880
&self.senders
7981
}

‎src/states.rs

+3-3
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)
Please sign in to comment.