flags.go 8.81 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
package flags

import (
	"time"

	"github.com/urfave/cli"
)

const envVarPrefix = "BATCH_SUBMITTER_"

func prefixEnvVar(name string) string {
	return envVarPrefix + name
}

var (
	/* Required Flags */

	BuildEnvFlag = cli.StringFlag{
		Name: "build-env",
		Usage: "Build environment for which the binary is produced, " +
			"e.g. production or development",
		Required: true,
		EnvVar:   "BUILD_ENV",
	}
	EthNetworkNameFlag = cli.StringFlag{
		Name:     "eth-network-name",
		Usage:    "Ethereum network name",
		Required: true,
		EnvVar:   "ETH_NETWORK_NAME",
	}
	L1EthRpcFlag = cli.StringFlag{
		Name:     "l1-eth-rpc",
		Usage:    "HTTP provider URL for L1",
		Required: true,
		EnvVar:   "L1_ETH_RPC",
	}
	L2EthRpcFlag = cli.StringFlag{
		Name:     "l2-eth-rpc",
		Usage:    "HTTP provider URL for L2",
		Required: true,
		EnvVar:   "L2_ETH_RPC",
	}
	CTCAddressFlag = cli.StringFlag{
		Name:     "ctc-address",
		Usage:    "Address of the CTC contract",
		Required: true,
		EnvVar:   "CTC_ADDRESS",
	}
	SCCAddressFlag = cli.StringFlag{
		Name:     "scc-address",
		Usage:    "Address of the SCC contract",
		Required: true,
		EnvVar:   "SCC_ADDRESS",
	}
55 56 57 58 59 60 61
	MinL1TxSizeFlag = cli.Uint64Flag{
		Name: "min-l1-tx-size",
		Usage: "Minimum size in bytes of any L1 transaction that gets " +
			"generated by the batch submitter",
		Required: true,
		EnvVar:   prefixEnvVar("MIN_L1_TX_SIZE"),
	}
62 63 64 65 66 67 68
	MaxL1TxSizeFlag = cli.Uint64Flag{
		Name: "max-l1-tx-size",
		Usage: "Maximum size in bytes of any L1 transaction that gets " +
			"generated by the batch submitter",
		Required: true,
		EnvVar:   prefixEnvVar("MAX_L1_TX_SIZE"),
	}
69 70 71 72 73 74 75
	MaxPlaintextBatchSizeFlag = cli.Uint64Flag{
		Name: "max-plaintext-batch-size",
		Usage: "Maximum size in bytes of of the plaintext tx data " +
			"encoded in batches",
		Required: true,
		EnvVar:   prefixEnvVar("MAX_PLAINTEXT_BATCH_SIZE"),
	}
76 77 78 79 80 81 82 83 84 85 86 87 88 89
	MinStateRootElementsFlag = cli.Uint64Flag{
		Name: "min-state-root-elements",
		Usage: "Minimum number of elements required to submit a state " +
			"root batch",
		Required: true,
		EnvVar:   prefixEnvVar("MIN_STATE_ROOT_ELEMENTS"),
	}
	MaxStateRootElementsFlag = cli.Uint64Flag{
		Name: "max-state-root-elements",
		Usage: "Maximum number of elements required to submit a state " +
			"root batch",
		Required: true,
		EnvVar:   prefixEnvVar("MAX_STATE_ROOT_ELEMENTS"),
	}
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
	MaxBatchSubmissionTimeFlag = cli.DurationFlag{
		Name: "max-batch-submission-time",
		Usage: "Maximum amount of time that we will wait before " +
			"submitting an under-sized batch",
		Required: true,
		EnvVar:   prefixEnvVar("MAX_BATCH_SUBMISSION_TIME"),
	}
	PollIntervalFlag = cli.DurationFlag{
		Name: "poll-interval",
		Usage: "Delay between querying L2 for more transactions and " +
			"creating a new batch",
		Required: true,
		EnvVar:   prefixEnvVar("POLL_INTERVAL"),
	}
	NumConfirmationsFlag = cli.Uint64Flag{
		Name: "num-confirmations",
		Usage: "Number of confirmations which we will wait after " +
			"appending a new batch",
		Required: true,
		EnvVar:   prefixEnvVar("NUM_CONFIRMATIONS"),
	}
111 112 113 114 115 116 117 118
	SafeAbortNonceTooLowCountFlag = cli.Uint64Flag{
		Name: "safe-abort-nonce-too-low-count",
		Usage: "Number of ErrNonceTooLow observations required to " +
			"give up on a tx at a particular nonce without receiving " +
			"confirmation",
		Required: true,
		EnvVar:   prefixEnvVar("SAFE_ABORT_NONCE_TOO_LOW_COUNT"),
	}
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
	ResubmissionTimeoutFlag = cli.DurationFlag{
		Name: "resubmission-timeout",
		Usage: "Duration we will wait before resubmitting a " +
			"transaction to L1",
		Required: true,
		EnvVar:   prefixEnvVar("RESUBMISSION_TIMEOUT"),
	}
	FinalityConfirmationsFlag = cli.Uint64Flag{
		Name: "finality-confirmations",
		Usage: "Number of confirmations that we should wait before " +
			"submitting state roots for CTC elements",
		Required: true,
		EnvVar:   prefixEnvVar("FINALITY_CONFIRMATIONS"),
	}
	RunTxBatchSubmitterFlag = cli.BoolFlag{
		Name:     "run-tx-batch-submitter",
		Usage:    "Determines whether or not to run the tx batch submitter",
		Required: true,
		EnvVar:   prefixEnvVar("RUN_TX_BATCH_SUBMITTER"),
	}
	RunStateBatchSubmitterFlag = cli.BoolFlag{
		Name:     "run-state-batch-submitter",
		Usage:    "Determines whether or not to run the state batch submitter",
		Required: true,
		EnvVar:   prefixEnvVar("RUN_STATE_BATCH_SUBMITTER"),
	}
	SafeMinimumEtherBalanceFlag = cli.Uint64Flag{
		Name: "safe-minimum-ether-balance",
		Usage: "Safe minimum amount of ether the batch submitter key " +
			"should hold before it starts to log errors",
		Required: true,
		EnvVar:   prefixEnvVar("SAFE_MINIMUM_ETHER_BALANCE"),
	}
	ClearPendingTxsFlag = cli.BoolFlag{
		Name: "clear-pending-txs",
		Usage: "Whether or not to clear pending transaction in the " +
			"mempool on startup",
		Required: true,
		EnvVar:   prefixEnvVar("CLEAR_PENDING_TXS"),
	}

	/* Optional Flags */

	LogLevelFlag = cli.StringFlag{
		Name:   "log-level",
		Usage:  "The lowest log level that will be output",
		Value:  "info",
		EnvVar: prefixEnvVar("LOG_LEVEL"),
	}
168 169 170 171 172 173 174
	LogTerminalFlag = cli.BoolFlag{
		Name: "log-terminal",
		Usage: "If true, outputs logs in terminal format, otherwise prints " +
			"in JSON format. If SENTRY_ENABLE is set to true, this flag is " +
			"ignored and logs are printed using JSON",
		EnvVar: prefixEnvVar("LOG_TERMINAL"),
	}
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
	SentryEnableFlag = cli.BoolFlag{
		Name:   "sentry-enable",
		Usage:  "Whether or not to enable Sentry. If true, sentry-dsn must also be set",
		EnvVar: prefixEnvVar("SENTRY_ENABLE"),
	}
	SentryDsnFlag = cli.StringFlag{
		Name:   "sentry-dsn",
		Usage:  "Sentry data source name",
		EnvVar: prefixEnvVar("SENTRY_DSN"),
	}
	SentryTraceRateFlag = cli.DurationFlag{
		Name:   "sentry-trace-rate",
		Usage:  "Sentry trace rate",
		Value:  50 * time.Millisecond,
		EnvVar: prefixEnvVar("SENTRY_TRACE_RATE"),
	}
	BlockOffsetFlag = cli.Uint64Flag{
		Name:   "block-offset",
		Usage:  "The offset between the CTC contract start and the L2 geth blocks",
		Value:  1,
		EnvVar: prefixEnvVar("BLOCK_OFFSET"),
	}
	SequencerPrivateKeyFlag = cli.StringFlag{
		Name:   "sequencer-private-key",
		Usage:  "The private key to use for sending to the sequencer contract",
		EnvVar: prefixEnvVar("SEQUENCER_PRIVATE_KEY"),
	}
	ProposerPrivateKeyFlag = cli.StringFlag{
		Name:   "proposer-private-key",
		Usage:  "The private key to use for sending to the proposer contract",
		EnvVar: prefixEnvVar("PROPOSER_PRIVATE_KEY"),
	}
	MnemonicFlag = cli.StringFlag{
		Name: "mnemonic",
		Usage: "The mnemonic used to derive the wallets for either the " +
			"sequencer or the proposer",
		EnvVar: prefixEnvVar("MNEMONIC"),
	}
	SequencerHDPathFlag = cli.StringFlag{
		Name: "sequencer-hd-path",
		Usage: "The HD path used to derive the sequencer wallet from the " +
			"mnemonic. The mnemonic flag must also be set.",
		EnvVar: prefixEnvVar("SEQUENCER_HD_PATH"),
	}
	ProposerHDPathFlag = cli.StringFlag{
		Name: "proposer-hd-path",
		Usage: "The HD path used to derive the proposer wallet from the " +
			"mnemonic. The mnemonic flag must also be set.",
		EnvVar: prefixEnvVar("PROPOSER_HD_PATH"),
	}
225 226 227 228 229 230
	SequencerBatchType = cli.StringFlag{
		Name:   "sequencer-batch-type",
		Usage:  "The type of sequencer batch to be submitted. Valid arguments are legacy or zlib.",
		Value:  "legacy",
		EnvVar: prefixEnvVar("SEQUENCER_BATCH_TYPE"),
	}
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
	MetricsServerEnableFlag = cli.BoolFlag{
		Name:   "metrics-server-enable",
		Usage:  "Whether or not to run the embedded metrics server",
		EnvVar: prefixEnvVar("METRICS_SERVER_ENABLE"),
	}
	MetricsHostnameFlag = cli.StringFlag{
		Name:   "metrics-hostname",
		Usage:  "The hostname of the metrics server",
		Value:  "127.0.0.1",
		EnvVar: prefixEnvVar("METRICS_HOSTNAME"),
	}
	MetricsPortFlag = cli.Uint64Flag{
		Name:   "metrics-port",
		Usage:  "The port of the metrics server",
		Value:  7300,
		EnvVar: prefixEnvVar("METRICS_PORT"),
	}
248
	HTTP2DisableFlag = cli.BoolFlag{
249 250
		Name:   "http2-disable",
		Usage:  "Whether or not to disable HTTP/2 support.",
251 252
		EnvVar: prefixEnvVar("HTTP2_DISABLE"),
	}
253 254 255 256 257 258 259 260 261
)

