Skip to content

Commit

Permalink
Merge PR: optimize performance of the func eth_call (#793)
Browse files Browse the repository at this point in the history
Co-authored-by: Zhong Qiu <[email protected]>
  • Loading branch information
KamiD and zhongqiuwood authored Apr 6, 2021
1 parent 3e50c81 commit b195921
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions app/rpc/namespaces/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ func (api *PublicEthereumAPI) SendRawTransaction(data hexutil.Bytes) (common.Has
// Call performs a raw contract call.
func (api *PublicEthereumAPI) Call(args rpctypes.CallArgs, blockNr rpctypes.BlockNumber, _ *map[common.Address]rpctypes.Account) (hexutil.Bytes, error) {
api.logger.Debug("eth_call", "args", args, "block number", blockNr)
simRes, err := api.doCall(args, blockNr, big.NewInt(ethermint.DefaultRPCGasLimit))
simRes, err := api.doCall(args, blockNr, big.NewInt(ethermint.DefaultRPCGasLimit), false)
if err != nil {
return []byte{}, TransformDataError(err, "eth_call")
}
Expand All @@ -543,7 +543,7 @@ func (api *PublicEthereumAPI) Call(args rpctypes.CallArgs, blockNr rpctypes.Bloc
// DoCall performs a simulated call operation through the evmtypes. It returns the
// estimated gas used on the operation or an error if fails.
func (api *PublicEthereumAPI) doCall(
args rpctypes.CallArgs, blockNum rpctypes.BlockNumber, globalGasCap *big.Int,
args rpctypes.CallArgs, blockNum rpctypes.BlockNumber, globalGasCap *big.Int, isEstimate bool,
) (*sdk.SimulationResponse, error) {

clientCtx := api.clientCtx
Expand All @@ -564,7 +564,11 @@ func (api *PublicEthereumAPI) doCall(
addr = *args.From
}

nonce, _ := api.accountNonce(api.clientCtx, addr, true)
nonce := uint64(0)
if isEstimate && args.To == nil && args.Data != nil {
//only get real nonce when estimate gas and the action is contract deploy
nonce, _ = api.accountNonce(api.clientCtx, addr, true)
}

// Set default gas & gas price if none were set
// Change this to uint64(math.MaxUint64 / 2) if gas cap can be configured
Expand Down Expand Up @@ -650,7 +654,7 @@ func (api *PublicEthereumAPI) doCall(
// param from the SDK.
func (api *PublicEthereumAPI) EstimateGas(args rpctypes.CallArgs) (hexutil.Uint64, error) {
api.logger.Debug("eth_estimateGas", "args", args)
simResponse, err := api.doCall(args, 0, big.NewInt(ethermint.DefaultRPCGasLimit))
simResponse, err := api.doCall(args, 0, big.NewInt(ethermint.DefaultRPCGasLimit), true)
if err != nil {
return 0, TransformDataError(err, "eth_estimateGas")
}
Expand Down
2 changes: 1 addition & 1 deletion app/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ const (
// DefaultGasPrice is default gas price for evm transactions
DefaultGasPrice = 20
// DefaultRPCGasLimit is default gas limit for RPC call operations
DefaultRPCGasLimit = 100000000000
DefaultRPCGasLimit = 30000000
)

0 comments on commit b195921

Please sign in to comment.