@@ -64,7 +64,7 @@ use anvil_core::eth::{
64
64
use anvil_rpc:: error:: RpcError ;
65
65
use flate2:: { read:: GzDecoder , write:: GzEncoder , Compression } ;
66
66
use foundry_evm:: {
67
- backend:: { BackendError , BackendResult , DatabaseError , DatabaseResult , RevertSnapshotAction } ,
67
+ backend:: { DatabaseError , DatabaseResult , RevertSnapshotAction } ,
68
68
constants:: DEFAULT_CREATE2_DEPLOYER_RUNTIME_CODE ,
69
69
decode:: RevertDecoder ,
70
70
inspectors:: AccessListInspector ,
@@ -277,7 +277,7 @@ impl Backend {
277
277
/// Applies the configured genesis settings
278
278
///
279
279
/// This will fund, create the genesis accounts
280
- async fn apply_genesis ( & self ) -> BackendResult < ( ) > {
280
+ async fn apply_genesis ( & self ) -> Result < ( ) , DatabaseError > {
281
281
trace ! ( target: "backend" , "setting genesis balances" ) ;
282
282
283
283
if self . fork . read ( ) . is_some ( ) {
@@ -291,27 +291,18 @@ impl Backend {
291
291
genesis_accounts_futures. push ( tokio:: task:: spawn ( async move {
292
292
let db = db. read ( ) . await ;
293
293
let info = db. basic_ref ( address) ?. unwrap_or_default ( ) ;
294
- Ok :: < _ , BackendError > ( ( address, info) )
294
+ Ok :: < _ , DatabaseError > ( ( address, info) )
295
295
} ) ) ;
296
296
}
297
297
298
298
let genesis_accounts = futures:: future:: join_all ( genesis_accounts_futures) . await ;
299
299
300
300
let mut db = self . db . write ( ) . await ;
301
301
302
- // in fork mode we only set the balance, this way the accountinfo is fetched from the
303
- // remote client, preserving code and nonce. The reason for that is private keys for dev
304
- // accounts are commonly known and are used on testnets
305
- let mut fork_genesis_infos = self . genesis . fork_genesis_account_infos . lock ( ) ;
306
- fork_genesis_infos. clear ( ) ;
307
-
308
302
for res in genesis_accounts {
309
- let ( address, mut info) = res. map_err ( BackendError :: display ) ? ?;
303
+ let ( address, mut info) = res. unwrap ( ) ?;
310
304
info. balance = self . genesis . balance ;
311
305
db. insert_account ( address, info. clone ( ) ) ;
312
-
313
- // store the fetched AccountInfo, so we can cheaply reset in [Self::reset_fork()]
314
- fork_genesis_infos. push ( info) ;
315
306
}
316
307
} else {
317
308
let mut db = self . db . write ( ) . await ;
@@ -459,23 +450,9 @@ impl Backend {
459
450
fork. total_difficulty ( ) ,
460
451
) ;
461
452
self . states . write ( ) . clear ( ) ;
453
+ self . db . write ( ) . await . clear ( ) ;
462
454
463
- // insert back all genesis accounts, by reusing cached `AccountInfo`s we don't need to
464
- // fetch the data via RPC again
465
- let mut db = self . db . write ( ) . await ;
466
-
467
- // clear database
468
- db. clear ( ) ;
469
-
470
- let fork_genesis_infos = self . genesis . fork_genesis_account_infos . lock ( ) ;
471
- for ( address, info) in
472
- self . genesis . accounts . iter ( ) . copied ( ) . zip ( fork_genesis_infos. iter ( ) . cloned ( ) )
473
- {
474
- db. insert_account ( address, info) ;
475
- }
476
-
477
- // reset the genesis.json alloc
478
- self . genesis . apply_genesis_json_alloc ( db) ?;
455
+ self . apply_genesis ( ) . await ?;
479
456
480
457
Ok ( ( ) )
481
458
} else {
0 commit comments