upgrade to ethermint v0.21.0 #99

Closed
0xmuralik wants to merge 384 commits from murali/update-fork into main
3 changed files with 70 additions and 50 deletions
Showing only changes of commit 0543a28941 - Show all commits

View File

@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements ### Improvements
* (deps) [tharsis#1046](https://github.com/tharsis/ethermint/pull/1046) Bump Cosmos SDK version to [`v0.45.3`](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.3) * (deps) [tharsis#1046](https://github.com/tharsis/ethermint/pull/1046) Bump Cosmos SDK version to [`v0.45.3`](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.3)
* (rpc) [tharsis#1056](https://github.com/tharsis/ethermint/pull/1056) Make json-rpc namespaces extensible
### Bug Fixes ### Bug Fixes

View File

@ -3,6 +3,8 @@
package rpc package rpc
import ( import (
"fmt"
"github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server"
@ -35,102 +37,119 @@ const (
apiVersion = "1.0" apiVersion = "1.0"
) )
// GetRPCAPIs returns the list of all APIs // APICreator creates the json-rpc api implementations.
func GetRPCAPIs(ctx *server.Context, clientCtx client.Context, tmWSClient *rpcclient.WSClient, selectedAPIs []string) []rpc.API { type APICreator = func(*server.Context, client.Context, *rpcclient.WSClient) []rpc.API
// apiCreators defines the json-rpc api namespaces.
var apiCreators map[string]APICreator
func init() {
apiCreators = map[string]APICreator{
EthNamespace: func(ctx *server.Context, clientCtx client.Context, tmWSClient *rpcclient.WSClient) []rpc.API {
nonceLock := new(types.AddrLocker) nonceLock := new(types.AddrLocker)
evmBackend := backend.NewEVMBackend(ctx, ctx.Logger, clientCtx) evmBackend := backend.NewEVMBackend(ctx, ctx.Logger, clientCtx)
return []rpc.API{
var apis []rpc.API {
// remove duplicates
selectedAPIs = unique(selectedAPIs)
for index := range selectedAPIs {
switch selectedAPIs[index] {
case EthNamespace:
apis = append(apis,
rpc.API{
Namespace: EthNamespace, Namespace: EthNamespace,
Version: apiVersion, Version: apiVersion,
Service: eth.NewPublicAPI(ctx.Logger, clientCtx, evmBackend, nonceLock), Service: eth.NewPublicAPI(ctx.Logger, clientCtx, evmBackend, nonceLock),
Public: true, Public: true,
}, },
rpc.API{ {
Namespace: EthNamespace, Namespace: EthNamespace,
Version: apiVersion, Version: apiVersion,
Service: filters.NewPublicAPI(ctx.Logger, clientCtx, tmWSClient, evmBackend), Service: filters.NewPublicAPI(ctx.Logger, clientCtx, tmWSClient, evmBackend),
Public: true, Public: true,
}, },
) }
case Web3Namespace: },
apis = append(apis, Web3Namespace: func(*server.Context, client.Context, *rpcclient.WSClient) []rpc.API {
rpc.API{ return []rpc.API{
{
Namespace: Web3Namespace, Namespace: Web3Namespace,
Version: apiVersion, Version: apiVersion,
Service: web3.NewPublicAPI(), Service: web3.NewPublicAPI(),
Public: true, Public: true,
}, },
) }
case NetNamespace: },
apis = append(apis, NetNamespace: func(_ *server.Context, clientCtx client.Context, _ *rpcclient.WSClient) []rpc.API {
rpc.API{ return []rpc.API{
{
Namespace: NetNamespace, Namespace: NetNamespace,
Version: apiVersion, Version: apiVersion,
Service: net.NewPublicAPI(clientCtx), Service: net.NewPublicAPI(clientCtx),
Public: true, Public: true,
}, },
) }
case PersonalNamespace: },
apis = append(apis, PersonalNamespace: func(ctx *server.Context, clientCtx client.Context, _ *rpcclient.WSClient) []rpc.API {
rpc.API{ evmBackend := backend.NewEVMBackend(ctx, ctx.Logger, clientCtx)
return []rpc.API{
{
Namespace: PersonalNamespace, Namespace: PersonalNamespace,
Version: apiVersion, Version: apiVersion,
Service: personal.NewAPI(ctx.Logger, clientCtx, evmBackend), Service: personal.NewAPI(ctx.Logger, clientCtx, evmBackend),
Public: false, Public: false,
}, },
) }
case TxPoolNamespace: },
apis = append(apis, TxPoolNamespace: func(ctx *server.Context, _ client.Context, _ *rpcclient.WSClient) []rpc.API {
rpc.API{ return []rpc.API{
{
Namespace: TxPoolNamespace, Namespace: TxPoolNamespace,
Version: apiVersion, Version: apiVersion,
Service: txpool.NewPublicAPI(ctx.Logger), Service: txpool.NewPublicAPI(ctx.Logger),
Public: true, Public: true,
}, },
) }
case DebugNamespace: },
apis = append(apis, DebugNamespace: func(ctx *server.Context, clientCtx client.Context, _ *rpcclient.WSClient) []rpc.API {
rpc.API{ evmBackend := backend.NewEVMBackend(ctx, ctx.Logger, clientCtx)
return []rpc.API{
{
Namespace: DebugNamespace, Namespace: DebugNamespace,
Version: apiVersion, Version: apiVersion,
Service: debug.NewAPI(ctx, evmBackend, clientCtx), Service: debug.NewAPI(ctx, evmBackend, clientCtx),
Public: true, Public: true,
}, },
) }
case MinerNamespace: },
apis = append(apis, MinerNamespace: func(ctx *server.Context, clientCtx client.Context, _ *rpcclient.WSClient) []rpc.API {
rpc.API{ evmBackend := backend.NewEVMBackend(ctx, ctx.Logger, clientCtx)
return []rpc.API{
{
Namespace: MinerNamespace, Namespace: MinerNamespace,
Version: apiVersion, Version: apiVersion,
Service: miner.NewPrivateAPI(ctx, clientCtx, evmBackend), Service: miner.NewPrivateAPI(ctx, clientCtx, evmBackend),
Public: false, Public: false,
}, },
) }
default: },
ctx.Logger.Error("invalid namespace value", "namespace", selectedAPIs[index]) }
}
// GetRPCAPIs returns the list of all APIs
func GetRPCAPIs(ctx *server.Context, clientCtx client.Context, tmWSClient *rpcclient.WSClient, selectedAPIs []string) []rpc.API {
var apis []rpc.API
for _, ns := range selectedAPIs {
if creator, ok := apiCreators[ns]; ok {
apis = append(apis, creator(ctx, clientCtx, tmWSClient)...)
} else {
ctx.Logger.Error("invalid namespace value", "namespace", ns)
} }
} }
return apis return apis
} }
func unique(intSlice []string) []string { // RegisterAPINamespace registers a new API namespace with the API creator.
keys := make(map[string]bool) // This function fails if the namespace is already registered.
var list []string func RegisterAPINamespace(ns string, creator APICreator) error {
for _, entry := range intSlice { if _, ok := apiCreators[ns]; ok {
if _, value := keys[entry]; !value { return fmt.Errorf("duplicated api namespace %s", ns)
keys[entry] = true
list = append(list, entry)
} }
} apiCreators[ns] = creator
return list return nil
} }

View File

@ -237,7 +237,7 @@ func (c JSONRPCConfig) Validate() error {
return errors.New("JSON-RPC HTTP idle timeout duration cannot be negative") return errors.New("JSON-RPC HTTP idle timeout duration cannot be negative")
} }
// TODO: validate APIs // check for duplicates
seenAPIs := make(map[string]bool) seenAPIs := make(map[string]bool)
for _, api := range c.API { for _, api := range c.API {
if seenAPIs[api] { if seenAPIs[api] {