@@ -10,13 +10,13 @@ use ethportal_api::types::state_trie::account_state::AccountState;
1010use hashbrown:: { HashMap as BrownHashMap , HashSet } ;
1111use parking_lot:: Mutex ;
1212use prometheus_exporter:: prometheus:: HistogramTimer ;
13+ use redb:: { Database as ReDB , Table , TableDefinition } ;
1314use revm:: {
1415 database:: { states:: PlainStorageChangeset , BundleState , OriginalValuesKnown } ,
1516 state:: { AccountInfo , Bytecode } ,
1617 Database , DatabaseRef ,
1718} ;
1819use revm_primitives:: KECCAK_EMPTY ;
19- use redb:: { Database as ReDB , Table , TableDefinition } ;
2020use tracing:: info;
2121
2222use super :: { account_db:: AccountDB , execution_position:: ExecutionPosition , trie_db:: TrieReDB } ;
@@ -53,15 +53,15 @@ pub struct EvmDB {
5353 pub db : Arc < ReDB > ,
5454 /// To get proofs and to verify trie state.
5555 pub trie : Arc < Mutex < EthTrie < TrieReDB > > > ,
56- }
56+ }
5757
5858impl EvmDB {
5959 pub fn new (
6060 config : StateConfig ,
6161 db : Arc < ReDB > ,
6262 execution_position : & ExecutionPosition ,
6363 ) -> anyhow:: Result < Self > {
64- // Initialize empty byte code in the database
64+ // Initialize empty byte code in the database
6565 let txn = db. begin_write ( ) ?;
6666 {
6767 let mut contracts_table = txn. open_table ( CONTRACTS_TABLE ) ?;
@@ -70,7 +70,7 @@ impl EvmDB {
7070 contracts_table. insert ( B256 :: ZERO . as_slice ( ) , empty_bytecode. as_ref ( ) ) ?;
7171 }
7272 txn. commit ( ) ?;
73-
73+
7474 // db.put(KECCAK_EMPTY, Bytecode::new().bytes().as_ref())?;
7575 // db.put(B256::ZERO, Bytecode::new().bytes().as_ref())?;
7676
@@ -100,7 +100,9 @@ impl EvmDB {
100100 let mut trie_diff = BrownHashMap :: new ( ) ;
101101
102102 let txn = self . db . begin_read ( ) . expect ( "Redb read transaction failed" ) ;
103- let storage_table = txn. open_table ( STORAGE_TABLE ) . expect ( "Failed to open Redb storage table" ) ;
103+ let storage_table = txn
104+ . open_table ( STORAGE_TABLE )
105+ . expect ( "Failed to open Redb storage table" ) ;
104106
105107 for key in self
106108 . storage_cache
@@ -213,7 +215,10 @@ impl EvmDB {
213215 let txn = self . db . begin_write ( ) ?;
214216 {
215217 let mut table = txn. open_table ( ACCOUNTS_TABLE ) ?;
216- table. insert ( address_hash. as_slice ( ) , alloy:: rlp:: encode ( & account_state) . as_slice ( ) ) ?;
218+ table. insert (
219+ address_hash. as_slice ( ) ,
220+ alloy:: rlp:: encode ( & account_state) . as_slice ( ) ,
221+ ) ?;
217222 }
218223 txn. commit ( ) ?;
219224
@@ -291,7 +296,10 @@ impl EvmDB {
291296 let txn = self . db . begin_write ( ) ?;
292297 {
293298 let mut table = txn. open_table ( ACCOUNTS_TABLE ) ?;
294- table. insert ( address_hash. as_slice ( ) , alloy:: rlp:: encode ( & account_state) . as_slice ( ) ) ?;
299+ table. insert (
300+ address_hash. as_slice ( ) ,
301+ alloy:: rlp:: encode ( & account_state) . as_slice ( ) ,
302+ ) ?;
295303 }
296304 txn. commit ( ) ?;
297305 stop_timer ( timer) ;
@@ -355,10 +363,12 @@ impl EvmDB {
355363 let txn = self . db . begin_write ( ) ?;
356364 {
357365 let mut table = txn. open_table ( CONTRACTS_TABLE ) ?;
358- table. insert ( hash. as_slice ( ) , bytecode. original_bytes ( ) . as_ref ( ) ) . expect ( "Inserting contract code should never fail" ) ;
366+ table
367+ . insert ( hash. as_slice ( ) , bytecode. original_bytes ( ) . as_ref ( ) )
368+ . expect ( "Inserting contract code should never fail" ) ;
359369 }
360370 txn. commit ( ) ?;
361-
371+
362372 stop_timer ( timer) ;
363373 }
364374 stop_timer ( timer) ;
@@ -431,7 +441,7 @@ impl DatabaseRef for EvmDB {
431441 let result = match table. get ( code_hash. as_slice ( ) ) {
432442 Ok ( Some ( value) ) => Ok ( Bytecode :: new_raw ( value. value ( ) . to_vec ( ) . into ( ) ) ) ,
433443 Ok ( None ) => Err ( Self :: Error :: NotFound ( "code_by_hash" . to_string ( ) ) ) ,
434- Err ( e) => Err ( Self :: Error :: DB ( e. into ( ) ) ) ,
444+ Err ( e) => Err ( Self :: Error :: DB ( Box :: new ( e. into ( ) ) ) ) ,
435445 } ;
436446 stop_timer ( timer) ;
437447 result
@@ -470,7 +480,7 @@ impl DatabaseRef for EvmDB {
470480 let result = match table. get ( key. as_slice ( ) ) {
471481 Ok ( Some ( value) ) => Ok ( B256 :: from_slice ( value. value ( ) ) ) ,
472482 Ok ( None ) => Err ( Self :: Error :: NotFound ( "block_hash" . to_string ( ) ) ) ,
473- Err ( e) => Err ( Self :: Error :: DB ( e. into ( ) ) ) ,
483+ Err ( e) => Err ( Self :: Error :: DB ( Box :: new ( e. into ( ) ) ) ) ,
474484 } ;
475485
476486 stop_timer ( timer) ;
0 commit comments