Skip to content

Commit

Permalink
fix: chain-id in grpc query is not initialized without abci event (ev…
Browse files Browse the repository at this point in the history
…mos#1405)

* fix: chain-id in grpc query is not initialized without abci event

Closes: evmos#1404

Solution:
- pass the chain-id from caller.

* Update CHANGELOG.md

* only override if input is not empty

* add comment to chain id

* pass chain-id to state transition

* Update x/evm/keeper/grpc_query.go

* Apply suggestions from code review

* fix golang lint

* update gomod2nix.toml

* fix unit tests

* update gomod2nix

* api breaking changelog

* add unit tests, and fix TraceBlock by the way

* Update CHANGELOG.md

* test --grpc-only mode in integration tests

* remove tmp var

* Update tests/integration_tests/test_grpc_only.py

* Update x/evm/keeper/grpc_query_test.go

Co-authored-by: mmsqe <tqd0800210105@gmail.com>

* fix linters

* fix nil pointer in tests

* fix conflicts

* fix conflicts

* fixes

* fix lint

* fix unit test

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: mmsqe <tqd0800210105@gmail.com>
Co-authored-by: Freddy Caceres <facs95@gmail.com>
  • Loading branch information
4 people committed Jan 16, 2023
1 parent 10bba9d commit 0e4d41e
Show file tree
Hide file tree
Showing 20 changed files with 2,212 additions and 113 deletions.
5 changes: 3 additions & 2 deletions client/docs/statik/statik.go

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,18 @@ paths:
required: false
type: string
format: uint64
- name: proposer_address
description: the proposer of the requested block.
in: query
required: false
type: string
format: byte
- name: chain_id
description: the eip155 chain id parsed from the requested block header.
in: query
required: false
type: string
format: int64
tags:
- Query
/ethermint/evm/v1/eth_call:
Expand Down Expand Up @@ -1599,6 +1611,18 @@ paths:
required: false
type: string
format: uint64
- name: proposer_address
description: the proposer of the requested block.
in: query
required: false
type: string
format: byte
- name: chain_id
description: the eip155 chain id parsed from the requested block header.
in: query
required: false
type: string
format: int64
tags:
- Query
/ethermint/evm/v1/params:
Expand Down Expand Up @@ -2515,6 +2539,18 @@ paths:
required: false
type: string
format: date-time
- name: proposer_address
description: the proposer of the requested block.
in: query
required: false
type: string
format: byte
- name: chain_id
description: the eip155 chain id parsed from the requested block header.
in: query
required: false
type: string
format: int64
tags:
- Query
/ethermint/evm/v1/trace_tx:
Expand Down Expand Up @@ -2961,6 +2997,18 @@ paths:
required: false
type: string
format: date-time
- name: proposer_address
description: the proposer of the requested block.
in: query
required: false
type: string
format: byte
- name: chain_id
description: the eip155 chain id parsed from the requested block header.
in: query
required: false
type: string
format: int64
tags:
- Query
/ethermint/evm/v1/validator_account/{cons_address}:
Expand Down
3 changes: 3 additions & 0 deletions docs/api/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ EthCallRequest defines EthCall request
| `args` | [bytes](#bytes) | | same json format as the json rpc api. |
| `gas_cap` | [uint64](#uint64) | | the default gas cap to be used |
| `proposer_address` | [bytes](#bytes) | | the proposer of the requested block |
| `chain_id` | [int64](#int64) | | the eip155 chain id parsed from the requested block header |



Expand Down Expand Up @@ -790,6 +791,7 @@ QueryTraceBlockRequest defines TraceTx request
| `block_hash` | [string](#string) | | block hex hash |
| `block_time` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | block time |
| `proposer_address` | [bytes](#bytes) | | the proposer of the requested block |
| `chain_id` | [int64](#int64) | | the eip155 chain id parsed from the requested block header |



Expand Down Expand Up @@ -826,6 +828,7 @@ QueryTraceTxRequest defines TraceTx request
| `block_hash` | [string](#string) | | block hex hash of requested transaction |
| `block_time` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | block time of requested transaction |
| `proposer_address` | [bytes](#bytes) | | the proposer of the requested block |
| `chain_id` | [int64](#int64) | | the eip155 chain id parsed from the requested block header |



Expand Down
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ schema = 3
version = "v0.19.3"
hash = "sha256-rmW2KoKmm4YXmYIYE1vXMOCaDyP1ym0qsW224PYc9rg="
[mod."github.com/cosmos/ibc-go/v3"]
version = "v3.2.0"
hash = "sha256-qVjWwNOQZvZQQBOKDOWomPshI2UO8Art2rPgdSgf8aE="
version = "v3.3.0"
hash = "sha256-ytLmHn/BXU3FeHvHntt08T7UkKetxdGxcVfFOP0WH8s="
[mod."github.com/cosmos/ledger-cosmos-go"]
version = "v0.11.1"
hash = "sha256-yli+VvVtZmHo2LPvCY6lYVUfcCDn3sBLDL+a8KIlqDA="
Expand Down
6 changes: 6 additions & 0 deletions proto/ethermint/evm/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ message EthCallRequest {
uint64 gas_cap = 2;
// the proposer of the requested block
bytes proposer_address = 3 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ConsAddress"];
// the eip155 chain id parsed from the requested block header
int64 chain_id = 4;
}

// EstimateGasResponse defines EstimateGas response
Expand Down Expand Up @@ -255,6 +257,8 @@ message QueryTraceTxRequest {
google.protobuf.Timestamp block_time = 7 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
// the proposer of the requested block
bytes proposer_address = 8 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ConsAddress"];
// the eip155 chain id parsed from the requested block header
int64 chain_id = 9;
}

// QueryTraceTxResponse defines TraceTx response
Expand All @@ -277,6 +281,8 @@ message QueryTraceBlockRequest {
google.protobuf.Timestamp block_time = 7 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
// the proposer of the requested block
bytes proposer_address = 8 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ConsAddress"];
// the eip155 chain id parsed from the requested block header
int64 chain_id = 9;
}

// QueryTraceBlockResponse defines TraceBlock response
Expand Down
9 changes: 5 additions & 4 deletions rpc/backend/backend_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package backend

import (
"bufio"
"fmt"
"math/big"
"os"
"path/filepath"
Expand Down Expand Up @@ -37,21 +36,23 @@ func TestBackendTestSuite(t *testing.T) {
suite.Run(t, new(BackendTestSuite))
}

const ChainID = "ethermint_9000-1"

// SetupTest is executed before every BackendTestSuite test
func (suite *BackendTestSuite) SetupTest() {
ctx := server.NewDefaultContext()
ctx.Viper.Set("telemetry.global-labels", []interface{}{})

baseDir := suite.T().TempDir()
nodeDirName := fmt.Sprintf("node")
nodeDirName := "node"
clientDir := filepath.Join(baseDir, nodeDirName, "evmoscli")
keyRing, err := suite.generateTestKeyring(clientDir)
if err != nil {
panic(err)
}

encodingConfig := encoding.MakeConfig(app.ModuleBasics)
clientCtx := client.Context{}.WithChainID("ethermint_9000-1").
clientCtx := client.Context{}.WithChainID(ChainID).
WithHeight(1).
WithTxConfig(encodingConfig.TxConfig).
WithKeyringDir(clientDir).
Expand All @@ -70,7 +71,7 @@ func (suite *BackendTestSuite) SetupTest() {
// buildEthereumTx returns an example legacy Ethereum transaction
func (suite *BackendTestSuite) buildEthereumTx() (*evmtypes.MsgEthereumTx, []byte) {
msgEthereumTx := evmtypes.NewTx(
big.NewInt(1),
suite.backend.chainID,
uint64(0),
&common.Address{},
big.NewInt(0),
Expand Down
5 changes: 5 additions & 0 deletions rpc/backend/call_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ func (b *Backend) SetTxDefaults(args evmtypes.TransactionArgs) (evmtypes.Transac
Value: args.Value,
Data: input,
AccessList: args.AccessList,
ChainID: args.ChainID,
Nonce: args.Nonce,
}

blockNr := rpctypes.NewBlockNumber(big.NewInt(0))
Expand Down Expand Up @@ -310,6 +312,7 @@ func (b *Backend) EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *rp
Args: bz,
GasCap: b.RPCGasCap(),
ProposerAddress: sdk.ConsAddress(header.Block.ProposerAddress),
ChainId: b.chainID.Int64(),
}

// From ContextWithHeight: if the provided height is 0,
Expand All @@ -336,10 +339,12 @@ func (b *Backend) DoCall(
// the error message imitates geth behavior
return nil, errors.New("header not found")
}

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

// From ContextWithHeight: if the provided height is 0,
Expand Down
Loading

0 comments on commit 0e4d41e

Please sign in to comment.