@@ -10,13 +10,13 @@ use ethportal_api::types::state_trie::account_state::AccountState;
10
10
use hashbrown:: { HashMap as BrownHashMap , HashSet } ;
11
11
use parking_lot:: Mutex ;
12
12
use prometheus_exporter:: prometheus:: HistogramTimer ;
13
+ use redb:: { Database as ReDB , Table , TableDefinition } ;
13
14
use revm:: {
14
15
database:: { states:: PlainStorageChangeset , BundleState , OriginalValuesKnown } ,
15
16
state:: { AccountInfo , Bytecode } ,
16
17
Database , DatabaseRef ,
17
18
} ;
18
19
use revm_primitives:: KECCAK_EMPTY ;
19
- use redb:: { Database as ReDB , Table , TableDefinition } ;
20
20
use tracing:: info;
21
21
22
22
use super :: { account_db:: AccountDB , execution_position:: ExecutionPosition , trie_db:: TrieReDB } ;
@@ -53,15 +53,15 @@ pub struct EvmDB {
53
53
pub db : Arc < ReDB > ,
54
54
/// To get proofs and to verify trie state.
55
55
pub trie : Arc < Mutex < EthTrie < TrieReDB > > > ,
56
- }
56
+ }
57
57
58
58
impl EvmDB {
59
59
pub fn new (
60
60
config : StateConfig ,
61
61
db : Arc < ReDB > ,
62
62
execution_position : & ExecutionPosition ,
63
63
) -> anyhow:: Result < Self > {
64
- // Initialize empty byte code in the database
64
+ // Initialize empty byte code in the database
65
65
let txn = db. begin_write ( ) ?;
66
66
{
67
67
let mut contracts_table = txn. open_table ( CONTRACTS_TABLE ) ?;
@@ -70,7 +70,7 @@ impl EvmDB {
70
70
contracts_table. insert ( B256 :: ZERO . as_slice ( ) , empty_bytecode. as_ref ( ) ) ?;
71
71
}
72
72
txn. commit ( ) ?;
73
-
73
+
74
74
// db.put(KECCAK_EMPTY, Bytecode::new().bytes().as_ref())?;
75
75
// db.put(B256::ZERO, Bytecode::new().bytes().as_ref())?;
76
76
@@ -100,7 +100,9 @@ impl EvmDB {
100
100
let mut trie_diff = BrownHashMap :: new ( ) ;
101
101
102
102
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" ) ;
104
106
105
107
for key in self
106
108
. storage_cache
@@ -213,7 +215,10 @@ impl EvmDB {
213
215
let txn = self . db . begin_write ( ) ?;
214
216
{
215
217
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
+ ) ?;
217
222
}
218
223
txn. commit ( ) ?;
219
224
@@ -291,7 +296,10 @@ impl EvmDB {
291
296
let txn = self . db . begin_write ( ) ?;
292
297
{
293
298
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
+ ) ?;
295
303
}
296
304
txn. commit ( ) ?;
297
305
stop_timer ( timer) ;
@@ -355,10 +363,12 @@ impl EvmDB {
355
363
let txn = self . db . begin_write ( ) ?;
356
364
{
357
365
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" ) ;
359
369
}
360
370
txn. commit ( ) ?;
361
-
371
+
362
372
stop_timer ( timer) ;
363
373
}
364
374
stop_timer ( timer) ;
@@ -431,7 +441,7 @@ impl DatabaseRef for EvmDB {
431
441
let result = match table. get ( code_hash. as_slice ( ) ) {
432
442
Ok ( Some ( value) ) => Ok ( Bytecode :: new_raw ( value. value ( ) . to_vec ( ) . into ( ) ) ) ,
433
443
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 ( ) ) ) ) ,
435
445
} ;
436
446
stop_timer ( timer) ;
437
447
result
@@ -470,7 +480,7 @@ impl DatabaseRef for EvmDB {
470
480
let result = match table. get ( key. as_slice ( ) ) {
471
481
Ok ( Some ( value) ) => Ok ( B256 :: from_slice ( value. value ( ) ) ) ,
472
482
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 ( ) ) ) ) ,
474
484
} ;
475
485
476
486
stop_timer ( timer) ;
0 commit comments