Skip to content

Commit

Permalink
Problem: duplicated encoding when passing state overrides (#394)
Browse files Browse the repository at this point in the history
* Problem: duplicated encoding when passing state overrides

use json.RawMessage to avoid decoding json unnesserarily

* optional parameter
  • Loading branch information
yihuang authored Jan 11, 2024
1 parent 2c2d539 commit ddb3035
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
3 changes: 2 additions & 1 deletion rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package backend

import (
"context"
"encoding/json"
"math/big"
"time"

Expand Down Expand Up @@ -128,7 +129,7 @@ type EVMBackend interface {
SendRawTransaction(data hexutil.Bytes) (common.Hash, error)
SetTxDefaults(args evmtypes.TransactionArgs) (evmtypes.TransactionArgs, error)
EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *rpctypes.BlockNumber) (hexutil.Uint64, error)
DoCall(args evmtypes.TransactionArgs, blockNr rpctypes.BlockNumber, overrides *rpctypes.StateOverride) (*evmtypes.MsgEthereumTxResponse, error)
DoCall(args evmtypes.TransactionArgs, blockNr rpctypes.BlockNumber, overrides *json.RawMessage) (*evmtypes.MsgEthereumTxResponse, error)
GasPrice() (*hexutil.Big, error)

// Filter API
Expand Down
11 changes: 4 additions & 7 deletions rpc/backend/call_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (b *Backend) EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *rp
// estimated gas used on the operation or an error if fails.
func (b *Backend) DoCall(
args evmtypes.TransactionArgs, blockNr rpctypes.BlockNumber,
overrides *rpctypes.StateOverride,
overrides *json.RawMessage,
) (*evmtypes.MsgEthereumTxResponse, error) {
bz, err := json.Marshal(&args)
if err != nil {
Expand All @@ -372,20 +372,17 @@ func (b *Backend) DoCall(
return nil, errors.New("header not found")
}

var overridesJSON []byte
var bzOverrides []byte
if overrides != nil {
overridesJSON, err = json.Marshal(overrides)
if err != nil {
return nil, err
}
bzOverrides = *overrides
}

req := evmtypes.EthCallRequest{
Args: bz,
GasCap: b.RPCGasCap(),
ProposerAddress: sdk.ConsAddress(header.Block.ProposerAddress),
ChainId: b.chainID.Int64(),
Overrides: overridesJSON,
Overrides: bzOverrides,
}

// From ContextWithHeight: if the provided height is 0,
Expand Down
5 changes: 3 additions & 2 deletions rpc/namespaces/ethereum/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package eth

import (
"context"
"encoding/json"

"github.com/ethereum/go-ethereum/signer/core/apitypes"

Expand Down Expand Up @@ -85,7 +86,7 @@ type EthereumAPI interface {
//
// Allows developers to read data from the blockchain which includes executing
// smart contracts. However, no data is published to the Ethereum network.
Call(args evmtypes.TransactionArgs, blockNrOrHash rpctypes.BlockNumberOrHash, overrides *rpctypes.StateOverride) (hexutil.Bytes, error)
Call(args evmtypes.TransactionArgs, blockNrOrHash rpctypes.BlockNumberOrHash, overrides *json.RawMessage) (hexutil.Bytes, error)

// Chain Information
//
Expand Down Expand Up @@ -281,7 +282,7 @@ func (e *PublicAPI) GetProof(address common.Address,
// Call performs a raw contract call.
func (e *PublicAPI) Call(args evmtypes.TransactionArgs,
blockNrOrHash rpctypes.BlockNumberOrHash,
overrides *rpctypes.StateOverride,
overrides *json.RawMessage,
) (hexutil.Bytes, error) {
e.logger.Debug("eth_call", "args", args.String(), "block number or hash", blockNrOrHash)

Expand Down

0 comments on commit ddb3035

Please sign in to comment.