var requiredFlags = []cli.Flag{
	BuildEnvFlag,
	EthNetworkNameFlag,
	L1EthRpcFlag,
	L2EthRpcFlag,
	CTCAddressFlag,
	SCCAddressFlag,
262
	MinL1TxSizeFlag,
263
	MaxL1TxSizeFlag,
264
	MaxPlaintextBatchSizeFlag,
265 266
	MinStateRootElementsFlag,
	MaxStateRootElementsFlag,
267 268 269
	MaxBatchSubmissionTimeFlag,
	PollIntervalFlag,
	NumConfirmationsFlag,
270
	SafeAbortNonceTooLowCountFlag,
271 272 273 274 275 276 277 278 279 280
	ResubmissionTimeoutFlag,
	FinalityConfirmationsFlag,
	RunTxBatchSubmitterFlag,
	RunStateBatchSubmitterFlag,
	SafeMinimumEtherBalanceFlag,
	ClearPendingTxsFlag,
}

var optionalFlags = []cli.Flag{
	LogLevelFlag,
281
	LogTerminalFlag,
282 283 284 285
	SentryEnableFlag,
	SentryDsnFlag,
	SentryTraceRateFlag,
	BlockOffsetFlag,
286
	SequencerBatchType,
287 288 289 290 291 292 293 294
	SequencerPrivateKeyFlag,
	ProposerPrivateKeyFlag,
	MnemonicFlag,
	SequencerHDPathFlag,
	ProposerHDPathFlag,
	MetricsServerEnableFlag,
	MetricsHostnameFlag,
	MetricsPortFlag,
295
	HTTP2DisableFlag,
296 297 298 299
}

// Flags contains the list of configuration options available to the binary.
var Flags = append(requiredFlags, optionalFlags...)