diff --git a/batch-submitter/batch_submitter.go b/batch-submitter/batch_submitter.go index 066765552..4e08f416b 100644 --- a/batch-submitter/batch_submitter.go +++ b/batch-submitter/batch_submitter.go @@ -166,27 +166,28 @@ func Main(gitVersion string) func(ctx *cli.Context) error { if cfg.RunStateBatchSubmitter { batchStateDriver, err := proposer.NewDriver(proposer.Config{ - Name: "Proposer", - L1Client: l1Client, - L2Client: l2Client, - TssClient: tssClient, - BlockOffset: cfg.BlockOffset, - MinStateRootElements: cfg.MinStateRootElements, - MaxStateRootElements: cfg.MaxStateRootElements, - SCCAddr: sccAddress, - CTCAddr: ctcAddress, - FPRollupAddr: common.HexToAddress(cfg.FPRollupAddress), - ChainID: chainID, - PrivKey: proposerPrivKey, - SccRollback: cfg.EnableSccRollback, - MaxBatchSubmissionTime: cfg.MaxBatchSubmissionTime, - PollInterval: cfg.PollInterval, - FinalityConfirmations: cfg.FinalityConfirmations, - EnableProposerHsm: cfg.EnableProposerHsm, - ProposerHsmAddress: cfg.ProposerHsmAddress, - ProposerHsmCreden: cfg.ProposerHsmCreden, - ProposerHsmAPIName: cfg.ProposerHsmAPIName, - AllowL2AutoRollback: cfg.AllowL2AutoRollback, + Name: "Proposer", + L1Client: l1Client, + L2Client: l2Client, + TssClient: tssClient, + BlockOffset: cfg.BlockOffset, + MinStateRootElements: cfg.MinStateRootElements, + MaxStateRootElements: cfg.MaxStateRootElements, + SCCAddr: sccAddress, + CTCAddr: ctcAddress, + FPRollupAddr: common.HexToAddress(cfg.FPRollupAddress), + ChainID: chainID, + PrivKey: proposerPrivKey, + SccRollback: cfg.EnableSccRollback, + RollupTimeout: cfg.RollupTimeout, + PollInterval: cfg.PollInterval, + FinalityConfirmations: cfg.FinalityConfirmations, + EnableProposerHsm: cfg.EnableProposerHsm, + ProposerHsmAddress: cfg.ProposerHsmAddress, + ProposerHsmCreden: cfg.ProposerHsmCreden, + ProposerHsmAPIName: cfg.ProposerHsmAPIName, + AllowL2AutoRollback: cfg.AllowL2AutoRollback, + MinTimeoutStateRootElements: cfg.MinTimeoutStateRootElements, }) if err != nil { return err diff --git a/batch-submitter/config.go b/batch-submitter/config.go index 527f9ff89..a0920b7e4 100644 --- a/batch-submitter/config.go +++ b/batch-submitter/config.go @@ -105,9 +105,7 @@ type Config struct { // in a batch. MaxTxBatchCount uint64 - // MaxBatchSubmissionTime is the maximum amount of time that we will - // wait before submitting an under-sized batch. - MaxBatchSubmissionTime time.Duration + RollupTimeout time.Duration // PollInterval is the delay between querying L2 for more transaction // and creating a new batch. @@ -236,6 +234,8 @@ type Config struct { MaxRollupTxn uint64 MinRollupTxn uint64 + + MinTimeoutStateRootElements uint64 } // NewConfig parses the Config from the provided flags or environment variables. @@ -259,7 +259,7 @@ func NewConfig(ctx *cli.Context) (Config, error) { MaxPlaintextBatchSize: ctx.GlobalUint64(flags.MaxPlaintextBatchSizeFlag.Name), MinStateRootElements: ctx.GlobalUint64(flags.MinStateRootElementsFlag.Name), MaxStateRootElements: ctx.GlobalUint64(flags.MaxStateRootElementsFlag.Name), - MaxBatchSubmissionTime: ctx.GlobalDuration(flags.MaxBatchSubmissionTimeFlag.Name), + RollupTimeout: ctx.GlobalDuration(flags.RollupTimeoutFlag.Name), PollInterval: ctx.GlobalDuration(flags.PollIntervalFlag.Name), NumConfirmations: ctx.GlobalUint64(flags.NumConfirmationsFlag.Name), SafeAbortNonceTooLowCount: ctx.GlobalUint64(flags.SafeAbortNonceTooLowCountFlag.Name), @@ -270,35 +270,36 @@ func NewConfig(ctx *cli.Context) (Config, error) { SafeMinimumEtherBalance: ctx.GlobalUint64(flags.SafeMinimumEtherBalanceFlag.Name), ClearPendingTxs: ctx.GlobalBool(flags.ClearPendingTxsFlag.Name), /* Optional Flags */ - LogLevel: ctx.GlobalString(flags.LogLevelFlag.Name), - LogTerminal: ctx.GlobalBool(flags.LogTerminalFlag.Name), - SentryEnable: ctx.GlobalBool(flags.SentryEnableFlag.Name), - SentryDsn: ctx.GlobalString(flags.SentryDsnFlag.Name), - SentryTraceRate: ctx.GlobalDuration(flags.SentryTraceRateFlag.Name), - BlockOffset: ctx.GlobalUint64(flags.BlockOffsetFlag.Name), - SequencerPrivateKey: ctx.GlobalString(flags.SequencerPrivateKeyFlag.Name), - ProposerPrivateKey: ctx.GlobalString(flags.ProposerPrivateKeyFlag.Name), - Mnemonic: ctx.GlobalString(flags.MnemonicFlag.Name), - SequencerHDPath: ctx.GlobalString(flags.SequencerHDPathFlag.Name), - ProposerHDPath: ctx.GlobalString(flags.ProposerHDPathFlag.Name), - SequencerBatchType: ctx.GlobalString(flags.SequencerBatchType.Name), - MetricsServerEnable: ctx.GlobalBool(flags.MetricsServerEnableFlag.Name), - MetricsHostname: ctx.GlobalString(flags.MetricsHostnameFlag.Name), - MetricsPort: ctx.GlobalUint64(flags.MetricsPortFlag.Name), - DisableHTTP2: ctx.GlobalBool(flags.HTTP2DisableFlag.Name), - EnableSccRollback: ctx.GlobalBool(flags.SccRollbackFlag.Name), - EnableSequencerHsm: ctx.GlobalBool(flags.EnableSequencerHsmFlag.Name), - SequencerHsmAddress: ctx.GlobalString(flags.SequencerHsmAddressFlag.Name), - SequencerHsmAPIName: ctx.GlobalString(flags.SequencerHsmAPIName.Name), - SequencerHsmCreden: ctx.GlobalString(flags.SequencerHsmCreden.Name), - EnableProposerHsm: ctx.GlobalBool(flags.EnableProposerHsmFlag.Name), - ProposerHsmAddress: ctx.GlobalString(flags.ProposerHsmAddressFlag.Name), - ProposerHsmAPIName: ctx.GlobalString(flags.ProposerHsmAPIName.Name), - ProposerHsmCreden: ctx.GlobalString(flags.ProposerHsmCreden.Name), - RollupClientHttp: ctx.GlobalString(flags.RollupClientHttpFlag.Name), - AllowL2AutoRollback: ctx.GlobalBool(flags.AllowL2AutoRollback.Name), - MaxRollupTxn: ctx.GlobalUint64(flags.MaxRollupTxnFlag.Name), - MinRollupTxn: ctx.GlobalUint64(flags.MinRollupTxnFlag.Name), + LogLevel: ctx.GlobalString(flags.LogLevelFlag.Name), + LogTerminal: ctx.GlobalBool(flags.LogTerminalFlag.Name), + SentryEnable: ctx.GlobalBool(flags.SentryEnableFlag.Name), + SentryDsn: ctx.GlobalString(flags.SentryDsnFlag.Name), + SentryTraceRate: ctx.GlobalDuration(flags.SentryTraceRateFlag.Name), + BlockOffset: ctx.GlobalUint64(flags.BlockOffsetFlag.Name), + SequencerPrivateKey: ctx.GlobalString(flags.SequencerPrivateKeyFlag.Name), + ProposerPrivateKey: ctx.GlobalString(flags.ProposerPrivateKeyFlag.Name), + Mnemonic: ctx.GlobalString(flags.MnemonicFlag.Name), + SequencerHDPath: ctx.GlobalString(flags.SequencerHDPathFlag.Name), + ProposerHDPath: ctx.GlobalString(flags.ProposerHDPathFlag.Name), + SequencerBatchType: ctx.GlobalString(flags.SequencerBatchType.Name), + MetricsServerEnable: ctx.GlobalBool(flags.MetricsServerEnableFlag.Name), + MetricsHostname: ctx.GlobalString(flags.MetricsHostnameFlag.Name), + MetricsPort: ctx.GlobalUint64(flags.MetricsPortFlag.Name), + DisableHTTP2: ctx.GlobalBool(flags.HTTP2DisableFlag.Name), + EnableSccRollback: ctx.GlobalBool(flags.SccRollbackFlag.Name), + EnableSequencerHsm: ctx.GlobalBool(flags.EnableSequencerHsmFlag.Name), + SequencerHsmAddress: ctx.GlobalString(flags.SequencerHsmAddressFlag.Name), + SequencerHsmAPIName: ctx.GlobalString(flags.SequencerHsmAPIName.Name), + SequencerHsmCreden: ctx.GlobalString(flags.SequencerHsmCreden.Name), + EnableProposerHsm: ctx.GlobalBool(flags.EnableProposerHsmFlag.Name), + ProposerHsmAddress: ctx.GlobalString(flags.ProposerHsmAddressFlag.Name), + ProposerHsmAPIName: ctx.GlobalString(flags.ProposerHsmAPIName.Name), + ProposerHsmCreden: ctx.GlobalString(flags.ProposerHsmCreden.Name), + RollupClientHttp: ctx.GlobalString(flags.RollupClientHttpFlag.Name), + AllowL2AutoRollback: ctx.GlobalBool(flags.AllowL2AutoRollback.Name), + MaxRollupTxn: ctx.GlobalUint64(flags.MaxRollupTxnFlag.Name), + MinRollupTxn: ctx.GlobalUint64(flags.MinRollupTxnFlag.Name), + MinTimeoutStateRootElements: ctx.GlobalUint64(flags.MinTimeoutStateRootElementsFlag.Name), } err := ValidateConfig(&cfg) diff --git a/batch-submitter/drivers/proposer/driver.go b/batch-submitter/drivers/proposer/driver.go index 4a58b4cd3..d9824fce3 100644 --- a/batch-submitter/drivers/proposer/driver.go +++ b/batch-submitter/drivers/proposer/driver.go @@ -46,27 +46,28 @@ const blockBuffer = 2 var bigOne = new(big.Int).SetUint64(1) //nolint:unused type Config struct { - Name string - L1Client *ethclient.Client - L2Client *l2ethclient.Client - TssClient *tssClient.Client - BlockOffset uint64 - MaxStateRootElements uint64 - MinStateRootElements uint64 - SCCAddr common.Address - CTCAddr common.Address - FPRollupAddr common.Address - ChainID *big.Int - PrivKey *ecdsa.PrivateKey - SccRollback bool - MaxBatchSubmissionTime time.Duration - PollInterval time.Duration - FinalityConfirmations uint64 - EnableProposerHsm bool - ProposerHsmCreden string - ProposerHsmAddress string - ProposerHsmAPIName string - AllowL2AutoRollback bool + Name string + L1Client *ethclient.Client + L2Client *l2ethclient.Client + TssClient *tssClient.Client + BlockOffset uint64 + MaxStateRootElements uint64 + MinStateRootElements uint64 + SCCAddr common.Address + CTCAddr common.Address + FPRollupAddr common.Address + ChainID *big.Int + PrivKey *ecdsa.PrivateKey + SccRollback bool + RollupTimeout time.Duration + PollInterval time.Duration + FinalityConfirmations uint64 + EnableProposerHsm bool + ProposerHsmCreden string + ProposerHsmAddress string + ProposerHsmAPIName string + AllowL2AutoRollback bool + MinTimeoutStateRootElements uint64 } type Driver struct { @@ -242,7 +243,6 @@ func (d *Driver) GetBatchBlockRange( return nil, nil, fmt.Errorf("invalid range, "+ "end(%v) < start(%v)", end, start) } - return start, end, nil } @@ -264,19 +264,20 @@ func (d *Driver) CraftBatchTx( d.lastStart = start d.lastCommitTime = time.Now().Add(-d.cfg.PollInterval) } - //If the waiting time has not been reached, then check whether the minimum stateroot number //is met. if not, return nil - if time.Now().Add(-d.cfg.MaxBatchSubmissionTime).Before(d.lastCommitTime) { - // Abort if we don't have enough state roots to meet our minimum - // requirement. - rangeLen := end.Uint64() - start.Uint64() - if rangeLen < d.cfg.MinStateRootElements { + rollupTxn := end.Uint64() - start.Uint64() + if rollupTxn < d.cfg.MinStateRootElements && (time.Now().Add(-d.cfg.RollupTimeout).Before(d.lastCommitTime) || rollupTxn < d.cfg.MinTimeoutStateRootElements) { + if rollupTxn < d.cfg.MinStateRootElements { log.Info(name+" number of state roots below minimum", - "num_state_roots", rangeLen, + "num_state_roots", rollupTxn, "min_state_roots", d.cfg.MinStateRootElements) return nil, nil } + log.Info(name+" number of timeout state roots below minimum or timeout can't satisfy the constrain", + "num_state_roots", rollupTxn, + "min_timeout_state_roots", d.cfg.MinTimeoutStateRootElements) + return nil, nil } var blocks []*l2types.Block diff --git a/batch-submitter/flags/flags.go b/batch-submitter/flags/flags.go index bb3418bab..5284b3b96 100644 --- a/batch-submitter/flags/flags.go +++ b/batch-submitter/flags/flags.go @@ -117,12 +117,11 @@ var ( Required: true, EnvVar: prefixEnvVar("MAX_STATE_ROOT_ELEMENTS"), } - MaxBatchSubmissionTimeFlag = cli.DurationFlag{ - Name: "max-batch-submission-time", - Usage: "Maximum amount of time that we will wait before " + - "submitting an under-sized batch", + RollupTimeoutFlag = cli.DurationFlag{ + Name: "rollup-timeout", + Usage: "Delay between rollup timeout transactions ", Required: true, - EnvVar: prefixEnvVar("MAX_BATCH_SUBMISSION_TIME"), + EnvVar: prefixEnvVar("ROLLUP_TIMEOUT"), } PollIntervalFlag = cli.DurationFlag{ Name: "poll-interval", @@ -357,6 +356,14 @@ var ( Required: true, EnvVar: prefixEnvVar("MAX_ROLLUP_TXN"), } + + MinTimeoutStateRootElementsFlag = cli.Uint64Flag{ + Name: "min-timeout-state-root-elements", + Usage: "Minimum number of elements required to submit a state " + + "root batch", + Required: true, + EnvVar: prefixEnvVar("MIN_TIMEOUT_STATE_ROOT_ELEMENTS"), + } ) var requiredFlags = []cli.Flag{ @@ -376,7 +383,7 @@ var requiredFlags = []cli.Flag{ MaxPlaintextBatchSizeFlag, MinStateRootElementsFlag, MaxStateRootElementsFlag, - MaxBatchSubmissionTimeFlag, + RollupTimeoutFlag, PollIntervalFlag, NumConfirmationsFlag, SafeAbortNonceTooLowCountFlag, @@ -388,6 +395,7 @@ var requiredFlags = []cli.Flag{ ClearPendingTxsFlag, MaxRollupTxnFlag, MinRollupTxnFlag, + MinTimeoutStateRootElementsFlag, } var optionalFlags = []cli.Flag{