Skip to content

Commit

Permalink
add rollup timeout config flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethanncnm committed Jul 21, 2023
1 parent 7b93641 commit 969590e
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 89 deletions.
43 changes: 22 additions & 21 deletions batch-submitter/batch_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 34 additions & 33 deletions batch-submitter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -236,6 +234,8 @@ type Config struct {
MaxRollupTxn uint64

MinRollupTxn uint64

MinTimeoutStateRootElements uint64
}

// NewConfig parses the Config from the provided flags or environment variables.
Expand All @@ -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),
Expand All @@ -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)
Expand Down
59 changes: 30 additions & 29 deletions batch-submitter/drivers/proposer/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down
20 changes: 14 additions & 6 deletions batch-submitter/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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{
Expand All @@ -376,7 +383,7 @@ var requiredFlags = []cli.Flag{
MaxPlaintextBatchSizeFlag,
MinStateRootElementsFlag,
MaxStateRootElementsFlag,
MaxBatchSubmissionTimeFlag,
RollupTimeoutFlag,
PollIntervalFlag,
NumConfirmationsFlag,
SafeAbortNonceTooLowCountFlag,
Expand All @@ -388,6 +395,7 @@ var requiredFlags = []cli.Flag{
ClearPendingTxsFlag,
MaxRollupTxnFlag,
MinRollupTxnFlag,
MinTimeoutStateRootElementsFlag,
}

var optionalFlags = []cli.Flag{
Expand Down

0 comments on commit 969590e

Please sign in to comment.