Skip to content

Commit

Permalink
Add flag & toml config for gRPC server (cosmos#6933)
Browse files Browse the repository at this point in the history
* Enable gRPC by default

* Add grpc flags

* Consistent comments in toml

* Stop grpc in test network cleaup

* Expose ports on Docker

* Fix tests

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
amaury1093 and mergify[bot] authored Aug 5, 2020
1 parent dfa0642 commit d2661a4
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ WORKDIR /root
# Copy over binaries from the build-env
COPY --from=build-env /go/bin/simd /usr/bin/simd

EXPOSE 26656 26657 1317
EXPOSE 26656 26657 1317 9090

# Run simd by default, omit entrypoint to ease using container with simcli
CMD ["simd"]
9 changes: 6 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: "3"

services:
simdnode0:
Expand All @@ -7,6 +7,7 @@ services:
ports:
- "26656-26657:26656-26657"
- "1317:1317"
- "9090:9090"
environment:
- ID=0
- LOG=${LOG:-simd.log}
Expand All @@ -22,6 +23,7 @@ services:
ports:
- "26659-26660:26656-26657"
- "1318:1317"
- "9090:9090"
environment:
- ID=1
- LOG=${LOG:-simd.log}
Expand All @@ -40,6 +42,7 @@ services:
ports:
- "26661-26662:26656-26657"
- "1319:1317"
- "9090:9090"
volumes:
- ./build:/simd:Z
networks:
Expand All @@ -55,6 +58,7 @@ services:
ports:
- "26663-26664:26656-26657"
- "1320:1317"
- "9090:9090"
volumes:
- ./build:/simd:Z
networks:
Expand All @@ -67,5 +71,4 @@ networks:
ipam:
driver: default
config:
-
subnet: 192.168.10.0/16
- subnet: 192.168.10.0/16
7 changes: 5 additions & 2 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (

const (
defaultMinGasPrices = ""

// DefaultGRPCAddress is the default address the gRPC server binds to.
DefaultGRPCAddress = "0.0.0.0:9090"
)

// BaseConfig defines the server's basic configuration
Expand Down Expand Up @@ -145,8 +148,8 @@ func DefaultConfig() *Config {
RPCMaxBodyBytes: 1000000,
},
GRPC: GRPCConfig{
Enable: false,
Address: "0.0.0.0:9090",
Enable: true,
Address: DefaultGRPCAddress,
},
}
}
Expand Down
32 changes: 22 additions & 10 deletions server/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ inter-block-cache = {{ .BaseConfig.InterBlockCache }}
[telemetry]
# Prefixed with keys to separate services
# Prefixed with keys to separate services.
service-name = "{{ .Telemetry.ServiceName }}"
# Enabled enables the application telemetry functionality. When enabled,
# an in-memory sink is also enabled by default. Operators may also enabled
# other sinks such as Prometheus.
enabled = {{ .Telemetry.Enabled }}
# Enable prefixing gauge values with hostname
# Enable prefixing gauge values with hostname.
enable-hostname = {{ .Telemetry.EnableHostname }}
# Enable adding hostname to labels
# Enable adding hostname to labels.
enable-hostname-label = {{ .Telemetry.EnableHostnameLabel }}
# Enable adding service to labels
# Enable adding service to labels.
enable-service-label = {{ .Telemetry.EnableServiceLabel }}
# PrometheusRetentionTime, when positive, enables a Prometheus metrics sink.
Expand All @@ -94,23 +94,35 @@ enable = {{ .API.Enable }}
# Swagger defines if swagger documentation should automatically be registered.
swagger = {{ .API.Swagger }}
# Address defines the API server to listen on
# Address defines the API server to listen on.
address = "{{ .API.Address }}"
# MaxOpenConnections defines the number of maximum open connections
# MaxOpenConnections defines the number of maximum open connections.
max-open-connections = {{ .API.MaxOpenConnections }}
# RPCReadTimeout defines the Tendermint RPC read timeout (in seconds)
# RPCReadTimeout defines the Tendermint RPC read timeout (in seconds).
rpc-read-timeout = {{ .API.RPCReadTimeout }}
# RPCWriteTimeout defines the Tendermint RPC write timeout (in seconds)
# RPCWriteTimeout defines the Tendermint RPC write timeout (in seconds).
rpc-write-timeout = {{ .API.RPCWriteTimeout }}
# RPCMaxBodyBytes defines the Tendermint maximum response body (in bytes)
# RPCMaxBodyBytes defines the Tendermint maximum response body (in bytes).
rpc-max-body-bytes = {{ .API.RPCMaxBodyBytes }}
# EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk)
# EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk).
enabled-unsafe-cors = {{ .API.EnableUnsafeCORS }}
###############################################################################
### gRPC Configuration ###
###############################################################################
[grpc]
# Enable defines if the gRPC server should be enabled.
enable = {{ .GRPC.Enable }}
# Address defines the gRPC server address to bind to.
address = "{{ .GRPC.Address }}"
`

var configTemplate *template.Template
Expand Down
2 changes: 1 addition & 1 deletion server/grpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (s *IntegrationTestSuite) TestGRPC() {
*bankRes.GetBalance(),
)
blockHeight := header.Get(servergrpc.GRPCBlockHeightHeader)
s.Require().NotEqual("", blockHeight[0]) // Should contain the block height
s.Require().NotEmpty(blockHeight[0]) // Should contain the block height

// Request metadata should work
bankRes, err = bankClient.Balance(
Expand Down
9 changes: 9 additions & 0 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ const (
FlagPruningInterval = "pruning-interval"
)

// GRPC-related flags.
const (
flagGRPCEnable = "grpc.enable"
flagGRPCAddress = "grpc.address"
)

// StartCmd runs the service passed in, either stand-alone or in-process with
// Tendermint.
func StartCmd(appCreator types.AppCreator, defaultNodeHome string) *cobra.Command {
Expand Down Expand Up @@ -123,6 +129,9 @@ which accepts a path for the resulting pprof file.
cmd.Flags().Uint64(FlagPruningInterval, 0, "Height interval at which pruned heights are removed from disk (ignored if pruning is not 'custom')")
cmd.Flags().Uint(FlagInvCheckPeriod, 0, "Assert registered invariants every N blocks")

cmd.Flags().Bool(flagGRPCEnable, true, "Define if the gRPC server should be enabled")
cmd.Flags().String(flagGRPCAddress, config.DefaultGRPCAddress, "the gRPC server address to listen on")

// add support for all Tendermint-specific command line options
tcmd.AddNodeFlags(cmd)
return cmd
Expand Down
9 changes: 7 additions & 2 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,11 @@ func New(t *testing.T, cfg Config) *Network {
tmCfg := ctx.Config
tmCfg.Consensus.TimeoutCommit = cfg.TimeoutCommit

// Only allow the first validator to expose an RPC and API server/client
// due to Tendermint in-process constraints.
// Only allow the first validator to expose an RPC, API and gRPC
// server/client due to Tendermint in-process constraints.
apiAddr := ""
tmCfg.RPC.ListenAddress = ""
appCfg.GRPC.Enable = false
if i == 0 {
apiListenAddr, _, err := server.FreeTCPAddr()
require.NoError(t, err)
Expand Down Expand Up @@ -439,6 +440,10 @@ func (n *Network) Cleanup() {
if v.api != nil {
_ = v.api.Close()
}

if v.grpc != nil {
v.grpc.Stop()
}
}

if n.Config.CleanupDir {
Expand Down

0 comments on commit d2661a4

Please sign in to comment.