Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

imp(rpc,server): concurrent gRPC queries #1352

Merged
merged 9 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -59,6 +59,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (test) [#1311](https://github.com/evmos/ethermint/pull/1311) Add integration test for the `rollback` cmd
* (ledger) [#1277](https://github.com/evmos/ethermint/pull/1277) Add Ledger preprocessing transaction hook for EIP-712-signed Cosmos payloads.
* (rpc) [#1296](https://github.com/evmos/ethermint/pull/1296) Add RPC Backend unit tests.
* (rpc) [#1352](https://github.com/evmos/ethermint/pull/1352) Make the grpc queries run concurrently, don't block the consensus state machine.

### Bug Fixes

Expand Down
30 changes: 27 additions & 3 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"net"
"net/http"
"os"
"path/filepath"
Expand All @@ -17,6 +18,7 @@ import (
"github.com/spf13/cobra"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

abciserver "github.com/tendermint/tendermint/abci/server"
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
Expand Down Expand Up @@ -363,17 +365,39 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty
}
}

var apiSrv *api.Server
if config.API.Enable {
if config.API.Enable || config.JSONRPC.Enable {
genDoc, err := genDocProvider()
if err != nil {
return err
}

clientCtx := clientCtx.
clientCtx = clientCtx.
WithHomeDir(home).
WithChainID(genDoc.ChainID)

// Set `GRPCClient` to `clientCtx` to enjoy concurrent grpc query.
if config.GRPC.Enable {
yihuang marked this conversation as resolved.
Show resolved Hide resolved
_, port, err := net.SplitHostPort(config.GRPC.Address)
if err != nil {
return err
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
}
grpcAddress := fmt.Sprintf("127.0.0.1:%s", port)
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
// If grpc is enabled, configure grpc client for grpc gateway and json-rpc.
grpcClient, err := grpc.Dial(
grpcAddress,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithDefaultCallOptions(grpc.ForceCodec(codec.NewProtoCodec(clientCtx.InterfaceRegistry).GRPCCodec())),
)
if err != nil {
return err
}
clientCtx = clientCtx.WithGRPCClient(grpcClient)
ctx.Logger.Debug("grpc client assigned to client context", "target", grpcAddress)
yihuang marked this conversation as resolved.
Show resolved Hide resolved
}
}

var apiSrv *api.Server
if config.API.Enable {
apiSrv = api.New(clientCtx, ctx.Logger.With("server", "api"))
app.RegisterAPIRoutes(apiSrv, config.API)
errCh := make(chan error)
Expand Down