@@ -25,18 +25,18 @@ use revm::{
2525use std:: { collections:: BTreeMap , sync:: Arc } ;
2626use tracing:: info;
2727
28- /// The database for [STF ].
29- type STFDB = CacheDB < EmptyDBTyped < ProviderError > > ;
28+ /// The database for [StateTransition ].
29+ type StfDb = CacheDB < EmptyDBTyped < ProviderError > > ;
3030
3131/// The execution fixture generator for `opt8n`.
32- pub ( crate ) struct STF {
32+ pub ( crate ) struct StateTransition {
3333 /// Inner cache database.
34- pub ( crate ) db : STFDB ,
34+ pub ( crate ) db : StfDb ,
3535 /// The [ChainSpec] for the devnet chain.
3636 pub ( crate ) chain_spec : Arc < ChainSpec > ,
3737}
3838
39- impl STF {
39+ impl StateTransition {
4040 /// Create a new execution fixture generator.
4141 pub ( crate ) fn new ( genesis : Genesis , state_dump : DumpBlockResponse ) -> Result < Self > {
4242 let mut db = CacheDB :: default ( ) ;
@@ -59,7 +59,7 @@ impl STF {
5959 . storage
6060 . as_ref ( )
6161 . unwrap_or ( & BTreeMap :: new ( ) )
62- . into_iter ( )
62+ . iter ( )
6363 . map ( |( k, v) | ( ( * k) . into ( ) , ( * v) . into ( ) ) )
6464 . collect ( ) ,
6565 account_state : AccountState :: None ,
@@ -79,11 +79,7 @@ impl STF {
7979 } ;
8080 db. insert_contract ( & mut info) ;
8181
82- let entry = db
83- . accounts
84- . entry ( * k)
85- . or_insert_with ( || DbAccount :: default ( ) ) ;
86-
82+ let entry = db. accounts . entry ( * k) . or_default ( ) ;
8783 entry. info = info;
8884 if let Some ( storage) = & account. storage {
8985 storage. iter ( ) . for_each ( |( k, v) | {
@@ -99,7 +95,7 @@ impl STF {
9995 }
10096
10197 /// Grab the block executor with the current state.
102- pub ( crate ) fn executor ( & mut self ) -> OpBlockExecutor < OptimismEvmConfig , STFDB > {
98+ pub ( crate ) fn executor ( & mut self ) -> OpBlockExecutor < OptimismEvmConfig , StfDb > {
10399 // Construct an ephemeral state with the current database.
104100 let state = State :: builder ( )
105101 . with_database ( self . db . clone ( ) )
@@ -178,11 +174,7 @@ impl STF {
178174 let mut info = account. info . clone ( ) . unwrap_or_default ( ) ;
179175 self . db . insert_contract ( & mut info) ;
180176
181- let db_account = self
182- . db
183- . accounts
184- . entry ( * address)
185- . or_insert_with ( || DbAccount :: default ( ) ) ;
177+ let db_account = self . db . accounts . entry ( * address) . or_default ( ) ;
186178 if account. is_info_changed ( ) {
187179 db_account. info = info;
188180 }
@@ -225,7 +217,12 @@ impl STF {
225217 current_number : U256 :: from ( header. number ) ,
226218 current_timestamp : U256 :: from ( header. timestamp ) ,
227219 parent_beacon_block_root : header. parent_beacon_block_root ,
228- block_hashes : Default :: default ( ) ,
220+ block_hashes : Some (
221+ [ ( U256 :: from ( header. number - 1 ) , header. parent_hash ) ]
222+ . iter ( )
223+ . cloned ( )
224+ . collect :: < HashMap < _ , _ > > ( ) ,
225+ ) ,
229226 } ,
230227 transactions : encoded_txs,
231228 result : ExecutionResult {
@@ -281,11 +278,10 @@ impl STF {
281278 . code
282279 . as_ref ( )
283280 . map ( |code| match code {
284- Bytecode :: LegacyRaw ( code) => Some ( keccak256 ( code) ) ,
285- Bytecode :: LegacyAnalyzed ( code) => Some ( keccak256 ( code. bytecode ( ) ) ) ,
281+ Bytecode :: LegacyRaw ( code) => keccak256 ( code) ,
282+ Bytecode :: LegacyAnalyzed ( code) => keccak256 ( code. bytecode ( ) ) ,
286283 _ => panic ! ( "Unsupported bytecode type" ) ,
287284 } )
288- . flatten ( )
289285 . unwrap_or ( KECCAK_EMPTY ) ,
290286 } ;
291287
@@ -313,8 +309,8 @@ impl STF {
313309 Ok ( hb. root ( ) )
314310 }
315311
316- /// Transforms a [STFDB ] into a map of [Address]es to [GenesisAccount]s.
317- fn gen_allocs ( db : STFDB ) -> HashMap < Address , GenesisAccount > {
312+ /// Transforms a [StfDb ] into a map of [Address]es to [GenesisAccount]s.
313+ fn gen_allocs ( db : StfDb ) -> HashMap < Address , GenesisAccount > {
318314 db. accounts
319315 . iter ( )
320316 . map ( |( address, account) | {
0 commit comments