diff --git a/Dockerfile b/Dockerfile index ef79b4585261..ed7762a1c115 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/docker-compose.yml b/docker-compose.yml index 7e7ce18cbc8b..ce93ce58750a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3' +version: "3" services: simdnode0: @@ -7,6 +7,7 @@ services: ports: - "26656-26657:26656-26657" - "1317:1317" + - "9090:9090" environment: - ID=0 - LOG=${LOG:-simd.log} @@ -22,6 +23,7 @@ services: ports: - "26659-26660:26656-26657" - "1318:1317" + - "9090:9090" environment: - ID=1 - LOG=${LOG:-simd.log} @@ -40,6 +42,7 @@ services: ports: - "26661-26662:26656-26657" - "1319:1317" + - "9090:9090" volumes: - ./build:/simd:Z networks: @@ -55,6 +58,7 @@ services: ports: - "26663-26664:26656-26657" - "1320:1317" + - "9090:9090" volumes: - ./build:/simd:Z networks: @@ -67,5 +71,4 @@ networks: ipam: driver: default config: - - - subnet: 192.168.10.0/16 + - subnet: 192.168.10.0/16 diff --git a/server/config/config.go b/server/config/config.go index 801aaa06d0ab..e57594290f6e 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -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 @@ -145,8 +148,8 @@ func DefaultConfig() *Config { RPCMaxBodyBytes: 1000000, }, GRPC: GRPCConfig{ - Enable: false, - Address: "0.0.0.0:9090", + Enable: true, + Address: DefaultGRPCAddress, }, } } diff --git a/server/config/toml.go b/server/config/toml.go index 31fe268ec29e..5eb71184ef18 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -53,7 +53,7 @@ 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, @@ -61,13 +61,13 @@ service-name = "{{ .Telemetry.ServiceName }}" # 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. @@ -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 diff --git a/server/grpc/server_test.go b/server/grpc/server_test.go index b2806e9b6e44..8e6ab335e174 100644 --- a/server/grpc/server_test.go +++ b/server/grpc/server_test.go @@ -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( diff --git a/server/start.go b/server/start.go index 810080f6f7f2..64dba2d3c6c6 100644 --- a/server/start.go +++ b/server/start.go @@ -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 { @@ -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 diff --git a/testutil/network/network.go b/testutil/network/network.go index 2f87aa0435a7..5e6c2f5d87d1 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -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) @@ -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 {