github.com/ethereum-optimism/optimism@v1.7.2/op-node/flags/flags.go (about)

     1  package flags
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"github.com/urfave/cli/v2"
     8  
     9  	"github.com/ethereum-optimism/optimism/op-node/rollup/sync"
    10  	plasma "github.com/ethereum-optimism/optimism/op-plasma"
    11  	openum "github.com/ethereum-optimism/optimism/op-service/enum"
    12  	opflags "github.com/ethereum-optimism/optimism/op-service/flags"
    13  	oplog "github.com/ethereum-optimism/optimism/op-service/log"
    14  	"github.com/ethereum-optimism/optimism/op-service/oppprof"
    15  	"github.com/ethereum-optimism/optimism/op-service/sources"
    16  )
    17  
    18  // Flags
    19  
    20  const EnvVarPrefix = "OP_NODE"
    21  
    22  const (
    23  	RollupCategory     = "1. ROLLUP"
    24  	L1RPCCategory      = "2. L1 RPC"
    25  	SequencerCategory  = "3. SEQUENCER"
    26  	OperationsCategory = "4. LOGGING, METRICS, DEBUGGING, AND API"
    27  	P2PCategory        = "5. PEER-TO-PEER"
    28  	PlasmaCategory     = "6. PLASMA (EXPERIMENTAL)"
    29  	MiscCategory       = "7. MISC"
    30  )
    31  
    32  func init() {
    33  	cli.HelpFlag.(*cli.BoolFlag).Category = MiscCategory
    34  	cli.VersionFlag.(*cli.BoolFlag).Category = MiscCategory
    35  }
    36  
    37  func prefixEnvVars(name string) []string {
    38  	return []string{EnvVarPrefix + "_" + name}
    39  }
    40  
    41  var (
    42  	/* Required Flags */
    43  	L1NodeAddr = &cli.StringFlag{
    44  		Name:     "l1",
    45  		Usage:    "Address of L1 User JSON-RPC endpoint to use (eth namespace required)",
    46  		Value:    "http://127.0.0.1:8545",
    47  		EnvVars:  prefixEnvVars("L1_ETH_RPC"),
    48  		Category: RollupCategory,
    49  	}
    50  	L2EngineAddr = &cli.StringFlag{
    51  		Name:     "l2",
    52  		Usage:    "Address of L2 Engine JSON-RPC endpoints to use (engine and eth namespace required)",
    53  		EnvVars:  prefixEnvVars("L2_ENGINE_RPC"),
    54  		Category: RollupCategory,
    55  	}
    56  	L2EngineJWTSecret = &cli.StringFlag{
    57  		Name:        "l2.jwt-secret",
    58  		Usage:       "Path to JWT secret key. Keys are 32 bytes, hex encoded in a file. A new key will be generated if the file is empty.",
    59  		EnvVars:     prefixEnvVars("L2_ENGINE_AUTH"),
    60  		Value:       "",
    61  		Destination: new(string),
    62  		Category:    RollupCategory,
    63  	}
    64  	BeaconAddr = &cli.StringFlag{
    65  		Name:     "l1.beacon",
    66  		Usage:    "Address of L1 Beacon-node HTTP endpoint to use.",
    67  		Required: false,
    68  		EnvVars:  prefixEnvVars("L1_BEACON"),
    69  		Category: RollupCategory,
    70  	}
    71  	/* Optional Flags */
    72  	BeaconHeader = &cli.StringFlag{
    73  		Name:     "l1.beacon-header",
    74  		Usage:    "Optional HTTP header to add to all requests to the L1 Beacon endpoint. Format: 'X-Key: Value'",
    75  		Required: false,
    76  		EnvVars:  prefixEnvVars("L1_BEACON_HEADER"),
    77  		Category: L1RPCCategory,
    78  	}
    79  	BeaconArchiverAddr = &cli.StringFlag{
    80  		Name:     "l1.beacon-archiver",
    81  		Usage:    "Address of L1 Beacon-node compatible HTTP endpoint to use. This is used to fetch blobs that the --l1.beacon does not have (i.e expired blobs).",
    82  		Required: false,
    83  		EnvVars:  prefixEnvVars("L1_BEACON_ARCHIVER"),
    84  		Category: L1RPCCategory,
    85  	}
    86  	BeaconCheckIgnore = &cli.BoolFlag{
    87  		Name:     "l1.beacon.ignore",
    88  		Usage:    "When false, halts op-node startup if the healthcheck to the Beacon-node endpoint fails.",
    89  		Required: false,
    90  		Value:    false,
    91  		EnvVars:  prefixEnvVars("L1_BEACON_IGNORE"),
    92  		Category: L1RPCCategory,
    93  	}
    94  	BeaconFetchAllSidecars = &cli.BoolFlag{
    95  		Name:     "l1.beacon.fetch-all-sidecars",
    96  		Usage:    "If true, all sidecars are fetched and filtered locally. Workaround for buggy Beacon nodes.",
    97  		Required: false,
    98  		Value:    false,
    99  		EnvVars:  prefixEnvVars("L1_BEACON_FETCH_ALL_SIDECARS"),
   100  		Category: L1RPCCategory,
   101  	}
   102  	SyncModeFlag = &cli.GenericFlag{
   103  		Name:    "syncmode",
   104  		Usage:   fmt.Sprintf("Blockchain sync mode (options: %s)", openum.EnumString(sync.ModeStrings)),
   105  		EnvVars: prefixEnvVars("SYNCMODE"),
   106  		Value: func() *sync.Mode {
   107  			out := sync.CLSync
   108  			return &out
   109  		}(),
   110  		Category: RollupCategory,
   111  	}
   112  	RPCListenAddr = &cli.StringFlag{
   113  		Name:     "rpc.addr",
   114  		Usage:    "RPC listening address",
   115  		EnvVars:  prefixEnvVars("RPC_ADDR"),
   116  		Value:    "127.0.0.1",
   117  		Category: OperationsCategory,
   118  	}
   119  	RPCListenPort = &cli.IntFlag{
   120  		Name:     "rpc.port",
   121  		Usage:    "RPC listening port",
   122  		EnvVars:  prefixEnvVars("RPC_PORT"),
   123  		Value:    9545, // Note: op-service/rpc/cli.go uses 8545 as the default.
   124  		Category: OperationsCategory,
   125  	}
   126  	RPCEnableAdmin = &cli.BoolFlag{
   127  		Name:     "rpc.enable-admin",
   128  		Usage:    "Enable the admin API (experimental)",
   129  		EnvVars:  prefixEnvVars("RPC_ENABLE_ADMIN"),
   130  		Category: OperationsCategory,
   131  	}
   132  	RPCAdminPersistence = &cli.StringFlag{
   133  		Name:     "rpc.admin-state",
   134  		Usage:    "File path used to persist state changes made via the admin API so they persist across restarts. Disabled if not set.",
   135  		EnvVars:  prefixEnvVars("RPC_ADMIN_STATE"),
   136  		Category: OperationsCategory,
   137  	}
   138  	L1TrustRPC = &cli.BoolFlag{
   139  		Name:     "l1.trustrpc",
   140  		Usage:    "Trust the L1 RPC, sync faster at risk of malicious/buggy RPC providing bad or inconsistent L1 data",
   141  		EnvVars:  prefixEnvVars("L1_TRUST_RPC"),
   142  		Category: L1RPCCategory,
   143  	}
   144  	L1RPCProviderKind = &cli.GenericFlag{
   145  		Name: "l1.rpckind",
   146  		Usage: "The kind of RPC provider, used to inform optimal transactions receipts fetching, and thus reduce costs. Valid options: " +
   147  			openum.EnumString(sources.RPCProviderKinds),
   148  		EnvVars: prefixEnvVars("L1_RPC_KIND"),
   149  		Value: func() *sources.RPCProviderKind {
   150  			out := sources.RPCKindStandard
   151  			return &out
   152  		}(),
   153  		Category: L1RPCCategory,
   154  	}
   155  	L1RethDBPath = &cli.StringFlag{
   156  		Name:     "l1.rethdb",
   157  		Usage:    "The L1 RethDB path, used to fetch receipts for L1 blocks. Only applicable when using the `reth_db` RPC kind with `l1.rpckind`.",
   158  		EnvVars:  prefixEnvVars("L1_RETHDB"),
   159  		Hidden:   true,
   160  		Category: L1RPCCategory,
   161  	}
   162  	L1RPCMaxConcurrency = &cli.IntFlag{
   163  		Name:     "l1.max-concurrency",
   164  		Usage:    "Maximum number of concurrent RPC requests to make to the L1 RPC provider.",
   165  		EnvVars:  prefixEnvVars("L1_MAX_CONCURRENCY"),
   166  		Value:    10,
   167  		Category: L1RPCCategory,
   168  	}
   169  	L1RPCRateLimit = &cli.Float64Flag{
   170  		Name:     "l1.rpc-rate-limit",
   171  		Usage:    "Optional self-imposed global rate-limit on L1 RPC requests, specified in requests / second. Disabled if set to 0.",
   172  		EnvVars:  prefixEnvVars("L1_RPC_RATE_LIMIT"),
   173  		Value:    0,
   174  		Category: L1RPCCategory,
   175  	}
   176  	L1RPCMaxBatchSize = &cli.IntFlag{
   177  		Name:     "l1.rpc-max-batch-size",
   178  		Usage:    "Maximum number of RPC requests to bundle, e.g. during L1 blocks receipt fetching. The L1 RPC rate limit counts this as N items, but allows it to burst at once.",
   179  		EnvVars:  prefixEnvVars("L1_RPC_MAX_BATCH_SIZE"),
   180  		Value:    20,
   181  		Category: L1RPCCategory,
   182  	}
   183  	L1HTTPPollInterval = &cli.DurationFlag{
   184  		Name:     "l1.http-poll-interval",
   185  		Usage:    "Polling interval for latest-block subscription when using an HTTP RPC provider. Ignored for other types of RPC endpoints.",
   186  		EnvVars:  prefixEnvVars("L1_HTTP_POLL_INTERVAL"),
   187  		Value:    time.Second * 12,
   188  		Category: L1RPCCategory,
   189  	}
   190  	VerifierL1Confs = &cli.Uint64Flag{
   191  		Name:     "verifier.l1-confs",
   192  		Usage:    "Number of L1 blocks to keep distance from the L1 head before deriving L2 data from. Reorgs are supported, but may be slow to perform.",
   193  		EnvVars:  prefixEnvVars("VERIFIER_L1_CONFS"),
   194  		Value:    0,
   195  		Category: L1RPCCategory,
   196  	}
   197  	SequencerEnabledFlag = &cli.BoolFlag{
   198  		Name:     "sequencer.enabled",
   199  		Usage:    "Enable sequencing of new L2 blocks. A separate batch submitter has to be deployed to publish the data for verifiers.",
   200  		EnvVars:  prefixEnvVars("SEQUENCER_ENABLED"),
   201  		Category: SequencerCategory,
   202  	}
   203  	SequencerStoppedFlag = &cli.BoolFlag{
   204  		Name:     "sequencer.stopped",
   205  		Usage:    "Initialize the sequencer in a stopped state. The sequencer can be started using the admin_startSequencer RPC",
   206  		EnvVars:  prefixEnvVars("SEQUENCER_STOPPED"),
   207  		Category: SequencerCategory,
   208  	}
   209  	SequencerMaxSafeLagFlag = &cli.Uint64Flag{
   210  		Name:     "sequencer.max-safe-lag",
   211  		Usage:    "Maximum number of L2 blocks for restricting the distance between L2 safe and unsafe. Disabled if 0.",
   212  		EnvVars:  prefixEnvVars("SEQUENCER_MAX_SAFE_LAG"),
   213  		Value:    0,
   214  		Category: SequencerCategory,
   215  	}
   216  	SequencerL1Confs = &cli.Uint64Flag{
   217  		Name:     "sequencer.l1-confs",
   218  		Usage:    "Number of L1 blocks to keep distance from the L1 head as a sequencer for picking an L1 origin.",
   219  		EnvVars:  prefixEnvVars("SEQUENCER_L1_CONFS"),
   220  		Value:    4,
   221  		Category: SequencerCategory,
   222  	}
   223  	L1EpochPollIntervalFlag = &cli.DurationFlag{
   224  		Name:     "l1.epoch-poll-interval",
   225  		Usage:    "Poll interval for retrieving new L1 epoch updates such as safe and finalized block changes. Disabled if 0 or negative.",
   226  		EnvVars:  prefixEnvVars("L1_EPOCH_POLL_INTERVAL"),
   227  		Value:    time.Second * 12 * 32,
   228  		Category: L1RPCCategory,
   229  	}
   230  	RuntimeConfigReloadIntervalFlag = &cli.DurationFlag{
   231  		Name:     "l1.runtime-config-reload-interval",
   232  		Usage:    "Poll interval for reloading the runtime config, useful when config events are not being picked up. Disabled if 0 or negative.",
   233  		EnvVars:  prefixEnvVars("L1_RUNTIME_CONFIG_RELOAD_INTERVAL"),
   234  		Value:    time.Minute * 10,
   235  		Category: L1RPCCategory,
   236  	}
   237  	MetricsEnabledFlag = &cli.BoolFlag{
   238  		Name:     "metrics.enabled",
   239  		Usage:    "Enable the metrics server",
   240  		EnvVars:  prefixEnvVars("METRICS_ENABLED"),
   241  		Category: OperationsCategory,
   242  	}
   243  	MetricsAddrFlag = &cli.StringFlag{
   244  		Name:     "metrics.addr",
   245  		Usage:    "Metrics listening address",
   246  		Value:    "0.0.0.0", // TODO(CLI-4159): Switch to 127.0.0.1
   247  		EnvVars:  prefixEnvVars("METRICS_ADDR"),
   248  		Category: OperationsCategory,
   249  	}
   250  	MetricsPortFlag = &cli.IntFlag{
   251  		Name:     "metrics.port",
   252  		Usage:    "Metrics listening port",
   253  		Value:    7300,
   254  		EnvVars:  prefixEnvVars("METRICS_PORT"),
   255  		Category: OperationsCategory,
   256  	}
   257  	SnapshotLog = &cli.StringFlag{
   258  		Name:     "snapshotlog.file",
   259  		Usage:    "Path to the snapshot log file",
   260  		EnvVars:  prefixEnvVars("SNAPSHOT_LOG"),
   261  		Category: OperationsCategory,
   262  	}
   263  	HeartbeatEnabledFlag = &cli.BoolFlag{
   264  		Name:     "heartbeat.enabled",
   265  		Usage:    "Enables or disables heartbeating",
   266  		EnvVars:  prefixEnvVars("HEARTBEAT_ENABLED"),
   267  		Category: OperationsCategory,
   268  	}
   269  	HeartbeatMonikerFlag = &cli.StringFlag{
   270  		Name:     "heartbeat.moniker",
   271  		Usage:    "Sets a moniker for this node",
   272  		EnvVars:  prefixEnvVars("HEARTBEAT_MONIKER"),
   273  		Category: OperationsCategory,
   274  	}
   275  	HeartbeatURLFlag = &cli.StringFlag{
   276  		Name:     "heartbeat.url",
   277  		Usage:    "Sets the URL to heartbeat to",
   278  		EnvVars:  prefixEnvVars("HEARTBEAT_URL"),
   279  		Value:    "https://heartbeat.optimism.io",
   280  		Category: OperationsCategory,
   281  	}
   282  	RollupHalt = &cli.StringFlag{
   283  		Name:     "rollup.halt",
   284  		Usage:    "Opt-in option to halt on incompatible protocol version requirements of the given level (major/minor/patch/none), as signaled onchain in L1",
   285  		EnvVars:  prefixEnvVars("ROLLUP_HALT"),
   286  		Category: RollupCategory,
   287  	}
   288  	RollupLoadProtocolVersions = &cli.BoolFlag{
   289  		Name:     "rollup.load-protocol-versions",
   290  		Usage:    "Load protocol versions from the superchain L1 ProtocolVersions contract (if available), and report in logs and metrics",
   291  		EnvVars:  prefixEnvVars("ROLLUP_LOAD_PROTOCOL_VERSIONS"),
   292  		Category: RollupCategory,
   293  	}
   294  	SafeDBPath = &cli.StringFlag{
   295  		Name:     "safedb.path",
   296  		Usage:    "File path used to persist safe head update data. Disabled if not set.",
   297  		EnvVars:  prefixEnvVars("SAFEDB_PATH"),
   298  		Category: OperationsCategory,
   299  	}
   300  	/* Deprecated Flags */
   301  	L2EngineSyncEnabled = &cli.BoolFlag{
   302  		Name:    "l2.engine-sync",
   303  		Usage:   "WARNING: Deprecated. Use --syncmode=execution-layer instead",
   304  		EnvVars: prefixEnvVars("L2_ENGINE_SYNC_ENABLED"),
   305  		Value:   false,
   306  		Hidden:  true,
   307  	}
   308  	SkipSyncStartCheck = &cli.BoolFlag{
   309  		Name: "l2.skip-sync-start-check",
   310  		Usage: "Skip sanity check of consistency of L1 origins of the unsafe L2 blocks when determining the sync-starting point. " +
   311  			"This defers the L1-origin verification, and is recommended to use in when utilizing l2.engine-sync",
   312  		EnvVars: prefixEnvVars("L2_SKIP_SYNC_START_CHECK"),
   313  		Value:   false,
   314  		Hidden:  true,
   315  	}
   316  	BetaExtraNetworks = &cli.BoolFlag{
   317  		Name:    "beta.extra-networks",
   318  		Usage:   "Legacy flag, ignored, all superchain-registry networks are enabled by default.",
   319  		EnvVars: prefixEnvVars("BETA_EXTRA_NETWORKS"),
   320  		Hidden:  true, // hidden, this is deprecated, the flag is not used anymore.
   321  	}
   322  	BackupL2UnsafeSyncRPC = &cli.StringFlag{
   323  		Name:    "l2.backup-unsafe-sync-rpc",
   324  		Usage:   "Set the backup L2 unsafe sync RPC endpoint.",
   325  		EnvVars: prefixEnvVars("L2_BACKUP_UNSAFE_SYNC_RPC"),
   326  		Hidden:  true,
   327  	}
   328  	BackupL2UnsafeSyncRPCTrustRPC = &cli.StringFlag{
   329  		Name: "l2.backup-unsafe-sync-rpc.trustrpc",
   330  		Usage: "Like l1.trustrpc, configure if response data from the RPC needs to be verified, e.g. blockhash computation." +
   331  			"This does not include checks if the blockhash is part of the canonical chain.",
   332  		EnvVars: prefixEnvVars("L2_BACKUP_UNSAFE_SYNC_RPC_TRUST_RPC"),
   333  		Hidden:  true,
   334  	}
   335  	ConductorEnabledFlag = &cli.BoolFlag{
   336  		Name:     "conductor.enabled",
   337  		Usage:    "Enable the conductor service",
   338  		EnvVars:  prefixEnvVars("CONDUCTOR_ENABLED"),
   339  		Value:    false,
   340  		Category: SequencerCategory,
   341  	}
   342  	ConductorRpcFlag = &cli.StringFlag{
   343  		Name:     "conductor.rpc",
   344  		Usage:    "Conductor service rpc endpoint",
   345  		EnvVars:  prefixEnvVars("CONDUCTOR_RPC"),
   346  		Value:    "http://127.0.0.1:8547",
   347  		Category: SequencerCategory,
   348  	}
   349  	ConductorRpcTimeoutFlag = &cli.DurationFlag{
   350  		Name:     "conductor.rpc-timeout",
   351  		Usage:    "Conductor service rpc timeout",
   352  		EnvVars:  prefixEnvVars("CONDUCTOR_RPC_TIMEOUT"),
   353  		Value:    time.Second * 1,
   354  		Category: SequencerCategory,
   355  	}
   356  )
   357  
   358  var requiredFlags = []cli.Flag{
   359  	L1NodeAddr,
   360  	L2EngineAddr,
   361  	L2EngineJWTSecret,
   362  }
   363  
   364  var optionalFlags = []cli.Flag{
   365  	BeaconAddr,
   366  	BeaconHeader,
   367  	BeaconArchiverAddr,
   368  	BeaconCheckIgnore,
   369  	BeaconFetchAllSidecars,
   370  	SyncModeFlag,
   371  	RPCListenAddr,
   372  	RPCListenPort,
   373  	L1TrustRPC,
   374  	L1RPCProviderKind,
   375  	L1RPCRateLimit,
   376  	L1RPCMaxBatchSize,
   377  	L1RPCMaxConcurrency,
   378  	L1HTTPPollInterval,
   379  	VerifierL1Confs,
   380  	SequencerEnabledFlag,
   381  	SequencerStoppedFlag,
   382  	SequencerMaxSafeLagFlag,
   383  	SequencerL1Confs,
   384  	L1EpochPollIntervalFlag,
   385  	RuntimeConfigReloadIntervalFlag,
   386  	RPCEnableAdmin,
   387  	RPCAdminPersistence,
   388  	MetricsEnabledFlag,
   389  	MetricsAddrFlag,
   390  	MetricsPortFlag,
   391  	SnapshotLog,
   392  	HeartbeatEnabledFlag,
   393  	HeartbeatMonikerFlag,
   394  	HeartbeatURLFlag,
   395  	RollupHalt,
   396  	RollupLoadProtocolVersions,
   397  	L1RethDBPath,
   398  	ConductorEnabledFlag,
   399  	ConductorRpcFlag,
   400  	ConductorRpcTimeoutFlag,
   401  	SafeDBPath,
   402  }
   403  
   404  var DeprecatedFlags = []cli.Flag{
   405  	L2EngineSyncEnabled,
   406  	SkipSyncStartCheck,
   407  	BetaExtraNetworks,
   408  	BackupL2UnsafeSyncRPC,
   409  	BackupL2UnsafeSyncRPCTrustRPC,
   410  	// Deprecated P2P Flags are added at the init step
   411  }
   412  
   413  // Flags contains the list of configuration options available to the binary.
   414  var Flags []cli.Flag
   415  
   416  func init() {
   417  	DeprecatedFlags = append(DeprecatedFlags, deprecatedP2PFlags(EnvVarPrefix)...)
   418  	optionalFlags = append(optionalFlags, P2PFlags(EnvVarPrefix)...)
   419  	optionalFlags = append(optionalFlags, oplog.CLIFlagsWithCategory(EnvVarPrefix, OperationsCategory)...)
   420  	optionalFlags = append(optionalFlags, oppprof.CLIFlagsWithCategory(EnvVarPrefix, OperationsCategory)...)
   421  	optionalFlags = append(optionalFlags, DeprecatedFlags...)
   422  	optionalFlags = append(optionalFlags, opflags.CLIFlags(EnvVarPrefix, RollupCategory)...)
   423  	optionalFlags = append(optionalFlags, plasma.CLIFlags(EnvVarPrefix, PlasmaCategory)...)
   424  	Flags = append(requiredFlags, optionalFlags...)
   425  }
   426  
   427  func CheckRequired(ctx *cli.Context) error {
   428  	for _, f := range requiredFlags {
   429  		if !ctx.IsSet(f.Names()[0]) {
   430  			return fmt.Errorf("flag %s is required", f.Names()[0])
   431  		}
   432  	}
   433  	return opflags.CheckRequiredXor(ctx)
   434  }