1
1
use super :: {
2
- backend:: mem:: { state, BlockRequest , State } ,
2
+ backend:: {
3
+ db:: MaybeFullDatabase ,
4
+ mem:: { state, BlockRequest , State } ,
5
+ } ,
3
6
sign:: build_typed_transaction,
4
7
} ;
5
8
use crate :: {
@@ -54,7 +57,7 @@ use alloy_rpc_types::{
54
57
} ,
55
58
request:: TransactionRequest ,
56
59
simulate:: { SimulatePayload , SimulatedBlock } ,
57
- state:: StateOverride ,
60
+ state:: EvmOverrides ,
58
61
trace:: {
59
62
filter:: TraceFilter ,
60
63
geth:: { GethDebugTracingCallOptions , GethDebugTracingOptions , GethTrace } ,
@@ -84,7 +87,7 @@ use foundry_evm::{
84
87
backend:: DatabaseError ,
85
88
decode:: RevertDecoder ,
86
89
revm:: {
87
- db:: DatabaseRef ,
90
+ db:: { CacheDB , DatabaseRef } ,
88
91
interpreter:: { return_ok, return_revert, InstructionResult } ,
89
92
primitives:: BlockEnv ,
90
93
} ,
@@ -247,18 +250,20 @@ impl EthApi {
247
250
EthRequest :: EthSendRawTransaction ( tx) => {
248
251
self . send_raw_transaction ( tx) . await . to_rpc_result ( )
249
252
}
250
- EthRequest :: EthCall ( call, block, overrides) => {
251
- self . call ( call, block, overrides) . await . to_rpc_result ( )
252
- }
253
+ EthRequest :: EthCall ( call, block, state_override, block_overrides) => self
254
+ . call ( call, block, EvmOverrides :: new ( state_override, block_overrides) )
255
+ . await
256
+ . to_rpc_result ( ) ,
253
257
EthRequest :: EthSimulateV1 ( simulation, block) => {
254
258
self . simulate_v1 ( simulation, block) . await . to_rpc_result ( )
255
259
}
256
260
EthRequest :: EthCreateAccessList ( call, block) => {
257
261
self . create_access_list ( call, block) . await . to_rpc_result ( )
258
262
}
259
- EthRequest :: EthEstimateGas ( call, block, overrides) => {
260
- self . estimate_gas ( call, block, overrides) . await . to_rpc_result ( )
261
- }
263
+ EthRequest :: EthEstimateGas ( call, block, state_override, block_overrides) => self
264
+ . estimate_gas ( call, block, EvmOverrides :: new ( state_override, block_overrides) )
265
+ . await
266
+ . to_rpc_result ( ) ,
262
267
EthRequest :: EthGetRawTransactionByHash ( hash) => {
263
268
self . raw_transaction ( hash) . await . to_rpc_result ( )
264
269
}
@@ -969,7 +974,8 @@ impl EthApi {
969
974
970
975
if request. gas . is_none ( ) {
971
976
// estimate if not provided
972
- if let Ok ( gas) = self . estimate_gas ( request. clone ( ) , None , None ) . await {
977
+ if let Ok ( gas) = self . estimate_gas ( request. clone ( ) , None , EvmOverrides :: default ( ) ) . await
978
+ {
973
979
request. gas = Some ( gas. to ( ) ) ;
974
980
}
975
981
}
@@ -996,7 +1002,8 @@ impl EthApi {
996
1002
997
1003
if request. gas . is_none ( ) {
998
1004
// estimate if not provided
999
- if let Ok ( gas) = self . estimate_gas ( request. clone ( ) , None , None ) . await {
1005
+ if let Ok ( gas) = self . estimate_gas ( request. clone ( ) , None , EvmOverrides :: default ( ) ) . await
1006
+ {
1000
1007
request. gas = Some ( gas. to ( ) ) ;
1001
1008
}
1002
1009
}
@@ -1070,16 +1077,16 @@ impl EthApi {
1070
1077
& self ,
1071
1078
request : WithOtherFields < TransactionRequest > ,
1072
1079
block_number : Option < BlockId > ,
1073
- overrides : Option < StateOverride > ,
1080
+ overrides : EvmOverrides ,
1074
1081
) -> Result < Bytes > {
1075
1082
node_info ! ( "eth_call" ) ;
1076
1083
let block_request = self . block_request ( block_number) . await ?;
1077
1084
// check if the number predates the fork, if in fork mode
1078
1085
if let BlockRequest :: Number ( number) = block_request {
1079
1086
if let Some ( fork) = self . get_fork ( ) {
1080
1087
if fork. predates_fork ( number) {
1081
- if overrides. is_some ( ) {
1082
- return Err ( BlockchainError :: StateOverrideError (
1088
+ if overrides. has_state ( ) || overrides . has_block ( ) {
1089
+ return Err ( BlockchainError :: EvmOverrideError (
1083
1090
"not available on past forked blocks" . to_string ( ) ,
1084
1091
) ) ;
1085
1092
}
@@ -1201,7 +1208,7 @@ impl EthApi {
1201
1208
& self ,
1202
1209
request : WithOtherFields < TransactionRequest > ,
1203
1210
block_number : Option < BlockId > ,
1204
- overrides : Option < StateOverride > ,
1211
+ overrides : EvmOverrides ,
1205
1212
) -> Result < U256 > {
1206
1213
node_info ! ( "eth_estimateGas" ) ;
1207
1214
self . do_estimate_gas (
@@ -2082,7 +2089,9 @@ impl EthApi {
2082
2089
2083
2090
// Estimate gas
2084
2091
if tx_req. gas . is_none ( ) {
2085
- if let Ok ( gas) = self . estimate_gas ( tx_req. clone ( ) , None , None ) . await {
2092
+ if let Ok ( gas) =
2093
+ self . estimate_gas ( tx_req. clone ( ) , None , EvmOverrides :: default ( ) ) . await
2094
+ {
2086
2095
tx_req. gas = Some ( gas. to ( ) ) ;
2087
2096
}
2088
2097
}
@@ -2550,7 +2559,8 @@ impl EthApi {
2550
2559
2551
2560
request. from = Some ( from) ;
2552
2561
2553
- let gas_limit_fut = self . estimate_gas ( request. clone ( ) , Some ( BlockId :: latest ( ) ) , None ) ;
2562
+ let gas_limit_fut =
2563
+ self . estimate_gas ( request. clone ( ) , Some ( BlockId :: latest ( ) ) , EvmOverrides :: default ( ) ) ;
2554
2564
2555
2565
let fees_fut = self . fee_history (
2556
2566
U256 :: from ( EIP1559_FEE_ESTIMATION_PAST_BLOCKS ) ,
@@ -2651,15 +2661,15 @@ impl EthApi {
2651
2661
& self ,
2652
2662
request : WithOtherFields < TransactionRequest > ,
2653
2663
block_number : Option < BlockId > ,
2654
- overrides : Option < StateOverride > ,
2664
+ overrides : EvmOverrides ,
2655
2665
) -> Result < u128 > {
2656
2666
let block_request = self . block_request ( block_number) . await ?;
2657
2667
// check if the number predates the fork, if in fork mode
2658
2668
if let BlockRequest :: Number ( number) = block_request {
2659
2669
if let Some ( fork) = self . get_fork ( ) {
2660
2670
if fork. predates_fork ( number) {
2661
- if overrides. is_some ( ) {
2662
- return Err ( BlockchainError :: StateOverrideError (
2671
+ if overrides. has_state ( ) || overrides . has_block ( ) {
2672
+ return Err ( BlockchainError :: EvmOverrideError (
2663
2673
"not available on past forked blocks" . to_string ( ) ,
2664
2674
) ) ;
2665
2675
}
@@ -2672,14 +2682,18 @@ impl EthApi {
2672
2682
// <https://github.com/foundry-rs/foundry/issues/6036>
2673
2683
self . on_blocking_task ( |this| async move {
2674
2684
this. backend
2675
- . with_database_at ( Some ( block_request) , |mut state, block| {
2676
- if let Some ( overrides) = overrides {
2677
- state = Box :: new ( state:: apply_state_override (
2678
- overrides. into_iter ( ) . collect ( ) ,
2679
- state,
2680
- ) ?) ;
2685
+ . with_database_at ( Some ( block_request) , |state, mut block| {
2686
+ let mut cache_db = CacheDB :: new ( state) ;
2687
+ if let Some ( state_overrides) = overrides. state {
2688
+ state:: apply_state_overrides (
2689
+ state_overrides. into_iter ( ) . collect ( ) ,
2690
+ & mut cache_db,
2691
+ ) ?;
2692
+ }
2693
+ if let Some ( block_overrides) = overrides. block {
2694
+ state:: apply_block_overrides ( * block_overrides, & mut cache_db, & mut block) ;
2681
2695
}
2682
- this. do_estimate_gas_with_state ( request, & state , block)
2696
+ this. do_estimate_gas_with_state ( request, cache_db . as_dyn ( ) , block)
2683
2697
} )
2684
2698
. await ?
2685
2699
} )
0 commit comments