@@ -1877,25 +1877,31 @@ fn merge_db_account_data<ExtDB: DatabaseRef>(
1877
1877
) {
1878
1878
trace ! ( ?addr, "merging database data" ) ;
1879
1879
1880
- let mut acc = if let Some ( acc) = active. accounts . get ( & addr) . cloned ( ) {
1881
- acc
1882
- } else {
1883
- // Account does not exist
1884
- return ;
1885
- } ;
1886
-
1887
- if let Some ( code) = active. contracts . get ( & acc. info . code_hash ) . cloned ( ) {
1888
- fork_db. contracts . insert ( acc. info . code_hash , code) ;
1889
- }
1890
-
1891
- if let Some ( fork_account) = fork_db. accounts . get_mut ( & addr) {
1892
- // This will merge the fork's tracked storage with active storage and update values
1893
- fork_account. storage . extend ( std:: mem:: take ( & mut acc. storage ) ) ;
1894
- // swap them so we can insert the account as whole in the next step
1895
- std:: mem:: swap ( & mut fork_account. storage , & mut acc. storage ) ;
1880
+ let Some ( acc) = active. accounts . get ( & addr) else { return } ;
1881
+
1882
+ // port contract cache over
1883
+ if let Some ( code) = active. contracts . get ( & acc. info . code_hash ) {
1884
+ trace ! ( "merging contract cache" ) ;
1885
+ fork_db. contracts . insert ( acc. info . code_hash , code. clone ( ) ) ;
1886
+ }
1887
+
1888
+ // port account storage over
1889
+ use std:: collections:: hash_map:: Entry ;
1890
+ match fork_db. accounts . entry ( addr) {
1891
+ Entry :: Vacant ( vacant) => {
1892
+ trace ! ( "target account not present - inserting from active" ) ;
1893
+ // if the fork_db doesn't have the target account
1894
+ // insert the entire thing
1895
+ vacant. insert ( acc. clone ( ) ) ;
1896
+ }
1897
+ Entry :: Occupied ( mut occupied) => {
1898
+ trace ! ( "target account present - merging storage slots" ) ;
1899
+ // if the fork_db does have the system,
1900
+ // extend the existing storage (overriding)
1901
+ let fork_account = occupied. get_mut ( ) ;
1902
+ fork_account. storage . extend ( & acc. storage ) ;
1903
+ }
1896
1904
}
1897
-
1898
- fork_db. accounts . insert ( addr, acc) ;
1899
1905
}
1900
1906
1901
1907
/// Returns true of the address is a contract
0 commit comments