Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
59361c3
update nix
mmsqe Jan 16, 2023
cd76122
support backup grpc client
mmsqe Jan 12, 2023
cca8b87
support grpc client map
mmsqe Jan 13, 2023
5421793
config deprecate migrate height
mmsqe Jan 13, 2023
b2c9ad4
apply backup grpc client
mmsqe Jan 13, 2023
39a5b18
Revert "keep grpc query compatible with version before migrate"
mmsqe Jan 13, 2023
546689f
cleanup todo
mmsqe Jan 14, 2023
87349ec
cant use var as key in toml
mmsqe Jan 14, 2023
ce340af
revert keep grpc query compatible with version before feemarket migrate
mmsqe Jan 16, 2023
6b1089d
fix config
mmsqe Jan 16, 2023
87ea19c
support backup for eth_call
mmsqe Jan 16, 2023
8bfaee0
fix lint
mmsqe Jan 17, 2023
163f4e2
fix test
mmsqe Jan 17, 2023
734c9a1
update change doc
mmsqe Jan 17, 2023
3befbb2
fix lint
mmsqe Jan 17, 2023
d858e2d
Merge branch 'main' into backup_grpc
mmsqe Jan 20, 2023
d528df7
clean up
mmsqe Jan 30, 2023
a2d71a0
allow query evm params with old blk
mmsqe Jan 30, 2023
98ed73d
Merge branch 'main' into backup_grpc
mmsqe Jan 30, 2023
b5b1154
Merge remote-tracking branch 'origin/main' into backup_grpc
mmsqe Mar 17, 2023
8131baa
update nix
mmsqe Mar 17, 2023
8c8bedc
add patch
mmsqe Mar 17, 2023
39a0fc9
test call with backup
mmsqe Mar 17, 2023
8167e30
add for debug tx & blk
mmsqe Mar 17, 2023
03d1a9e
keep migrate no change
mmsqe Mar 16, 2023
af4604e
Revert "revert keep grpc query compatible with version before feemark…
mmsqe Mar 17, 2023
f1772f8
Revert "Revert "keep grpc query compatible with version before migrate""
mmsqe Mar 17, 2023
f26c579
fix lint
mmsqe Mar 17, 2023
0843594
keep migrate related stuff no change
mmsqe Mar 17, 2023
a1eda26
fix resolve
mmsqe Mar 17, 2023
5aa6504
revert query param change
mmsqe Mar 21, 2023
fd8bc47
fix template
mmsqe Mar 24, 2023
ea15608
Merge remote-tracking branch 'origin/main' into backup_grpc
mmsqe Mar 24, 2023
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## Unreleased

### Features

