From cfa1764f4d98581a4c45c4467784033bef172cbd Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 4 Aug 2020 15:02:43 +0200 Subject: [PATCH 1/6] Enable gRPC by default --- server/config/config.go | 2 +- server/config/toml.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/server/config/config.go b/server/config/config.go index 801aaa06d0ab..84c080d94b66 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -145,7 +145,7 @@ func DefaultConfig() *Config { RPCMaxBodyBytes: 1000000, }, GRPC: GRPCConfig{ - Enable: false, + Enable: true, Address: "0.0.0.0:9090", }, } diff --git a/server/config/toml.go b/server/config/toml.go index 31fe268ec29e..4555ab663c2e 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -111,6 +111,18 @@ rpc-max-body-bytes = {{ .API.RPCMaxBodyBytes }} # 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 API server should be enabled. +enable = {{ .GRPC.Enable }} + +# Address defines the API server to listen on +address = "{{ .GRPC.Address }}" ` var configTemplate *template.Template From 249eb79bc82f6f9131605633a06013b84ec9dc4f Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 5 Aug 2020 14:41:01 +0200 Subject: [PATCH 2/6] Add grpc flags --- server/config/config.go | 5 ++++- server/config/toml.go | 6 +++--- server/grpc/server_test.go | 2 +- server/start.go | 9 +++++++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/server/config/config.go b/server/config/config.go index 84c080d94b66..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 @@ -146,7 +149,7 @@ func DefaultConfig() *Config { }, GRPC: GRPCConfig{ Enable: true, - Address: "0.0.0.0:9090", + Address: DefaultGRPCAddress, }, } } diff --git a/server/config/toml.go b/server/config/toml.go index 4555ab663c2e..1e7908df6c09 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -113,15 +113,15 @@ rpc-max-body-bytes = {{ .API.RPCMaxBodyBytes }} enabled-unsafe-cors = {{ .API.EnableUnsafeCORS }} ############################################################################### -### GRPC Configuration ### +### gRPC Configuration ### ############################################################################### [grpc] -# Enable defines if the API server should be enabled. +# Enable defines if the gRPC server should be enabled. enable = {{ .GRPC.Enable }} -# Address defines the API server to listen on +# Address defines the gRPC server address to bind to. address = "{{ .GRPC.Address }}" ` 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 From b49552b811b9f48f2fe4d8d2a302775f8b4cc749 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 5 Aug 2020 14:45:01 +0200 Subject: [PATCH 3/6] Consistent comments in toml --- server/config/toml.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/server/config/toml.go b/server/config/toml.go index 1e7908df6c09..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,22 +94,22 @@ 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 }} ############################################################################### From 09694a25187517769175af178b5a3cf3294195cf Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 5 Aug 2020 15:24:47 +0200 Subject: [PATCH 4/6] Stop grpc in test network cleaup --- testutil/network/network.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/testutil/network/network.go b/testutil/network/network.go index 2f87aa0435a7..32b239fd0cec 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -439,6 +439,10 @@ func (n *Network) Cleanup() { if v.api != nil { _ = v.api.Close() } + + if v.grpc != nil { + v.grpc.Stop() + } } if n.Config.CleanupDir { From b024541ed24d7121573b879802c0d955e5ac1175 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 5 Aug 2020 16:41:37 +0200 Subject: [PATCH 5/6] Expose ports on Docker --- Dockerfile | 2 +- docker-compose.yml | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4f836543f5d9..28f83f5fe33b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,7 +39,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 From 721c73bc3672a5a95a8c6b2e3dc07464fed5824f Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 5 Aug 2020 17:25:52 +0200 Subject: [PATCH 6/6] Fix tests --- testutil/network/network.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/testutil/network/network.go b/testutil/network/network.go index 32b239fd0cec..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)