Skip to content

Commit

Permalink
Problem: grpc query is not run concurrently
Browse files Browse the repository at this point in the history
Solution:
- Initiate the GRPCClient introduced in [sdk 0.46](cosmos/cosmos-sdk#11234).
  • Loading branch information
yihuang committed Sep 20, 2022
1 parent 67f1e97 commit ac729f1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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 backend blocks.go unit tests.
* (rpc) [#]() Make grape queries run concurrently.

### 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 {
_, port, err := net.SplitHostPort(config.GRPC.Address)
if err != nil {
return err
}
grpcAddress := fmt.Sprintf("127.0.0.1:%s", port)
// 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)
}
}

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

0 comments on commit ac729f1

Please sign in to comment.