rpc: protocol version (#575)

* evm: protocol version

* changelog

* version

* fix

* support latest version only
This commit is contained in:
Federico Kunze 2020-12-08 16:51:26 -03:00 committed by GitHub
parent 3bb76e8533
commit ef1bef16e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 20 additions and 60 deletions

View File

@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (evm) [\#621](https://github.com/cosmos/ethermint/issues/621) EVM `GenesisAccount` fields now share the same format as the auth module `Account`. * (evm) [\#621](https://github.com/cosmos/ethermint/issues/621) EVM `GenesisAccount` fields now share the same format as the auth module `Account`.
* (evm) [\#618](https://github.com/cosmos/ethermint/issues/618) Add missing EVM `Context` `GetHash` field that retrieves a the header hash from a given block height. * (evm) [\#618](https://github.com/cosmos/ethermint/issues/618) Add missing EVM `Context` `GetHash` field that retrieves a the header hash from a given block height.
* (app) [\#617](https://github.com/cosmos/ethermint/issues/617) Fix genesis export functionality. * (app) [\#617](https://github.com/cosmos/ethermint/issues/617) Fix genesis export functionality.
* (rpc) [\#574](https://github.com/cosmos/ethermint/issues/574) Fix outdated version from `eth_protocolVersion`.
## [v0.3.1] - 2020-11-24 ## [v0.3.1] - 2020-11-24

View File

@ -123,6 +123,7 @@ all: tools verify install
############################################################################### ###############################################################################
build: go.sum build: go.sum
ifeq ($(OS), Windows_NT) 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_DAEMON_BINARY).exe ./cmd/$(ETHERMINT_DAEMON_BINARY)
go build -mod=readonly $(BUILD_FLAGS) -o build/$(ETHERMINT_CLI_BINARY).exe ./cmd/$(ETHERMINT_CLI_BINARY) go build -mod=readonly $(BUILD_FLAGS) -o build/$(ETHERMINT_CLI_BINARY).exe ./cmd/$(ETHERMINT_CLI_BINARY)
@ -130,7 +131,6 @@ 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_DAEMON_BINARY) ./cmd/$(ETHERMINT_DAEMON_BINARY)
go build -mod=readonly $(BUILD_FLAGS) -o build/$(ETHERMINT_CLI_BINARY) ./cmd/$(ETHERMINT_CLI_BINARY) go build -mod=readonly $(BUILD_FLAGS) -o build/$(ETHERMINT_CLI_BINARY) ./cmd/$(ETHERMINT_CLI_BINARY)
endif endif
go build -mod=readonly ./...
build-ethermint: go.sum build-ethermint: go.sum
mkdir -p $(BUILDDIR) mkdir -p $(BUILDDIR)

View File

@ -17,7 +17,6 @@ import (
rpctypes "github.com/cosmos/ethermint/rpc/types" rpctypes "github.com/cosmos/ethermint/rpc/types"
ethermint "github.com/cosmos/ethermint/types" ethermint "github.com/cosmos/ethermint/types"
"github.com/cosmos/ethermint/utils" "github.com/cosmos/ethermint/utils"
"github.com/cosmos/ethermint/version"
evmtypes "github.com/cosmos/ethermint/x/evm/types" evmtypes "github.com/cosmos/ethermint/x/evm/types"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
@ -124,7 +123,7 @@ func (api *PublicEthereumAPI) SetKeys(keys []ethsecp256k1.PrivKey) {
// ProtocolVersion returns the supported Ethereum protocol version. // ProtocolVersion returns the supported Ethereum protocol version.
func (api *PublicEthereumAPI) ProtocolVersion() hexutil.Uint { func (api *PublicEthereumAPI) ProtocolVersion() hexutil.Uint {
api.logger.Debug("eth_protocolVersion") api.logger.Debug("eth_protocolVersion")
return hexutil.Uint(version.ProtocolVersion) return hexutil.Uint(ethermint.ProtocolVersion)
} }
// ChainId returns the chain's identifier in hex format // ChainId returns the chain's identifier in hex format

View File

@ -1,23 +1,26 @@
package web3 package web3
import ( import (
"github.com/cosmos/ethermint/version" "fmt"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto" "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. // PublicWeb3API is the web3_ prefixed set of APIs in the Web3 JSON-RPC spec.
type PublicWeb3API struct{} type PublicWeb3API struct{}
// New creates an instance of the Web3 API. // NewAPI creates an instance of the Web3 API.
func NewAPI() *PublicWeb3API { func NewAPI() *PublicWeb3API {
return &PublicWeb3API{} return &PublicWeb3API{}
} }
// ClientVersion returns the client version in the Web3 user agent format. // ClientVersion returns the client version in the Web3 user agent format.
func (PublicWeb3API) ClientVersion() string { 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. // Sha3 returns the keccak-256 hash of the passed-in input.

View File

@ -24,7 +24,7 @@ import (
ethtypes "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types"
rpctypes "github.com/cosmos/ethermint/rpc/types" rpctypes "github.com/cosmos/ethermint/rpc/types"
"github.com/cosmos/ethermint/version" ethermint "github.com/cosmos/ethermint/types"
) )
const ( const (
@ -258,7 +258,7 @@ func TestEth_GetTransactionLogs(t *testing.T) {
} }
func TestEth_protocolVersion(t *testing.T) { func TestEth_protocolVersion(t *testing.T) {
expectedRes := hexutil.Uint(version.ProtocolVersion) expectedRes := hexutil.Uint(ethermint.ProtocolVersion)
rpcRes := call(t, "eth_protocolVersion", []string{}) rpcRes := call(t, "eth_protocolVersion", []string{})

9
types/protocol.go Normal file
View File

@ -0,0 +1,9 @@
package types
// Constants to match up protocol versions and messages
const (
eth65 = 65
// ProtocolVersion is the latest supported version of the eth protocol.
ProtocolVersion = eth65
)

View File

@ -1,26 +0,0 @@
package version
import (
"fmt"
"runtime"
)
// AppName represents the application name as the 'user agent' on the larger Ethereum network.
const AppName = "Ethermint"
// Version contains the application semantic version.
//
// TODO: How do we want to version this being that an initial Ethermint has
// been developed?
const Version = "0.0.0"
// ProtocolVersion is the supported Ethereum protocol version (e.g., Homestead, Olympic, etc.)
const ProtocolVersion = 63
// GitCommit contains the git SHA1 short hash set by build flags.
var GitCommit = ""
// ClientVersion returns the full version string for identification on the larger Ethereum network.
func ClientVersion() string {
return fmt.Sprintf("%s/%s+%s/%s/%s", AppName, Version, GitCommit, runtime.GOOS, runtime.Version())
}

View File

@ -10,11 +10,9 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/ethermint/utils" "github.com/cosmos/ethermint/utils"
"github.com/cosmos/ethermint/version"
"github.com/cosmos/ethermint/x/evm/types" "github.com/cosmos/ethermint/x/evm/types"
ethcmn "github.com/ethereum/go-ethereum/common" ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
) )
@ -23,8 +21,6 @@ import (
func NewQuerier(keeper Keeper) sdk.Querier { func NewQuerier(keeper Keeper) sdk.Querier {
return func(ctx sdk.Context, path []string, _ abci.RequestQuery) ([]byte, error) { return func(ctx sdk.Context, path []string, _ abci.RequestQuery) ([]byte, error) {
switch path[0] { switch path[0] {
case types.QueryProtocolVersion:
return queryProtocolVersion(keeper)
case types.QueryBalance: case types.QueryBalance:
return queryBalance(ctx, path, keeper) return queryBalance(ctx, path, keeper)
case types.QueryBlockNumber: case types.QueryBlockNumber:
@ -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) { func queryBalance(ctx sdk.Context, path []string, keeper Keeper) ([]byte, error) {
addr := ethcmn.HexToAddress(path[1]) addr := ethcmn.HexToAddress(path[1])
balance := keeper.GetBalance(ctx, addr) balance := keeper.GetBalance(ctx, addr)

View File

@ -17,7 +17,6 @@ func (suite *KeeperTestSuite) TestQuerier() {
malleate func() malleate func()
expPass bool expPass bool
}{ }{
{"protocol version", []string{types.QueryProtocolVersion}, func() {}, true},
{"balance", []string{types.QueryBalance, addrHex}, func() { {"balance", []string{types.QueryBalance, addrHex}, func() {
suite.app.EvmKeeper.SetBalance(suite.ctx, suite.address, big.NewInt(5)) suite.app.EvmKeeper.SetBalance(suite.ctx, suite.address, big.NewInt(5))
}, true}, }, true},

View File

@ -8,7 +8,6 @@ import (
// Supported endpoints // Supported endpoints
const ( const (
QueryProtocolVersion = "protocolVersion"
QueryBalance = "balance" QueryBalance = "balance"
QueryBlockNumber = "blockNumber" QueryBlockNumber = "blockNumber"
QueryStorage = "storage" QueryStorage = "storage"
@ -22,15 +21,6 @@ const (
QueryExportAccount = "exportAccount" 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 // QueryResBalance is response type for balance query
type QueryResBalance struct { type QueryResBalance struct {
Balance string `json:"balance"` Balance string `json:"balance"`