Skip to content

Commit

Permalink
Merge pull request #232 from scrtlabs/grpc-concurrency-fix
Browse files Browse the repository at this point in the history
Fixed GRPC gateway concurrency. Set default to enabled
  • Loading branch information
Cashmaney authored Nov 10, 2022
2 parents 75c9cbc + 16f6f8f commit ae915c4
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 39 deletions.
5 changes: 0 additions & 5 deletions client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ func ReadPersistentCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Cont
clientCtx = clientCtx.WithSimulation(dryRun)
}

if !clientCtx.GRPCConcurrency || flagSet.Changed(flags.FlagGRPCConcurrency) {
grpcConcurrency, _ := flagSet.GetBool(flags.FlagGRPCConcurrency)
clientCtx = clientCtx.WithConcurrency(grpcConcurrency)
}

if clientCtx.KeyringDir == "" || flagSet.Changed(flags.FlagKeyringDir) {
keyringDir, _ := flagSet.GetString(flags.FlagKeyringDir)

Expand Down
9 changes: 1 addition & 8 deletions client/config/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package config
import (
"encoding/json"
"fmt"
"github.com/spf13/cobra"
tmcli "github.com/tendermint/tendermint/libs/cli"
"path/filepath"
"strconv"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand Down Expand Up @@ -80,8 +78,6 @@ func runConfigCmd(cmd *cobra.Command, args []string) error {
cmd.Println(conf.Node)
case flags.FlagBroadcastMode:
cmd.Println(conf.BroadcastMode)
case flags.FlagGRPCConcurrency:
cmd.Println(conf.GRPCConcurrency)
default:
err := errUnknownConfigKey(key)
return fmt.Errorf("couldn't get the value for the key: %v, error: %v", key, err)
Expand All @@ -102,9 +98,6 @@ func runConfigCmd(cmd *cobra.Command, args []string) error {
conf.SetNode(value)
case flags.FlagBroadcastMode:
conf.SetBroadcastMode(value)
case flags.FlagGRPCConcurrency:
valuebool, _ := strconv.ParseBool(value)
conf.SetGRPCConcurrency(valuebool)
default:
return errUnknownConfigKey(key)
}
Expand Down
29 changes: 11 additions & 18 deletions client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,30 @@ import (

// Default constants
const (
chainID = ""
keyringBackend = "os"
output = "text"
node = "tcp://localhost:26657"
broadcastMode = "sync"
grpcConcurrency = false
chainID = ""
keyringBackend = "os"
output = "text"
node = "tcp://localhost:26657"
broadcastMode = "sync"
)

type ClientConfig struct {
ChainID string `mapstructure:"chain-id" json:"chain-id"`
KeyringBackend string `mapstructure:"keyring-backend" json:"keyring-backend"`
Output string `mapstructure:"output" json:"output"`
Node string `mapstructure:"node" json:"node"`
BroadcastMode string `mapstructure:"broadcast-mode" json:"broadcast-mode"`
GRPCConcurrency bool `mapstructure:"grpc-concurrency" json:"grpc-concurrency"`
ChainID string `mapstructure:"chain-id" json:"chain-id"`
KeyringBackend string `mapstructure:"keyring-backend" json:"keyring-backend"`
Output string `mapstructure:"output" json:"output"`
Node string `mapstructure:"node" json:"node"`
BroadcastMode string `mapstructure:"broadcast-mode" json:"broadcast-mode"`
}

// defaultClientConfig returns the reference to ClientConfig with default values.
func defaultClientConfig() *ClientConfig {
return &ClientConfig{chainID, keyringBackend, output, node,
broadcastMode, grpcConcurrency}
return &ClientConfig{chainID, keyringBackend, output, node, broadcastMode}
}

func (c *ClientConfig) SetChainID(chainID string) {
c.ChainID = chainID
}

func (c *ClientConfig) SetGRPCConcurrency(grpcConcurrency bool) {
c.GRPCConcurrency = grpcConcurrency
}

func (c *ClientConfig) SetKeyringBackend(keyringBackend string) {
c.KeyringBackend = keyringBackend
}
Expand Down
4 changes: 0 additions & 4 deletions client/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ output = "{{ .Output }}"
node = "{{ .Node }}"
# Transaction broadcasting mode (sync|async|block)
broadcast-mode = "{{ .BroadcastMode }}"
# Concurrency defines if node queries should be done in parallel.
# This is experimental and has led to node failures, so enable with caution.
# The default value is false.
grpc-concurrency = {{ .GRPCConcurrency }}
`

// writeConfigToFile parses defaultConfigTemplate, renders config using the template and writes it to
Expand Down
1 change: 0 additions & 1 deletion client/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ const (
FlagKeyAlgorithm = "algo"
FlagFeeAccount = "fee-account"
FlagReverse = "reverse"
FlagGRPCConcurrency = "grpc-concurrency"

// Tendermint logging flags
FlagLogLevel = "log_level"
Expand Down
10 changes: 8 additions & 2 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ type GRPCConfig struct {
// MaxSendMsgSize defines the max message size in bytes the server can send.
// The default value is math.MaxInt32.
MaxSendMsgSize int `mapstructure:"max-send-msg-size"`

Concurrency bool `mapstructure:"concurrency"`
}

// GRPCWebConfig defines configuration for the gRPC-web server.
Expand Down Expand Up @@ -252,6 +254,7 @@ func DefaultConfig() *Config {
Address: DefaultGRPCAddress,
MaxRecvMsgSize: DefaultGRPCMaxRecvMsgSize,
MaxSendMsgSize: DefaultGRPCMaxSendMsgSize,
Concurrency: true,
},
Rosetta: RosettaConfig{
Enable: false,
Expand Down Expand Up @@ -333,8 +336,11 @@ func GetConfig(v *viper.Viper) (Config, error) {
Offline: v.GetBool("rosetta.offline"),
},
GRPC: GRPCConfig{
Enable: v.GetBool("grpc.enable"),
Address: v.GetString("grpc.address"),
Enable: v.GetBool("grpc.enable"),
Address: v.GetString("grpc.address"),
MaxRecvMsgSize: v.GetInt("grpc.max-recv-msg-size"),
MaxSendMsgSize: v.GetInt("grpc.max-send-msg-size"),
Concurrency: v.GetBool("grpc.concurrency"),
},
GRPCWeb: GRPCWebConfig{
Enable: v.GetBool("grpc-web.enable"),
Expand Down
11 changes: 11 additions & 0 deletions server/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ enable = {{ .GRPC.Enable }}
# Address defines the gRPC server address to bind to.
address = "{{ .GRPC.Address }}"
# The default value is math.MaxInt32.
max-recv-msg-size = "{{ .GRPC.MaxRecvMsgSize }}"
# The default value is math.MaxInt32.
max-send-msg-size = "{{ .GRPC.MaxSendMsgSize }}"
# Concurrency defines if node queries should be done in parallel.
# This is experimental and has led to node failures, so enable with caution.
# The default value is false.
concurrency = {{ .GRPC.Concurrency }}
###############################################################################
### gRPC Web Configuration ###
###############################################################################
Expand Down
6 changes: 5 additions & 1 deletion server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
return err
}

config, err := config.GetConfig(ctx.Viper)
config, err := serverconfig.GetConfig(ctx.Viper)
if err != nil {
return err
}
Expand Down Expand Up @@ -315,6 +315,10 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
}
}

if config.GRPC.Concurrency {
clientCtx = clientCtx.WithConcurrency(true)
}

var apiSrv *api.Server
if config.API.Enable {
genDoc, err := genDocProvider()
Expand Down

0 comments on commit ae915c4

Please sign in to comment.