Skip to content

Commit

Permalink
Problem: subscription refactoring not merged (#375)
Browse files Browse the repository at this point in the history
* Problem: internal websocket connection is heavy and unstable (#373)

* Problem: internal websocket connection is heavy and unstable

Solution:
- use local node client directly.

* ignore duplicate subscriptions, it's possible in concurrency

* bigger start timeout

* handle error

* fix lint

* fix unit test

* rename

* fix test

* remove test

* add buffer

* Problem: channels are not efficient for broadcasting scenario (#374)

* implement stream

* rpc stream

* websocket use stream

* filter apis use stream

* cleanup

* move modules

* cleanup

* fix cond race

* fix lint

* nit

* fix build

* fix lint

* err return

* fix empty logs

* fix filter initial offset

* fix filter

* fix filter

* fix test

* changelog

* add comments
  • Loading branch information
yihuang authored Nov 14, 2023
1 parent b9078ab commit 8b1ec23
Show file tree
Hide file tree
Showing 18 changed files with 1,085 additions and 1,067 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (evm) [#343](https://github.com/crypto-org-chain/ethermint/pull/343) Add native event converter APIs.
- (ante) [#353](https://github.com/crypto-org-chain/ethermint/pull/353) Remove blocked address decorator and support custom decorators instead.
- (statedb) [#359](https://github.com/crypto-org-chain/ethermint/pull/359) Add `CacheContext` method to StateDB, to support efficient read-only native actions.
- (rpc) [#375](https://github.com/crypto-org-chain/ethermint/pull/375) Refactor websocket/subscription system to improve performance and stability.

## [v0.21.0] - 2023-01-26

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ test-import:
go test -run TestImporterTestSuite -v --vet=off github.com/evmos/ethermint/tests/importer

test-rpc:
./scripts/integration-test-all.sh -t "rpc" -q 1 -z 1 -s 2 -m "rpc" -r "true"
./scripts/integration-test-all.sh -t "rpc" -q 1 -z 1 -s 5 -m "rpc" -r "true"

run-integration-tests:
@nix-shell ./tests/integration_tests/shell.nix --run ./scripts/run-integration-tests.sh
Expand Down
25 changes: 12 additions & 13 deletions rpc/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ import (
"github.com/evmos/ethermint/rpc/namespaces/ethereum/personal"
"github.com/evmos/ethermint/rpc/namespaces/ethereum/txpool"
"github.com/evmos/ethermint/rpc/namespaces/ethereum/web3"
"github.com/evmos/ethermint/rpc/stream"
ethermint "github.com/evmos/ethermint/types"

rpcclient "github.com/cometbft/cometbft/rpc/jsonrpc/client"
)

// RPC namespaces and API version
Expand All @@ -60,7 +59,7 @@ const (
type APICreator = func(
ctx *server.Context,
clientCtx client.Context,
tendermintWebsocketClient *rpcclient.WSClient,
stream *stream.RPCStream,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
) []rpc.API
Expand All @@ -72,7 +71,7 @@ func init() {
apiCreators = map[string]APICreator{
EthNamespace: func(ctx *server.Context,
clientCtx client.Context,
tmWSClient *rpcclient.WSClient,
stream *stream.RPCStream,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
) []rpc.API {
Expand All @@ -87,12 +86,12 @@ func init() {
{
Namespace: EthNamespace,
Version: apiVersion,
Service: filters.NewPublicAPI(ctx.Logger, clientCtx, tmWSClient, evmBackend),
Service: filters.NewPublicAPI(ctx.Logger, clientCtx, stream, evmBackend),
Public: true,
},
}
},
Web3Namespace: func(*server.Context, client.Context, *rpcclient.WSClient, bool, ethermint.EVMTxIndexer) []rpc.API {
Web3Namespace: func(*server.Context, client.Context, *stream.RPCStream, bool, ethermint.EVMTxIndexer) []rpc.API {
return []rpc.API{
{
Namespace: Web3Namespace,
Expand All @@ -102,7 +101,7 @@ func init() {
},
}
},
NetNamespace: func(_ *server.Context, clientCtx client.Context, _ *rpcclient.WSClient, _ bool, _ ethermint.EVMTxIndexer) []rpc.API {
NetNamespace: func(_ *server.Context, clientCtx client.Context, _ *stream.RPCStream, _ bool, _ ethermint.EVMTxIndexer) []rpc.API {
return []rpc.API{
{
Namespace: NetNamespace,
Expand All @@ -114,7 +113,7 @@ func init() {
},
PersonalNamespace: func(ctx *server.Context,
clientCtx client.Context,
_ *rpcclient.WSClient,
_ *stream.RPCStream,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
) []rpc.API {
Expand All @@ -128,7 +127,7 @@ func init() {
},
}
},
TxPoolNamespace: func(ctx *server.Context, _ client.Context, _ *rpcclient.WSClient, _ bool, _ ethermint.EVMTxIndexer) []rpc.API {
TxPoolNamespace: func(ctx *server.Context, _ client.Context, _ *stream.RPCStream, _ bool, _ ethermint.EVMTxIndexer) []rpc.API {
return []rpc.API{
{
Namespace: TxPoolNamespace,
Expand All @@ -140,7 +139,7 @@ func init() {
},
DebugNamespace: func(ctx *server.Context,
clientCtx client.Context,
_ *rpcclient.WSClient,
_ *stream.RPCStream,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
) []rpc.API {
Expand All @@ -156,7 +155,7 @@ func init() {
},
MinerNamespace: func(ctx *server.Context,
clientCtx client.Context,
_ *rpcclient.WSClient,
_ *stream.RPCStream,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
) []rpc.API {
Expand All @@ -176,7 +175,7 @@ func init() {
// GetRPCAPIs returns the list of all APIs
func GetRPCAPIs(ctx *server.Context,
clientCtx client.Context,
tmWSClient *rpcclient.WSClient,
stream *stream.RPCStream,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
selectedAPIs []string,
Expand All @@ -185,7 +184,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, stream, allowUnprotectedTxs, indexer)...)
} else {
ctx.Logger.Error("invalid namespace value", "namespace", ns)
}
Expand Down
Loading

0 comments on commit 8b1ec23

Please sign in to comment.