Skip to content

Commit 506dcc1

Browse files
committed
chore: integrate into trevm
1 parent 1ad8681 commit 506dcc1

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

src/db/sync_state.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use revm::{
77
BundleState,
88
},
99
primitives::{Account, AccountInfo, Bytecode},
10-
DatabaseCommit, DatabaseRef, TransitionAccount, TransitionState,
10+
Database, DatabaseCommit, DatabaseRef, TransitionAccount, TransitionState,
1111
};
1212
use std::{
1313
collections::{hash_map, BTreeMap},
@@ -300,6 +300,26 @@ impl<DB: DatabaseRef> DatabaseCommit for ConcurrentState<DB> {
300300
}
301301
}
302302

303+
impl<Db: DatabaseRef> Database for ConcurrentState<Db> {
304+
type Error = <Self as DatabaseRef>::Error;
305+
306+
fn basic(&mut self, address: Address) -> Result<Option<AccountInfo>, Self::Error> {
307+
self.basic_ref(address)
308+
}
309+
310+
fn code_by_hash(&mut self, code_hash: B256) -> Result<Bytecode, Self::Error> {
311+
self.code_by_hash_ref(code_hash)
312+
}
313+
314+
fn storage(&mut self, address: Address, index: U256) -> Result<U256, Self::Error> {
315+
self.storage_ref(address, index)
316+
}
317+
318+
fn block_hash(&mut self, number: u64) -> Result<B256, Self::Error> {
319+
self.block_hash_ref(number)
320+
}
321+
}
322+
303323
// Some code above and documentation is adapted from the revm crate, and is
304324
// reproduced here under the terms of the MIT license.
305325
//

src/evm.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::{
2-
driver::DriveBlockResult, Block, BlockDriver, BundleDriver, Cfg, ChainDriver,
3-
DriveBundleResult, DriveChainResult, ErroredState, EvmErrored, EvmExtUnchecked, EvmNeedsBlock,
4-
EvmNeedsCfg, EvmNeedsTx, EvmReady, EvmTransacted, HasBlock, HasCfg, HasTx, NeedsCfg, NeedsTx,
5-
TransactedState, Tx,
2+
db::ConcurrentState, driver::DriveBlockResult, Block, BlockDriver, BundleDriver, Cfg,
3+
ChainDriver, DriveBundleResult, DriveChainResult, ErroredState, EvmErrored, EvmExtUnchecked,
4+
EvmNeedsBlock, EvmNeedsCfg, EvmNeedsTx, EvmReady, EvmTransacted, HasBlock, HasCfg, HasTx,
5+
NeedsCfg, NeedsTx, TransactedState, Tx,
66
};
77
use alloc::{boxed::Box, fmt};
88
use alloy_primitives::{Address, Bytes, U256};
@@ -440,7 +440,7 @@ impl<Ext, Db: Database<Error = Infallible> + DatabaseCommit, TrevmState>
440440
}
441441
}
442442

443-
// --- ALL STATES, WITH STATE<DB>
443+
// --- ALL STATES, WITH State<Db> or ConcurrentState<Db>
444444

445445
impl<Ext, Db: Database + DatabaseCommit, TrevmState> Trevm<'_, Ext, State<Db>, TrevmState> {
446446
/// Set the [EIP-161] state clear flag, activated in the Spurious Dragon
@@ -450,6 +450,14 @@ impl<Ext, Db: Database + DatabaseCommit, TrevmState> Trevm<'_, Ext, State<Db>, T
450450
}
451451
}
452452

453+
impl<Ext, Db: DatabaseRef, TrevmState> Trevm<'_, Ext, ConcurrentState<Db>, TrevmState> {
454+
/// Set the [EIP-161] state clear flag, activated in the Spurious Dragon
455+
/// hardfork.
456+
pub fn set_state_clear_flag(&mut self, flag: bool) {
457+
self.inner.db_mut().set_state_clear_flag(flag)
458+
}
459+
}
460+
453461
// --- NEEDS CFG
454462

455463
impl<'a, Ext, Db: Database + DatabaseCommit> EvmNeedsCfg<'a, Ext, Db> {
@@ -878,7 +886,7 @@ impl<'a, Ext, Db: Database + DatabaseCommit, TrevmState: HasBlock> Trevm<'a, Ext
878886
}
879887
}
880888

881-
// --- Needs Block with State<Db>
889+
// --- Needs Block with State<Db> or ConcurrentState<Db>
882890

883891
impl< Ext, Db: Database> EvmNeedsBlock<'_, Ext, State<Db>> {
884892
/// Finish execution and return the outputs.
@@ -897,6 +905,23 @@ impl< Ext, Db: Database> EvmNeedsBlock<'_, Ext, State<Db>> {
897905
}
898906
}
899907

908+
impl<'a, Ext, Db: DatabaseRef> EvmNeedsBlock<'a, Ext, ConcurrentState<Db>> {
909+
/// Finish execution and return the outputs.
910+
///
911+
/// ## Panics
912+
///
913+
/// If the State has not been built with StateBuilder::with_bundle_update.
914+
///
915+
/// See [`State::merge_transitions`] and [`State::take_bundle`].
916+
pub fn finish(self) -> BundleState {
917+
let Self { inner: mut evm, .. } = self;
918+
evm.db_mut().merge_transitions(BundleRetention::Reverts);
919+
let bundle = evm.db_mut().take_bundle();
920+
921+
bundle
922+
}
923+
}
924+
900925
// --- NEEDS TX
901926

902927
impl<'a, Ext, Db: Database + DatabaseCommit> EvmNeedsTx<'a, Ext, Db> {

0 commit comments

Comments
 (0)