Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix new version of hardhat call eth_estimateGas fail #3257

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions app/rpc/namespaces/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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")
}
Expand Down Expand Up @@ -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
}
Expand Down
Loading