From 558ee2678b6e549d7b1a79526cd3184d2c5420a7 Mon Sep 17 00:00:00 2001 From: bidlocode Date: Thu, 1 Oct 2020 02:55:56 +0600 Subject: [PATCH] Optional services flags (#7358) * add DisableMonitoringFlag(--disable-monitoring) to validator * add EnableRPCFlag(--rpc) to validator (now rpc and grpc-gateway disabled by default) * add DisableMonitoringFlag(--disable-monitoring) to slasher * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into optional-services-flags * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into optional-services-flags * Merge branch 'master' into optional-services-flags --- slasher/main.go | 1 + slasher/node/node.go | 7 +++++-- slasher/usage.go | 1 + validator/flags/flags.go | 6 ++++++ validator/main.go | 2 ++ validator/node/node.go | 24 +++++++++++++++--------- validator/usage.go | 2 ++ 7 files changed, 32 insertions(+), 11 deletions(-) diff --git a/slasher/main.go b/slasher/main.go index 5de54f53ab02..69d71df79407 100644 --- a/slasher/main.go +++ b/slasher/main.go @@ -51,6 +51,7 @@ var appFlags = []cli.Flag{ cmd.TraceSampleFractionFlag, cmd.MonitoringHostFlag, flags.MonitoringPortFlag, + cmd.DisableMonitoringFlag, cmd.LogFileName, cmd.LogFormat, cmd.ClearDB, diff --git a/slasher/node/node.go b/slasher/node/node.go index 9bf6627d49b5..dcd9cf6d59b4 100644 --- a/slasher/node/node.go +++ b/slasher/node/node.go @@ -85,8 +85,11 @@ func NewSlasherNode(cliCtx *cli.Context) (*SlasherNode, error) { services: registry, stop: make(chan struct{}), } - if err := slasher.registerPrometheusService(); err != nil { - return nil, err + + if !cliCtx.Bool(cmd.DisableMonitoringFlag.Name) { + if err := slasher.registerPrometheusService(); err != nil { + return nil, err + } } if err := slasher.startDB(); err != nil { diff --git a/slasher/usage.go b/slasher/usage.go index f441dff59ff8..760e5851f81a 100644 --- a/slasher/usage.go +++ b/slasher/usage.go @@ -55,6 +55,7 @@ var appHelpFlagGroups = []flagGroup{ cmd.TraceSampleFractionFlag, cmd.MonitoringHostFlag, flags.MonitoringPortFlag, + cmd.DisableMonitoringFlag, cmd.LogFormat, cmd.LogFileName, cmd.ForceClearDB, diff --git a/validator/flags/flags.go b/validator/flags/flags.go index 50241b110121..778e1a7d1920 100644 --- a/validator/flags/flags.go +++ b/validator/flags/flags.go @@ -44,6 +44,12 @@ var ( Name: "tls-cert", Usage: "Certificate for secure gRPC. Pass this and the tls-key flag in order to use gRPC securely.", } + // EnableRPCFlag enables controlling the validator client via gRPC (without web UI). + EnableRPCFlag = &cli.BoolFlag{ + Name: "rpc", + Usage: "Enables the RPC server for the validator client (without Web UI)", + Value: false, + } // RPCHost defines the host on which the RPC server should listen. RPCHost = &cli.StringFlag{ Name: "rpc-host", diff --git a/validator/main.go b/validator/main.go index 9f74a212a4e1..c6c1354f1ec5 100644 --- a/validator/main.go +++ b/validator/main.go @@ -61,6 +61,7 @@ var appFlags = []cli.Flag{ flags.UnencryptedKeysFlag, flags.InteropStartIndex, flags.InteropNumValidators, + flags.EnableRPCFlag, flags.RPCHost, flags.RPCPort, flags.GRPCGatewayPort, @@ -74,6 +75,7 @@ var appFlags = []cli.Flag{ flags.DisableAccountMetricsFlag, cmd.MonitoringHostFlag, flags.MonitoringPortFlag, + cmd.DisableMonitoringFlag, flags.SlasherRPCProviderFlag, flags.SlasherCertFlag, flags.DeprecatedPasswordsDirFlag, diff --git a/validator/node/node.go b/validator/node/node.go index 646e203f818f..f0a21cd2276c 100644 --- a/validator/node/node.go +++ b/validator/node/node.go @@ -221,8 +221,10 @@ func (s *ValidatorClient) initializeFromCLI(cliCtx *cli.Context) error { return errors.Wrap(err, "could not initialize db") } s.db = valDB - if err := s.registerPrometheusService(); err != nil { - return err + if !cliCtx.Bool(cmd.DisableMonitoringFlag.Name) { + if err := s.registerPrometheusService(); err != nil { + return err + } } if featureconfig.Get().SlasherProtection { if err := s.registerSlasherClientService(); err != nil { @@ -232,11 +234,13 @@ func (s *ValidatorClient) initializeFromCLI(cliCtx *cli.Context) error { if err := s.registerClientService(keyManagerV1, keyManagerV2); err != nil { return err } - if err := s.registerRPCService(cliCtx); err != nil { - return err - } - if err := s.registerRPCGatewayService(cliCtx); err != nil { - return err + if cliCtx.Bool(flags.EnableRPCFlag.Name) { + if err := s.registerRPCService(cliCtx); err != nil { + return err + } + if err := s.registerRPCGatewayService(cliCtx); err != nil { + return err + } } return nil } @@ -286,8 +290,10 @@ func (s *ValidatorClient) initializeForWeb(cliCtx *cli.Context) error { return errors.Wrap(err, "could not initialize db") } s.db = valDB - if err := s.registerPrometheusService(); err != nil { - return err + if !cliCtx.Bool(cmd.DisableMonitoringFlag.Name) { + if err := s.registerPrometheusService(); err != nil { + return err + } } if featureconfig.Get().SlasherProtection { if err := s.registerSlasherClientService(); err != nil { diff --git a/validator/usage.go b/validator/usage.go index ddf9712dc714..b82cde417d3d 100644 --- a/validator/usage.go +++ b/validator/usage.go @@ -56,6 +56,7 @@ var appHelpFlagGroups = []flagGroup{ cmd.TraceSampleFractionFlag, cmd.MonitoringHostFlag, flags.MonitoringPortFlag, + cmd.DisableMonitoringFlag, cmd.LogFormat, cmd.LogFileName, cmd.ConfigFileFlag, @@ -88,6 +89,7 @@ var appHelpFlagGroups = []flagGroup{ flags.DisablePenaltyRewardLogFlag, flags.UnencryptedKeysFlag, flags.GraffitiFlag, + flags.EnableRPCFlag, flags.RPCHost, flags.RPCPort, flags.GRPCGatewayPort,