From e569df5ebc21dac87cbbe3bd9bfbf1dea90295a3 Mon Sep 17 00:00:00 2001 From: james-prysm <90280386+james-prysm@users.noreply.github.com> Date: Thu, 5 Jun 2025 14:18:54 -0500 Subject: [PATCH] moving web flag to feature (#15382) --- changelog/james-prysm_move-web-flag.md | 3 +++ cmd/validator/flags/flags.go | 7 +------ cmd/validator/main.go | 1 - cmd/validator/usage.go | 1 - config/features/config.go | 5 +++++ config/features/flags.go | 8 ++++++++ validator/node/node.go | 5 ++--- validator/rpc/auth_token.go | 9 +++++---- validator/rpc/server.go | 8 +++----- 9 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 changelog/james-prysm_move-web-flag.md diff --git a/changelog/james-prysm_move-web-flag.md b/changelog/james-prysm_move-web-flag.md new file mode 100644 index 0000000000..a046ee223f --- /dev/null +++ b/changelog/james-prysm_move-web-flag.md @@ -0,0 +1,3 @@ +### Ignored + +- Code cleanup by moving the web flag as a feature flag so that we don't need to pass a variable throughout the code base. \ No newline at end of file diff --git a/cmd/validator/flags/flags.go b/cmd/validator/flags/flags.go index 9d0dd6de78..9eb417e9f4 100644 --- a/cmd/validator/flags/flags.go +++ b/cmd/validator/flags/flags.go @@ -325,12 +325,7 @@ var ( Usage: "Skips the y/n confirmation userprompt for sending a deposit to the deposit contract.", Value: false, } - // EnableWebFlag enables controlling the validator client via the Prysm web ui. This is a work in progress. - EnableWebFlag = &cli.BoolFlag{ - Name: "web", - Usage: "(Work in progress): Enables the web portal for the validator client.", - Value: false, - } + // SlashingProtectionExportDirFlag allows specifying the output directory // for a validator's slashing protection history. SlashingProtectionExportDirFlag = &cli.StringFlag{ diff --git a/cmd/validator/main.go b/cmd/validator/main.go index 8995d4caff..04a138fe89 100644 --- a/cmd/validator/main.go +++ b/cmd/validator/main.go @@ -72,7 +72,6 @@ var appFlags = []cli.Flag{ flags.SlasherCertFlag, flags.WalletPasswordFileFlag, flags.WalletDirFlag, - flags.EnableWebFlag, flags.GraffitiFileFlag, flags.EnableDistributed, flags.AuthTokenPathFlag, diff --git a/cmd/validator/usage.go b/cmd/validator/usage.go index 5706c2faba..68255848f7 100644 --- a/cmd/validator/usage.go +++ b/cmd/validator/usage.go @@ -136,7 +136,6 @@ var appHelpFlagGroups = []flagGroup{ { Name: "misc", Flags: []cli.Flag{ - flags.EnableWebFlag, flags.DisablePenaltyRewardLogFlag, flags.DisableAccountMetricsFlag, flags.EnableDistributed, diff --git a/config/features/config.go b/config/features/config.go index ec5254c1ce..4d5a64cc8a 100644 --- a/config/features/config.go +++ b/config/features/config.go @@ -51,6 +51,7 @@ type Flags struct { EnableBeaconRESTApi bool // EnableBeaconRESTApi enables experimental usage of the beacon REST API by the validator when querying a beacon node EnableExperimentalAttestationPool bool // EnableExperimentalAttestationPool enables an experimental attestation pool design. EnableDutiesV2 bool // EnableDutiesV2 sets validator client to use the get Duties V2 endpoint + EnableWeb bool // EnableWeb enables the webui on the validator client // Logging related toggles. DisableGRPCConnectionLogs bool // Disables logging when a new grpc client has connected. EnableFullSSZDataLogging bool // Enables logging for full ssz data on rejected gossip messages @@ -339,6 +340,10 @@ func ConfigureValidator(ctx *cli.Context) error { logEnabled(EnableDutiesV2) cfg.EnableDutiesV2 = true } + if ctx.Bool(EnableWebFlag.Name) { + logEnabled(EnableWebFlag) + cfg.EnableWeb = true + } cfg.KeystoreImportDebounceInterval = ctx.Duration(dynamicKeyReloadDebounceInterval.Name) Init(cfg) return nil diff --git a/config/features/flags.go b/config/features/flags.go index 9c312c5bef..243de982d0 100644 --- a/config/features/flags.go +++ b/config/features/flags.go @@ -194,6 +194,13 @@ var ( Name: "enable-duties-v2", Usage: "Forces use of get duties v2 endpoint.", } + + // EnableWebFlag enables controlling the validator client via the Prysm web ui. This is a work in progress. + EnableWebFlag = &cli.BoolFlag{ + Name: "web", + Usage: "(Work in progress): Enables the web portal for the validator client.", + Value: false, + } ) // devModeFlags holds list of flags that are set when development mode is on. @@ -215,6 +222,7 @@ var ValidatorFlags = append(deprecatedFlags, []cli.Flag{ enableDoppelGangerProtection, EnableBeaconRESTApi, EnableDutiesV2, + EnableWebFlag, }...) // E2EValidatorFlags contains a list of the validator feature flags to be tested in E2E. diff --git a/validator/node/node.go b/validator/node/node.go index d0608c050b..1726494441 100644 --- a/validator/node/node.go +++ b/validator/node/node.go @@ -437,7 +437,7 @@ func (c *ValidatorClient) registerValidatorService(cliCtx *cli.Context) error { Web3SignerConfig: web3signerConfig, ProposerSettings: ps, ValidatorsRegBatchSize: cliCtx.Int(flags.ValidatorsRegistrationBatchSizeFlag.Name), - EnableAPI: cliCtx.Bool(flags.EnableWebFlag.Name) || cliCtx.Bool(flags.EnableRPCFlag.Name), + EnableAPI: features.Get().EnableWeb || cliCtx.Bool(flags.EnableRPCFlag.Name), LogValidatorPerformance: !cliCtx.Bool(flags.DisablePenaltyRewardLogFlag.Name), EmitAccountMetrics: !cliCtx.Bool(flags.DisableAccountMetricsFlag.Name), Distributed: cliCtx.Bool(flags.EnableDistributed.Name), @@ -501,7 +501,7 @@ func proposerSettings(cliCtx *cli.Context, db iface.ValidatorDB) (*proposer.Sett } func (c *ValidatorClient) registerRPCService(cliCtx *cli.Context) error { - serveWebUI := cliCtx.IsSet(flags.EnableWebFlag.Name) + serveWebUI := features.Get().EnableWeb if !cliCtx.IsSet(flags.EnableRPCFlag.Name) && !serveWebUI { return nil } @@ -557,7 +557,6 @@ func (c *ValidatorClient) registerRPCService(cliCtx *cli.Context) error { AuthTokenPath: authTokenPath, Middlewares: middlewares, Router: http.NewServeMux(), - ServeWebUI: serveWebUI, }) return c.services.RegisterService(s) } diff --git a/validator/rpc/auth_token.go b/validator/rpc/auth_token.go index 3ae87c998f..5d7d251279 100644 --- a/validator/rpc/auth_token.go +++ b/validator/rpc/auth_token.go @@ -13,6 +13,7 @@ import ( "strings" "github.com/OffchainLabs/prysm/v6/api" + "github.com/OffchainLabs/prysm/v6/config/features" "github.com/OffchainLabs/prysm/v6/encoding/bytesutil" "github.com/OffchainLabs/prysm/v6/io/file" "github.com/fsnotify/fsnotify" @@ -32,7 +33,7 @@ func CreateAuthToken(authPath, validatorWebAddr string) error { if err := saveAuthToken(authPath, token); err != nil { return err } - logValidatorWebAuth(true, validatorWebAddr, token, authPath) + logValidatorWebAuth(validatorWebAddr, token, authPath) return nil } @@ -105,7 +106,7 @@ func (s *Server) refreshAuthTokenFromFileChanges(ctx context.Context, authTokenP continue } validatorWebAddr := fmt.Sprintf("%s:%d", s.httpHost, s.httpPort) - logValidatorWebAuth(s.serveWebUI, validatorWebAddr, s.authToken, authTokenPath) + logValidatorWebAuth(validatorWebAddr, s.authToken, authTokenPath) case err := <-watcher.Errors: log.WithError(err).Errorf("Could not watch for file changes for: %s", authTokenPath) case <-ctx.Done(): @@ -114,8 +115,8 @@ func (s *Server) refreshAuthTokenFromFileChanges(ctx context.Context, authTokenP } } -func logValidatorWebAuth(useWeb bool, validatorWebAddr, token, tokenPath string) { - if useWeb { +func logValidatorWebAuth(validatorWebAddr, token, tokenPath string) { + if features.Get().EnableWeb { webAuthURLTemplate := "http://%s/initialize?token=%s" webAuthURL := fmt.Sprintf( webAuthURLTemplate, diff --git a/validator/rpc/server.go b/validator/rpc/server.go index 15a4dbb2c1..5e9b4da703 100644 --- a/validator/rpc/server.go +++ b/validator/rpc/server.go @@ -13,6 +13,7 @@ import ( "github.com/OffchainLabs/prysm/v6/api/server/httprest" "github.com/OffchainLabs/prysm/v6/api/server/middleware" "github.com/OffchainLabs/prysm/v6/async/event" + "github.com/OffchainLabs/prysm/v6/config/features" "github.com/OffchainLabs/prysm/v6/io/logs" ethpb "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1" "github.com/OffchainLabs/prysm/v6/validator/accounts/wallet" @@ -43,12 +44,10 @@ type Config struct { AuthTokenPath string Middlewares []middleware.Middleware Router *http.ServeMux - ServeWebUI bool } // Server defining a HTTP server for the remote signer API and registering clients type Server struct { - serveWebUI bool walletInitialized bool logStreamerBufferSize int grpcMaxCallRecvMsgSize int @@ -106,7 +105,6 @@ func NewServer(ctx context.Context, cfg *Config) *Server { beaconApiEndpoint: cfg.BeaconApiEndpoint, beaconNodeEndpoint: cfg.BeaconNodeGRPCEndpoint, router: cfg.Router, - serveWebUI: cfg.ServeWebUI, } if server.authTokenPath == "" && server.walletDir != "" { @@ -119,7 +117,7 @@ func NewServer(ctx context.Context, cfg *Config) *Server { log.WithError(err).Error("Could not initialize web auth token") } validatorWebAddr := fmt.Sprintf("%s:%d", server.httpHost, server.httpPort) - logValidatorWebAuth(server.serveWebUI, validatorWebAddr, server.authToken, server.authTokenPath) + logValidatorWebAuth(validatorWebAddr, server.authToken, server.authTokenPath) go server.refreshAuthTokenFromFileChanges(server.ctx, server.authTokenPath) } @@ -166,7 +164,7 @@ func (s *Server) InitializeRoutesWithWebHandler() error { s.router.ServeHTTP(w, r) return } - if s.serveWebUI { + if features.Get().EnableWeb { web.Handler(w, r) } })