@@ -777,6 +777,13 @@ impl Backend {
777
777
self . inner . precompiles ( ) . contains ( addr)
778
778
}
779
779
780
+ /// Sets the initial journaled state to use when initializing forks
781
+ #[ inline]
782
+ fn set_init_journaled_state ( & mut self , journaled_state : JournaledState ) {
783
+ trace ! ( "recording fork init journaled_state" ) ;
784
+ self . fork_init_journaled_state = journaled_state;
785
+ }
786
+
780
787
/// Cleans up already loaded accounts that would be initialized without the correct data from
781
788
/// the fork.
782
789
///
@@ -800,10 +807,21 @@ impl Backend {
800
807
let mut journaled_state = self . fork_init_journaled_state . clone ( ) ;
801
808
for loaded_account in loaded_accounts. iter ( ) . copied ( ) {
802
809
trace ! ( ?loaded_account, "replacing account on init" ) ;
803
- let fork_account = Database :: basic ( & mut fork. db , loaded_account) ?
804
- . ok_or ( DatabaseError :: MissingAccount ( loaded_account) ) ?;
805
810
let init_account =
806
811
journaled_state. state . get_mut ( & loaded_account) . expect ( "exists; qed" ) ;
812
+
813
+ // here's an edge case where we need to check if this account has been created, in
814
+ // which case we don't need to replace it with the account from the fork because the
815
+ // created account takes precedence: for example contract creation in setups
816
+ if init_account. is_created ( ) {
817
+ trace ! ( ?loaded_account, "skipping created account" ) ;
818
+ continue
819
+ }
820
+
821
+ // otherwise we need to replace the account's info with the one from the fork's
822
+ // database
823
+ let fork_account = Database :: basic ( & mut fork. db , loaded_account) ?
824
+ . ok_or ( DatabaseError :: MissingAccount ( loaded_account) ) ?;
807
825
init_account. info = fork_account;
808
826
}
809
827
fork. journaled_state = journaled_state;
@@ -1043,8 +1061,8 @@ impl DatabaseExt for Backend {
1043
1061
// different forks. Since the `JournaledState` is valid for all forks until the
1044
1062
// first fork is selected, we need to update it for all forks and use it as init state
1045
1063
// for all future forks
1046
- trace ! ( "recording fork init journaled_state" ) ;
1047
- self . fork_init_journaled_state = active_journaled_state. clone ( ) ;
1064
+
1065
+ self . set_init_journaled_state ( active_journaled_state. clone ( ) ) ;
1048
1066
self . prepare_init_journal_state ( ) ?;
1049
1067
1050
1068
// Make sure that the next created fork has a depth of 0.
0 commit comments