@@ -775,18 +775,30 @@ impl EthApi {
775775 node_info ! ( "eth_getAccountInfo" ) ;
776776
777777 if let Some ( fork) = self . get_fork ( ) {
778+ let block_request = self . block_request ( block_number) . await ?;
778779 // check if the number predates the fork, if in fork mode
779- if let BlockRequest :: Number ( number) = self . block_request ( block_number) . await ?
780- && fork. predates_fork_inclusive ( number)
781- {
782- // if this predates the fork we need to fetch balance, nonce, code individually
783- // because the provider might not support this endpoint
784- let balance = fork. get_balance ( address, number) . map_err ( BlockchainError :: from) ;
785- let code = fork. get_code ( address, number) . map_err ( BlockchainError :: from) ;
786- let nonce = self . get_transaction_count ( address, Some ( number. into ( ) ) ) ;
787- let ( balance, code, nonce) = try_join ! ( balance, code, nonce) ?;
788-
789- return Ok ( alloy_rpc_types:: eth:: AccountInfo { balance, nonce, code } ) ;
780+ if let BlockRequest :: Number ( number) = block_request {
781+ trace ! ( target: "node" , "get_account_info: fork block {}, requested block {number}" , fork. block_number( ) ) ;
782+ return if fork. predates_fork ( number) {
783+ // if this predates the fork we need to fetch balance, nonce, code individually
784+ // because the provider might not support this endpoint
785+ let balance = fork. get_balance ( address, number) . map_err ( BlockchainError :: from) ;
786+ let code = fork. get_code ( address, number) . map_err ( BlockchainError :: from) ;
787+ let nonce = self . get_transaction_count ( address, Some ( number. into ( ) ) ) ;
788+ let ( balance, code, nonce) = try_join ! ( balance, code, nonce) ?;
789+
790+ Ok ( alloy_rpc_types:: eth:: AccountInfo { balance, nonce, code } )
791+ } else {
792+ // Anvil node is at the same block or higher than the fork block,
793+ // return account info from backend to reflect current state.
794+ let account_info = self . backend . get_account ( address) . await ?;
795+ let code = self . backend . get_code ( address, Some ( block_request) ) . await ?;
796+ Ok ( alloy_rpc_types:: eth:: AccountInfo {
797+ balance : account_info. balance ,
798+ nonce : account_info. nonce ,
799+ code,
800+ } )
801+ } ;
790802 }
791803 }
792804
0 commit comments