diff --git a/app/rpc/namespaces/eth/api.go b/app/rpc/namespaces/eth/api.go index c2b401dae5..6158a24800 100644 --- a/app/rpc/namespaces/eth/api.go +++ b/app/rpc/namespaces/eth/api.go @@ -1063,13 +1063,13 @@ func (api *PublicEthereumAPI) doCall( return &simResponse, nil } -func (api *PublicEthereumAPI) simDoCall(args rpctypes.CallArgs, cap uint64) (uint64, error) { +func (api *PublicEthereumAPI) simDoCall(args rpctypes.CallArgs, cap uint64, blockNum rpctypes.BlockNumber) (uint64, error) { // Create a helper to check if a gas allowance results in an executable transaction executable := func(gas uint64) (*sdk.SimulationResponse, error) { if gas != 0 { args.Gas = (*hexutil.Uint64)(&gas) } - return api.doCall(args, 0, big.NewInt(int64(cap)), true, nil) + return api.doCall(args, blockNum, big.NewInt(int64(cap)), true, nil) } // get exact gas limit @@ -1112,7 +1112,7 @@ func (api *PublicEthereumAPI) simDoCall(args rpctypes.CallArgs, cap uint64) (uin } // EstimateGas returns an estimate of gas usage for the given smart contract call. -func (api *PublicEthereumAPI) EstimateGas(args rpctypes.CallArgs) (hexutil.Uint64, error) { +func (api *PublicEthereumAPI) EstimateGas(args rpctypes.CallArgs, blockNrOrHash *rpctypes.BlockNumberOrHash) (hexutil.Uint64, error) { monitor := monitor.GetMonitor("eth_estimateGas", api.logger, api.Metrics).OnBegin() defer monitor.OnEnd("args", args) @@ -1127,7 +1127,15 @@ func (api *PublicEthereumAPI) EstimateGas(args rpctypes.CallArgs) (hexutil.Uint6 args.GasPrice = api.gasPrice } - estimatedGas, err := api.simDoCall(args, maxGasLimitPerTx) + blockNr := rpctypes.LatestBlockNumber + if blockNrOrHash != nil { + blockNr, err = api.backend.ConvertToBlockNumber(*blockNrOrHash) + if err != nil { + return 0, TransformDataError(err, "eth_estimateGas") + } + } + + estimatedGas, err := api.simDoCall(args, maxGasLimitPerTx, blockNr) if err != nil { return 0, TransformDataError(err, "eth_estimateGas") } @@ -1667,7 +1675,7 @@ func (api *PublicEthereumAPI) generateFromArgs(args rpctypes.SendTxArgs) (*evmty Value: args.Value, Data: &input, } - gl, err := api.EstimateGas(callArgs) + gl, err := api.EstimateGas(callArgs, nil) if err != nil { return nil, err }