moving web flag to feature (#15382)

This commit is contained in:
james-prysm
2025-06-05 14:18:54 -05:00
committed by GitHub
parent 8c324cc491
commit e569df5ebc
9 changed files with 27 additions and 20 deletions

View File

@@ -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.

View File

@@ -325,12 +325,7 @@ var (
Usage: "Skips the y/n confirmation userprompt for sending a deposit to the deposit contract.", Usage: "Skips the y/n confirmation userprompt for sending a deposit to the deposit contract.",
Value: false, 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 // SlashingProtectionExportDirFlag allows specifying the output directory
// for a validator's slashing protection history. // for a validator's slashing protection history.
SlashingProtectionExportDirFlag = &cli.StringFlag{ SlashingProtectionExportDirFlag = &cli.StringFlag{

View File

@@ -72,7 +72,6 @@ var appFlags = []cli.Flag{
flags.SlasherCertFlag, flags.SlasherCertFlag,
flags.WalletPasswordFileFlag, flags.WalletPasswordFileFlag,
flags.WalletDirFlag, flags.WalletDirFlag,
flags.EnableWebFlag,
flags.GraffitiFileFlag, flags.GraffitiFileFlag,
flags.EnableDistributed, flags.EnableDistributed,
flags.AuthTokenPathFlag, flags.AuthTokenPathFlag,

View File

@@ -136,7 +136,6 @@ var appHelpFlagGroups = []flagGroup{
{ {
Name: "misc", Name: "misc",
Flags: []cli.Flag{ Flags: []cli.Flag{
flags.EnableWebFlag,
flags.DisablePenaltyRewardLogFlag, flags.DisablePenaltyRewardLogFlag,
flags.DisableAccountMetricsFlag, flags.DisableAccountMetricsFlag,
flags.EnableDistributed, flags.EnableDistributed,

View File

@@ -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 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. EnableExperimentalAttestationPool bool // EnableExperimentalAttestationPool enables an experimental attestation pool design.
EnableDutiesV2 bool // EnableDutiesV2 sets validator client to use the get Duties V2 endpoint 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. // Logging related toggles.
DisableGRPCConnectionLogs bool // Disables logging when a new grpc client has connected. DisableGRPCConnectionLogs bool // Disables logging when a new grpc client has connected.
EnableFullSSZDataLogging bool // Enables logging for full ssz data on rejected gossip messages EnableFullSSZDataLogging bool // Enables logging for full ssz data on rejected gossip messages
@@ -339,6 +340,10 @@ func ConfigureValidator(ctx *cli.Context) error {
logEnabled(EnableDutiesV2) logEnabled(EnableDutiesV2)
cfg.EnableDutiesV2 = true cfg.EnableDutiesV2 = true
} }
if ctx.Bool(EnableWebFlag.Name) {
logEnabled(EnableWebFlag)
cfg.EnableWeb = true
}
cfg.KeystoreImportDebounceInterval = ctx.Duration(dynamicKeyReloadDebounceInterval.Name) cfg.KeystoreImportDebounceInterval = ctx.Duration(dynamicKeyReloadDebounceInterval.Name)
Init(cfg) Init(cfg)
return nil return nil

View File

@@ -194,6 +194,13 @@ var (
Name: "enable-duties-v2", Name: "enable-duties-v2",
Usage: "Forces use of get duties v2 endpoint.", 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. // devModeFlags holds list of flags that are set when development mode is on.
@@ -215,6 +222,7 @@ var ValidatorFlags = append(deprecatedFlags, []cli.Flag{
enableDoppelGangerProtection, enableDoppelGangerProtection,
EnableBeaconRESTApi, EnableBeaconRESTApi,
EnableDutiesV2, EnableDutiesV2,
EnableWebFlag,
}...) }...)
// E2EValidatorFlags contains a list of the validator feature flags to be tested in E2E. // E2EValidatorFlags contains a list of the validator feature flags to be tested in E2E.

View File

@@ -437,7 +437,7 @@ func (c *ValidatorClient) registerValidatorService(cliCtx *cli.Context) error {
Web3SignerConfig: web3signerConfig, Web3SignerConfig: web3signerConfig,
ProposerSettings: ps, ProposerSettings: ps,
ValidatorsRegBatchSize: cliCtx.Int(flags.ValidatorsRegistrationBatchSizeFlag.Name), 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), LogValidatorPerformance: !cliCtx.Bool(flags.DisablePenaltyRewardLogFlag.Name),
EmitAccountMetrics: !cliCtx.Bool(flags.DisableAccountMetricsFlag.Name), EmitAccountMetrics: !cliCtx.Bool(flags.DisableAccountMetricsFlag.Name),
Distributed: cliCtx.Bool(flags.EnableDistributed.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 { 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 { if !cliCtx.IsSet(flags.EnableRPCFlag.Name) && !serveWebUI {
return nil return nil
} }
@@ -557,7 +557,6 @@ func (c *ValidatorClient) registerRPCService(cliCtx *cli.Context) error {
AuthTokenPath: authTokenPath, AuthTokenPath: authTokenPath,
Middlewares: middlewares, Middlewares: middlewares,
Router: http.NewServeMux(), Router: http.NewServeMux(),
ServeWebUI: serveWebUI,
}) })
return c.services.RegisterService(s) return c.services.RegisterService(s)
} }

View File

@@ -13,6 +13,7 @@ import (
"strings" "strings"
"github.com/OffchainLabs/prysm/v6/api" "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/encoding/bytesutil"
"github.com/OffchainLabs/prysm/v6/io/file" "github.com/OffchainLabs/prysm/v6/io/file"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
@@ -32,7 +33,7 @@ func CreateAuthToken(authPath, validatorWebAddr string) error {
if err := saveAuthToken(authPath, token); err != nil { if err := saveAuthToken(authPath, token); err != nil {
return err return err
} }
logValidatorWebAuth(true, validatorWebAddr, token, authPath) logValidatorWebAuth(validatorWebAddr, token, authPath)
return nil return nil
} }
@@ -105,7 +106,7 @@ func (s *Server) refreshAuthTokenFromFileChanges(ctx context.Context, authTokenP
continue continue
} }
validatorWebAddr := fmt.Sprintf("%s:%d", s.httpHost, s.httpPort) 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: case err := <-watcher.Errors:
log.WithError(err).Errorf("Could not watch for file changes for: %s", authTokenPath) log.WithError(err).Errorf("Could not watch for file changes for: %s", authTokenPath)
case <-ctx.Done(): case <-ctx.Done():
@@ -114,8 +115,8 @@ func (s *Server) refreshAuthTokenFromFileChanges(ctx context.Context, authTokenP
} }
} }
func logValidatorWebAuth(useWeb bool, validatorWebAddr, token, tokenPath string) { func logValidatorWebAuth(validatorWebAddr, token, tokenPath string) {
if useWeb { if features.Get().EnableWeb {
webAuthURLTemplate := "http://%s/initialize?token=%s" webAuthURLTemplate := "http://%s/initialize?token=%s"
webAuthURL := fmt.Sprintf( webAuthURL := fmt.Sprintf(
webAuthURLTemplate, webAuthURLTemplate,

View File

@@ -13,6 +13,7 @@ import (
"github.com/OffchainLabs/prysm/v6/api/server/httprest" "github.com/OffchainLabs/prysm/v6/api/server/httprest"
"github.com/OffchainLabs/prysm/v6/api/server/middleware" "github.com/OffchainLabs/prysm/v6/api/server/middleware"
"github.com/OffchainLabs/prysm/v6/async/event" "github.com/OffchainLabs/prysm/v6/async/event"
"github.com/OffchainLabs/prysm/v6/config/features"
"github.com/OffchainLabs/prysm/v6/io/logs" "github.com/OffchainLabs/prysm/v6/io/logs"
ethpb "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1" ethpb "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1"
"github.com/OffchainLabs/prysm/v6/validator/accounts/wallet" "github.com/OffchainLabs/prysm/v6/validator/accounts/wallet"
@@ -43,12 +44,10 @@ type Config struct {
AuthTokenPath string AuthTokenPath string
Middlewares []middleware.Middleware Middlewares []middleware.Middleware
Router *http.ServeMux Router *http.ServeMux
ServeWebUI bool
} }
// Server defining a HTTP server for the remote signer API and registering clients // Server defining a HTTP server for the remote signer API and registering clients
type Server struct { type Server struct {
serveWebUI bool
walletInitialized bool walletInitialized bool
logStreamerBufferSize int logStreamerBufferSize int
grpcMaxCallRecvMsgSize int grpcMaxCallRecvMsgSize int
@@ -106,7 +105,6 @@ func NewServer(ctx context.Context, cfg *Config) *Server {
beaconApiEndpoint: cfg.BeaconApiEndpoint, beaconApiEndpoint: cfg.BeaconApiEndpoint,
beaconNodeEndpoint: cfg.BeaconNodeGRPCEndpoint, beaconNodeEndpoint: cfg.BeaconNodeGRPCEndpoint,
router: cfg.Router, router: cfg.Router,
serveWebUI: cfg.ServeWebUI,
} }
if server.authTokenPath == "" && server.walletDir != "" { 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") log.WithError(err).Error("Could not initialize web auth token")
} }
validatorWebAddr := fmt.Sprintf("%s:%d", server.httpHost, server.httpPort) 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) go server.refreshAuthTokenFromFileChanges(server.ctx, server.authTokenPath)
} }
@@ -166,7 +164,7 @@ func (s *Server) InitializeRoutesWithWebHandler() error {
s.router.ServeHTTP(w, r) s.router.ServeHTTP(w, r)
return return
} }
if s.serveWebUI { if features.Get().EnableWeb {
web.Handler(w, r) web.Handler(w, r)
} }
}) })