* (rpc) [#1603](https://github.com/evmos/ethermint/pull/1603) Support multi gRPC query clients serve with old binary.

### State Machine Breaking

* (deps) [#1168](https://github.com/evmos/ethermint/pull/1168) Upgrade Cosmos SDK to [`v0.46.6`]
Expand Down
44 changes: 36 additions & 8 deletions rpc/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
ethermint "github.com/evmos/ethermint/types"

rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
"google.golang.org/grpc"
)

// RPC namespaces and API version
Expand All @@ -60,6 +61,7 @@ const (
type APICreator = func(
ctx *server.Context,
clientCtx client.Context,
backupGRPCClientConns map[[2]int]*grpc.ClientConn,
tendermintWebsocketClient *rpcclient.WSClient,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
Expand All @@ -72,11 +74,12 @@ func init() {
apiCreators = map[string]APICreator{
EthNamespace: func(ctx *server.Context,
clientCtx client.Context,
backupGRPCClientConns map[[2]int]*grpc.ClientConn,
tmWSClient *rpcclient.WSClient,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
) []rpc.API {
evmBackend := backend.NewBackend(ctx, ctx.Logger, clientCtx, allowUnprotectedTxs, indexer)
evmBackend := backend.NewBackend(ctx, ctx.Logger, clientCtx, backupGRPCClientConns, allowUnprotectedTxs, indexer)
return []rpc.API{
{
Namespace: EthNamespace,
Expand All @@ -92,7 +95,14 @@ func init() {
},
}
},
Web3Namespace: func(*server.Context, client.Context, *rpcclient.WSClient, bool, ethermint.EVMTxIndexer) []rpc.API {
Web3Namespace: func(
*server.Context,
client.Context,
map[[2]int]*grpc.ClientConn,
*rpcclient.WSClient,
bool,
ethermint.EVMTxIndexer,
) []rpc.API {
return []rpc.API{
{
Namespace: Web3Namespace,
Expand All @@ -102,7 +112,14 @@ func init() {
},
}
},
NetNamespace: func(_ *server.Context, clientCtx client.Context, _ *rpcclient.WSClient, _ bool, _ ethermint.EVMTxIndexer) []rpc.API {
NetNamespace: func(
_ *server.Context,
clientCtx client.Context,
_ map[[2]int]*grpc.ClientConn,
_ *rpcclient.WSClient,
_ bool,
_ ethermint.EVMTxIndexer,
) []rpc.API {
return []rpc.API{
{
Namespace: NetNamespace,
Expand All @@ -114,11 +131,12 @@ func init() {
},
PersonalNamespace: func(ctx *server.Context,
clientCtx client.Context,
backupGRPCClientConns map[[2]int]*grpc.ClientConn,
_ *rpcclient.WSClient,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
) []rpc.API {
evmBackend := backend.NewBackend(ctx, ctx.Logger, clientCtx, allowUnprotectedTxs, indexer)
evmBackend := backend.NewBackend(ctx, ctx.Logger, clientCtx, backupGRPCClientConns, allowUnprotectedTxs, indexer)
return []rpc.API{
{
Namespace: PersonalNamespace,
Expand All @@ -128,7 +146,14 @@ func init() {
},
}
},
TxPoolNamespace: func(ctx *server.Context, _ client.Context, _ *rpcclient.WSClient, _ bool, _ ethermint.EVMTxIndexer) []rpc.API {
TxPoolNamespace: func(
ctx *server.Context,
_ client.Context,
_ map[[2]int]*grpc.ClientConn,
_ *rpcclient.WSClient,
_ bool,
_ ethermint.EVMTxIndexer,
) []rpc.API {
return []rpc.API{
{
Namespace: TxPoolNamespace,
Expand All @@ -140,11 +165,12 @@ func init() {
},
DebugNamespace: func(ctx *server.Context,
clientCtx client.Context,
backupGRPCClientConns map[[2]int]*grpc.ClientConn,
_ *rpcclient.WSClient,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
) []rpc.API {
evmBackend := backend.NewBackend(ctx, ctx.Logger, clientCtx, allowUnprotectedTxs, indexer)
evmBackend := backend.NewBackend(ctx, ctx.Logger, clientCtx, backupGRPCClientConns, allowUnprotectedTxs, indexer)
return []rpc.API{
{
Namespace: DebugNamespace,
Expand All @@ -156,11 +182,12 @@ func init() {
},
MinerNamespace: func(ctx *server.Context,
clientCtx client.Context,
backupGRPCClientConns map[[2]int]*grpc.ClientConn,
_ *rpcclient.WSClient,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
) []rpc.API {
evmBackend := backend.NewBackend(ctx, ctx.Logger, clientCtx, allowUnprotectedTxs, indexer)
evmBackend := backend.NewBackend(ctx, ctx.Logger, clientCtx, backupGRPCClientConns, allowUnprotectedTxs, indexer)
return []rpc.API{
{
Namespace: MinerNamespace,
Expand All @@ -176,6 +203,7 @@ func init() {
// GetRPCAPIs returns the list of all APIs
func GetRPCAPIs(ctx *server.Context,
clientCtx client.Context,
backupGRPCClientConns map[[2]int]*grpc.ClientConn,
tmWSClient *rpcclient.WSClient,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
Expand All @@ -185,7 +213,7 @@ func GetRPCAPIs(ctx *server.Context,

for _, ns := range selectedAPIs {
if creator, ok := apiCreators[ns]; ok {
apis = append(apis, creator(ctx, clientCtx, tmWSClient, allowUnprotectedTxs, indexer)...)
apis = append(apis, creator(ctx, clientCtx, backupGRPCClientConns, tmWSClient, allowUnprotectedTxs, indexer)...)
} else {
ctx.Logger.Error("invalid namespace value", "namespace", ns)
}
Expand Down
20 changes: 11 additions & 9 deletions rpc/backend/account_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ func (b *Backend) GetCode(address common.Address, blockNrOrHash rpctypes.BlockNu
req := &evmtypes.QueryCodeRequest{
Address: address.String(),
}

res, err := b.queryClient.Code(rpctypes.ContextWithHeight(blockNum.Int64()), req)
height := blockNum.Int64()
queryClient := b.getGrpcClient(height)
res, err := queryClient.Code(rpctypes.ContextWithHeight(height), req)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -84,10 +85,10 @@ func (b *Backend) GetProof(address common.Address, storageKeys []string, blockNr

// query storage proofs
storageProofs := make([]rpctypes.StorageResult, len(storageKeys))

queryClient := b.getGrpcClient(height)
for i, key := range storageKeys {
hexKey := common.HexToHash(key)
valueBz, proof, err := b.queryClient.GetProof(clientCtx, evmtypes.StoreKey, evmtypes.StateKey(address, hexKey.Bytes()))
valueBz, proof, err := queryClient.GetProof(clientCtx, evmtypes.StoreKey, evmtypes.StateKey(address, hexKey.Bytes()))
if err != nil {
return nil, err
}
Expand All @@ -104,14 +105,14 @@ func (b *Backend) GetProof(address common.Address, storageKeys []string, blockNr
Address: address.String(),
}

res, err := b.queryClient.Account(ctx, req)
res, err := queryClient.Account(ctx, req)
if err != nil {
return nil, err
}

// query account proofs
accountKey := authtypes.AddressStoreKey(sdk.AccAddress(address.Bytes()))
_, proof, err := b.queryClient.GetProof(clientCtx, authtypes.StoreKey, accountKey)
_, proof, err := queryClient.GetProof(clientCtx, authtypes.StoreKey, accountKey)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -143,8 +144,9 @@ func (b *Backend) GetStorageAt(address common.Address, key string, blockNrOrHash
Address: address.String(),
Key: key,
}

res, err := b.queryClient.Storage(rpctypes.ContextWithHeight(blockNum.Int64()), req)
height := blockNum.Int64()
queryClient := b.getGrpcClient(height)
res, err := queryClient.Storage(rpctypes.ContextWithHeight(height), req)
if err != nil {
return nil, err
}
Expand All @@ -169,7 +171,7 @@ func (b *Backend) GetBalance(address common.Address, blockNrOrHash rpctypes.Bloc
return nil, err
}

res, err := b.queryClient.Balance(rpctypes.ContextWithHeight(blockNum.Int64()), req)
res, err := b.getGrpcClient(blockNum.Int64()).Balance(rpctypes.ContextWithHeight(blockNum.Int64()), req)
if err != nil {
return nil, err
}
Expand Down
16 changes: 15 additions & 1 deletion rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
Expand All @@ -34,8 +35,10 @@ import (
"github.com/evmos/ethermint/server/config"
ethermint "github.com/evmos/ethermint/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
"github.com/tendermint/tendermint/libs/log"
tmrpctypes "github.com/tendermint/tendermint/rpc/core/types"
"google.golang.org/grpc"
)

// BackendI implements the Cosmos and EVM backend.
Expand Down Expand Up @@ -149,6 +152,7 @@ type Backend struct {
ctx context.Context
clientCtx client.Context
queryClient *rpctypes.QueryClient // gRPC query client
backupQueryClients map[[2]int]*rpctypes.QueryClient
logger log.Logger
chainID *big.Int
cfg config.Config
Expand All @@ -161,6 +165,7 @@ func NewBackend(
ctx *server.Context,
logger log.Logger,
clientCtx client.Context,
backupGRPCClientConns map[[2]int]*grpc.ClientConn,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
) *Backend {
Expand All @@ -174,14 +179,23 @@ func NewBackend(
panic(err)
}

return &Backend{
backend := &Backend{
ctx: context.Background(),
clientCtx: clientCtx,
queryClient: rpctypes.NewQueryClient(clientCtx),
backupQueryClients: make(map[[2]int]*rpctypes.QueryClient),
logger: logger.With("module", "backend"),
chainID: chainID,
cfg: appConf,
allowUnprotectedTxs: allowUnprotectedTxs,
indexer: indexer,
}
for key, conn := range backupGRPCClientConns {
backend.backupQueryClients[key] = &rpctypes.QueryClient{
ServiceClient: tx.NewServiceClient(conn),
QueryClient: evmtypes.NewQueryClient(conn),
FeeMarket: feemarkettypes.NewQueryClient(conn),
}
}
Comment on lines +193 to +199

Check failure

Code scanning / gosec

the value in the range statement should be _ unless copying a map: want: for key := range m

the value in the range statement should be _ unless copying a map: want: for key := range m
Comment on lines +193 to +199

Check warning

Code scanning / CodeQL

Iteration over map

Iteration over map may be a possible source of non-determinism
return backend
}
3 changes: 2 additions & 1 deletion rpc/backend/backend_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
rpctypes "github.com/evmos/ethermint/rpc/types"
"github.com/evmos/ethermint/tests"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"google.golang.org/grpc"
)

type BackendTestSuite struct {
Expand Down Expand Up @@ -79,7 +80,7 @@ func (suite *BackendTestSuite) SetupTest() {
allowUnprotectedTxs := false
idxer := indexer.NewKVIndexer(dbm.NewMemDB(), ctx.Logger, clientCtx)

suite.backend = NewBackend(ctx, ctx.Logger, clientCtx, allowUnprotectedTxs, idxer)
suite.backend = NewBackend(ctx, ctx.Logger, clientCtx, make(map[[2]int]*grpc.ClientConn), allowUnprotectedTxs, idxer)
suite.backend.queryClient.QueryClient = mocks.NewEVMQueryClient(suite.T())
suite.backend.clientCtx.Client = mocks.NewClient(suite.T())
suite.backend.queryClient.FeeMarket = mocks.NewFeeMarketQueryClient(suite.T())
Expand Down
3 changes: 2 additions & 1 deletion rpc/backend/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
func (b *Backend) BlockNumber() (hexutil.Uint64, error) {
// do any grpc query, ignore the response and use the returned block height
var header metadata.MD
// use latest queryClient to get block height
_, err := b.queryClient.Params(b.ctx, &evmtypes.QueryParamsRequest{}, grpc.Header(&header))
if err != nil {
return hexutil.Uint64(0), err
Expand Down Expand Up @@ -412,7 +413,7 @@ func (b *Backend) RPCBlockFromTendermintBlock(
var validatorAccAddr sdk.AccAddress

ctx := rpctypes.ContextWithHeight(block.Height)
res, err := b.queryClient.ValidatorAccount(ctx, req)
res, err := b.getGrpcClient(block.Height).ValidatorAccount(ctx, req)
if err != nil {
b.logger.Debug(
"failed to query validator operator address",
Expand Down
8 changes: 5 additions & 3 deletions rpc/backend/call_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func (b *Backend) SendRawTransaction(data hexutil.Bytes) (common.Hash, error) {
}

// Query params to use the EVM denomination
// use latest queryClient in send
res, err := b.queryClient.QueryClient.Params(b.ctx, &evmtypes.QueryParamsRequest{})
if err != nil {
b.logger.Error("failed to query evm params", "error", err.Error())
Expand Down Expand Up @@ -332,6 +333,7 @@ func (b *Backend) EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *rp
// From ContextWithHeight: if the provided height is 0,
// it will return an empty context and the gRPC query will use
// the latest block height for querying.
// use latest queryClient to estimate
res, err := b.queryClient.EstimateGas(rpctypes.ContextWithHeight(blockNr.Int64()), &req)
if err != nil {
return 0, err
Expand Down Expand Up @@ -364,7 +366,8 @@ func (b *Backend) DoCall(
// From ContextWithHeight: if the provided height is 0,
// it will return an empty context and the gRPC query will use
// the latest block height for querying.
ctx := rpctypes.ContextWithHeight(blockNr.Int64())
height := blockNr.Int64()
ctx := rpctypes.ContextWithHeight(height)
timeout := b.RPCEVMTimeout()

// Setup context so it may be canceled the call has completed
Expand All @@ -379,8 +382,7 @@ func (b *Backend) DoCall(
// Make sure the context is canceled when the call has completed
// this makes sure resources are cleaned up.
defer cancel()

res, err := b.queryClient.EthCall(ctx, &req)
res, err := b.getGrpcClient(height).EthCall(ctx, &req)
if err != nil {
return nil, err
}
Expand Down
10 changes: 7 additions & 3 deletions rpc/backend/chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (b *Backend) ChainID() (*hexutil.Big, error) {

// ChainConfig returns the latest ethereum chain configuration
func (b *Backend) ChainConfig() *params.ChainConfig {
// use latest queryClient to get config
params, err := b.queryClient.Params(b.ctx, &evmtypes.QueryParamsRequest{})
if err != nil {
return nil
Expand All @@ -64,6 +65,7 @@ func (b *Backend) ChainConfig() *params.ChainConfig {

// GlobalMinGasPrice returns MinGasPrice param from FeeMarket
func (b *Backend) GlobalMinGasPrice() (sdk.Dec, error) {
// use latest queryClient to get MinGasPrice
res, err := b.queryClient.FeeMarket.Params(b.ctx, &feemarkettypes.QueryParamsRequest{})
if err != nil {
return sdk.ZeroDec(), err
Expand All @@ -77,7 +79,9 @@ func (b *Backend) GlobalMinGasPrice() (sdk.Dec, error) {
// return nil.
func (b *Backend) BaseFee(blockRes *tmrpctypes.ResultBlockResults) (*big.Int, error) {
// return BaseFee if London hard fork is activated and feemarket is enabled
res, err := b.queryClient.BaseFee(rpctypes.ContextWithHeight(blockRes.Height), &evmtypes.QueryBaseFeeRequest{})
height := blockRes.Height
queryClient := b.getGrpcClient(height)
res, err := queryClient.BaseFee(rpctypes.ContextWithHeight(height), &evmtypes.QueryBaseFeeRequest{})
if err != nil || res.BaseFee == nil {
// we can't tell if it's london HF not enabled or the state is pruned,
// in either case, we'll fallback to parsing from begin blocker event,
Expand Down Expand Up @@ -143,7 +147,7 @@ func (b *Backend) GetCoinbase() (sdk.AccAddress, error) {
req := &evmtypes.QueryValidatorAccountRequest{
ConsAddress: sdk.ConsAddress(status.ValidatorInfo.Address).String(),
}

// use latest queryClient to get coinbase
res, err := b.queryClient.ValidatorAccount(b.ctx, req)
if err != nil {
return nil, err
Expand Down Expand Up @@ -258,7 +262,7 @@ func (b *Backend) SuggestGasTipCap(baseFee *big.Int) (*big.Int, error) {
// london hardfork not enabled or feemarket not enabled
return big.NewInt(0), nil
}

// use latest queryClient to get gas info
params, err := b.queryClient.FeeMarket.Params(b.ctx, &feemarkettypes.QueryParamsRequest{})
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions rpc/backend/node_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ func (b *Backend) RPCBlockRangeCap() int32 {
// the node config. If set value is 0, it will default to 20.

func (b *Backend) RPCMinGasPrice() int64 {
// use latest queryClient to get gas price
evmParams, err := b.queryClient.Params(b.ctx, &evmtypes.QueryParamsRequest{})
if err != nil {
return ethermint.DefaultGasPrice
Expand Down
Loading