@@ -6,8 +6,8 @@ use self::error::StoreError;
6
6
use bytes:: Bytes ;
7
7
use engines:: api:: StoreEngine ;
8
8
use ethereum_rust_core:: types:: {
9
- Account , AccountInfo , Block , BlockBody , BlockHash , BlockHeader , BlockNumber , Genesis , Index ,
10
- Receipt , Transaction ,
9
+ Account , AccountInfo , Block , BlockBody , BlockHash , BlockHeader , BlockNumber , ChainConfig ,
10
+ Genesis , Index , Receipt , Transaction ,
11
11
} ;
12
12
use ethereum_types:: { Address , H256 , U256 } ;
13
13
use std:: fmt:: Debug ;
@@ -246,8 +246,8 @@ impl Store {
246
246
self . add_account ( address, account. into ( ) ) ?;
247
247
}
248
248
249
- // Store chain info
250
- self . update_chain_id ( genesis. config . chain_id )
249
+ // Set chain config
250
+ self . set_chain_config ( & genesis. config )
251
251
}
252
252
253
253
pub fn get_transaction_by_hash (
@@ -298,14 +298,18 @@ impl Store {
298
298
. increment_balance ( address, amount)
299
299
}
300
300
301
- pub fn update_chain_id ( & self , chain_id : U256 ) -> Result < ( ) , StoreError > {
302
- self . engine . lock ( ) . unwrap ( ) . update_chain_id ( chain_id )
301
+ pub fn set_chain_config ( & self , chain_config : & ChainConfig ) -> Result < ( ) , StoreError > {
302
+ self . engine . lock ( ) . unwrap ( ) . set_chain_config ( chain_config )
303
303
}
304
304
305
305
pub fn get_chain_id ( & self ) -> Result < Option < U256 > , StoreError > {
306
306
self . engine . lock ( ) . unwrap ( ) . get_chain_id ( )
307
307
}
308
308
309
+ pub fn get_cancun_time ( & self ) -> Result < Option < u64 > , StoreError > {
310
+ self . engine . lock ( ) . unwrap ( ) . get_cancun_time ( )
311
+ }
312
+
309
313
pub fn update_earliest_block_number (
310
314
& self ,
311
315
block_number : BlockNumber ,
@@ -409,7 +413,8 @@ mod tests {
409
413
test_store_account_storage ( store. clone ( ) ) ;
410
414
test_remove_account_storage ( store. clone ( ) ) ;
411
415
test_increment_balance ( store. clone ( ) ) ;
412
- test_store_chain_data ( store. clone ( ) ) ;
416
+ test_store_chain_config ( store. clone ( ) ) ;
417
+ test_store_block_tags ( store. clone ( ) ) ;
413
418
}
414
419
415
420
fn test_store_account ( store : Store ) {
@@ -661,15 +666,30 @@ mod tests {
661
666
assert_eq ! ( stored_account_info. balance, 75 . into( ) ) ;
662
667
}
663
668
664
- fn test_store_chain_data ( store : Store ) {
669
+ fn test_store_chain_config ( store : Store ) {
665
670
let chain_id = U256 :: from_dec_str ( "46" ) . unwrap ( ) ;
671
+ let cancun_time = 12 ;
672
+ let chain_config = ChainConfig {
673
+ chain_id,
674
+ cancun_time : Some ( cancun_time) ,
675
+ ..Default :: default ( )
676
+ } ;
677
+
678
+ store. set_chain_config ( & chain_config) . unwrap ( ) ;
679
+
680
+ let stored_chain_id = store. get_chain_id ( ) . unwrap ( ) . unwrap ( ) ;
681
+ let stored_cancun_time = store. get_cancun_time ( ) . unwrap ( ) . unwrap ( ) ;
682
+
683
+ assert_eq ! ( chain_id, stored_chain_id) ;
684
+ assert_eq ! ( cancun_time, stored_cancun_time) ;
685
+ }
686
+ fn test_store_block_tags ( store : Store ) {
666
687
let earliest_block_number = 0 ;
667
688
let finalized_block_number = 7 ;
668
689
let safe_block_number = 6 ;
669
690
let latest_block_number = 8 ;
670
691
let pending_block_number = 9 ;
671
692
672
- store. update_chain_id ( chain_id) . unwrap ( ) ;
673
693
store
674
694
. update_earliest_block_number ( earliest_block_number)
675
695
. unwrap ( ) ;
@@ -684,14 +704,12 @@ mod tests {
684
704
. update_pending_block_number ( pending_block_number)
685
705
. unwrap ( ) ;
686
706
687
- let stored_chain_id = store. get_chain_id ( ) . unwrap ( ) . unwrap ( ) ;
688
707
let stored_earliest_block_number = store. get_earliest_block_number ( ) . unwrap ( ) . unwrap ( ) ;
689
708
let stored_finalized_block_number = store. get_finalized_block_number ( ) . unwrap ( ) . unwrap ( ) ;
690
709
let stored_safe_block_number = store. get_safe_block_number ( ) . unwrap ( ) . unwrap ( ) ;
691
710
let stored_latest_block_number = store. get_latest_block_number ( ) . unwrap ( ) . unwrap ( ) ;
692
711
let stored_pending_block_number = store. get_pending_block_number ( ) . unwrap ( ) . unwrap ( ) ;
693
712
694
- assert_eq ! ( chain_id, stored_chain_id) ;
695
713
assert_eq ! ( earliest_block_number, stored_earliest_block_number) ;
696
714
assert_eq ! ( finalized_block_number, stored_finalized_block_number) ;
697
715
assert_eq ! ( safe_block_number, stored_safe_block_number) ;
0 commit comments