Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

rpc: protocol version #575

Merged
merged 9 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (evm) [\#621](https:/cosmos/ethermint/issues/621) EVM `GenesisAccount` fields now share the same format as the auth module `Account`.
* (app) [\#617](https:/cosmos/ethermint/issues/617) Fix genesis export functionality.
* (rpc) [\#574](https:/cosmos/ethermint/issues/574) Fix outdated version from `eth_protocolVersion`.

## [v0.3.1] - 2020-11-24

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ all: tools verify install
###############################################################################

build: go.sum

ifeq ($(OS), Windows_NT)
go build -mod=readonly $(BUILD_FLAGS) -o build/$(ETHERMINT_DAEMON_BINARY).exe ./cmd/$(ETHERMINT_DAEMON_BINARY)
go build -mod=readonly $(BUILD_FLAGS) -o build/$(ETHERMINT_CLI_BINARY).exe ./cmd/$(ETHERMINT_CLI_BINARY)
else
go build -mod=readonly $(BUILD_FLAGS) -o build/$(ETHERMINT_DAEMON_BINARY) ./cmd/$(ETHERMINT_DAEMON_BINARY)
go build -mod=readonly $(BUILD_FLAGS) -o build/$(ETHERMINT_CLI_BINARY) ./cmd/$(ETHERMINT_CLI_BINARY)
endif
go build -mod=readonly ./...

build-ethermint: go.sum
mkdir -p $(BUILDDIR)
Expand Down
3 changes: 1 addition & 2 deletions rpc/namespaces/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
rpctypes "github.com/cosmos/ethermint/rpc/types"
ethermint "github.com/cosmos/ethermint/types"
"github.com/cosmos/ethermint/utils"
"github.com/cosmos/ethermint/version"
evmtypes "github.com/cosmos/ethermint/x/evm/types"

abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -124,7 +123,7 @@ func (api *PublicEthereumAPI) SetKeys(keys []ethsecp256k1.PrivKey) {
// ProtocolVersion returns the supported Ethereum protocol version.
func (api *PublicEthereumAPI) ProtocolVersion() hexutil.Uint {
api.logger.Debug("eth_protocolVersion")
return hexutil.Uint(version.ProtocolVersion)
return hexutil.Uint(ethermint.ProtocolVersions[0])
}

// ChainId returns the chain's identifier in hex format
Expand Down
9 changes: 6 additions & 3 deletions rpc/namespaces/web3/api.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
package web3

import (
"github.com/cosmos/ethermint/version"
"fmt"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"

"github.com/cosmos/cosmos-sdk/version"
)

// PublicWeb3API is the web3_ prefixed set of APIs in the Web3 JSON-RPC spec.
type PublicWeb3API struct{}

// New creates an instance of the Web3 API.
// NewAPI creates an instance of the Web3 API.
func NewAPI() *PublicWeb3API {
return &PublicWeb3API{}
}

// ClientVersion returns the client version in the Web3 user agent format.
func (PublicWeb3API) ClientVersion() string {
return version.ClientVersion()
info := version.NewInfo()
return fmt.Sprintf("%s-%s", info.Name, info.Version)
}

// Sha3 returns the keccak-256 hash of the passed-in input.
Expand Down
3 changes: 1 addition & 2 deletions tests/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
ethtypes "github.com/ethereum/go-ethereum/core/types"

rpctypes "github.com/cosmos/ethermint/rpc/types"
"github.com/cosmos/ethermint/version"
)

const (
Expand Down Expand Up @@ -258,7 +257,7 @@ func TestEth_GetTransactionLogs(t *testing.T) {
}

func TestEth_protocolVersion(t *testing.T) {
expectedRes := hexutil.Uint(version.ProtocolVersion)
expectedRes := hexutil.Uint(ethermint.ProtocolVersions[0])

rpcRes := call(t, "eth_protocolVersion", []string{})

Expand Down
11 changes: 11 additions & 0 deletions types/protocol.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package types

// Constants to match up protocol versions and messages
const (
eth63 = 63
eth64 = 64
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
eth65 = 65
)

// ProtocolVersions are the supported versions of the eth protocol (first is primary).
var ProtocolVersions = []uint{eth65, eth64, eth63}
26 changes: 0 additions & 26 deletions version/version.go

This file was deleted.

15 changes: 0 additions & 15 deletions x/evm/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/cosmos/ethermint/utils"
"github.com/cosmos/ethermint/version"
"github.com/cosmos/ethermint/x/evm/types"

ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"

abci "github.com/tendermint/tendermint/abci/types"
)
Expand All @@ -23,8 +21,6 @@ import (
func NewQuerier(keeper Keeper) sdk.Querier {
return func(ctx sdk.Context, path []string, _ abci.RequestQuery) ([]byte, error) {
switch path[0] {
case types.QueryProtocolVersion:
return queryProtocolVersion(keeper)
case types.QueryBalance:
return queryBalance(ctx, path, keeper)
case types.QueryBlockNumber:
Expand All @@ -51,17 +47,6 @@ func NewQuerier(keeper Keeper) sdk.Querier {
}
}

func queryProtocolVersion(keeper Keeper) ([]byte, error) {
vers := version.ProtocolVersion

bz, err := codec.MarshalJSONIndent(keeper.cdc, hexutil.Uint(vers))
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
}

return bz, nil
}

func queryBalance(ctx sdk.Context, path []string, keeper Keeper) ([]byte, error) {
addr := ethcmn.HexToAddress(path[1])
balance := keeper.GetBalance(ctx, addr)
Expand Down
1 change: 0 additions & 1 deletion x/evm/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func (suite *KeeperTestSuite) TestQuerier() {
malleate func()
expPass bool
}{
{"protocol version", []string{types.QueryProtocolVersion}, func() {}, true},
{"balance", []string{types.QueryBalance, addrHex}, func() {
suite.app.EvmKeeper.SetBalance(suite.ctx, suite.address, big.NewInt(5))
}, true},
Expand Down
10 changes: 0 additions & 10 deletions x/evm/types/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

// Supported endpoints
const (
QueryProtocolVersion = "protocolVersion"
QueryBalance = "balance"
QueryBlockNumber = "blockNumber"
QueryStorage = "storage"
Expand All @@ -22,15 +21,6 @@ const (
QueryExportAccount = "exportAccount"
)

// QueryResProtocolVersion is response type for protocol version query
type QueryResProtocolVersion struct {
Version string `json:"version"`
}

func (q QueryResProtocolVersion) String() string {
return q.Version
}

// QueryResBalance is response type for balance query
type QueryResBalance struct {
Balance string `json:"balance"`
Expand Down