Skip to content

Commit

Permalink
R4R: Feature/fix mt batcher (#1334)
Browse files Browse the repository at this point in the history
# Goals of PR

Core changes:

- modify for Rollup services optimization code. 

Notes:

- associated pr: #1301

Related Issues:

- no
  • Loading branch information
tw5428561 authored Aug 9, 2023
2 parents 446e2af + 09c8c57 commit 10f6f93
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
3 changes: 0 additions & 3 deletions batch-submitter/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,13 @@ var (
Name: "min-rollup-txn",
Usage: "Minimum number of transaction from l2geth which is used to submit to rollup",
Required: true,
Value: 20,
EnvVar: prefixEnvVar("MIN_ROLLUP_TXN"),
}

MaxRollupTxnFlag = cli.Uint64Flag{
Name: "max-rollup-txn",
Usage: "Maximum number of transaction from l2geth which is used to submit to rollup",
Required: true,
Value: 70,
EnvVar: prefixEnvVar("MAX_ROLLUP_TXN"),
}

Expand All @@ -343,7 +341,6 @@ var (
Usage: "Minimum number of elements required to submit a state " +
"root batch",
Required: true,
Value: 100,
EnvVar: prefixEnvVar("MIN_TIMEOUT_STATE_ROOT_ELEMENTS"),
}
)
Expand Down
2 changes: 1 addition & 1 deletion datalayr
1 change: 0 additions & 1 deletion mt-batcher/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ var (
MinTimeoutRollupTxnFlag = cli.Uint64Flag{
Name: "min-timeout-rollup-txn",
Usage: "minimum of timeout Rollup transaction amount for mantle da",
Value: 500,
Required: true,
EnvVar: prefixEnvVar(envVarPrefix, "MIN_TIMEOUT_ROLLUP_TXN"),
}
Expand Down
32 changes: 17 additions & 15 deletions mt-batcher/services/sequencer/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ import (
"github.com/mantlenetworkio/mantle/mt-batcher/txmgr"
)

var (
pollingInterval = 1000 * time.Millisecond
)

type SignerFn func(context.Context, common.Address, *types.Transaction) (*types.Transaction, error)

type DriverConfig struct {
Expand Down Expand Up @@ -761,32 +765,31 @@ func (d *Driver) Stop() {

func (d *Driver) GetBatchBlockRangeWithTimeout(ctx context.Context) (*big.Int, *big.Int, error) {
log.Debug("RollupTimeInterval start")
pollingInterval := 500 * time.Millisecond
rollupTimout := d.Cfg.RollupTimeout
exit := time.NewTimer(rollupTimout)
ticker := time.NewTicker(pollingInterval)
for {
// normal logic
start, end, err := d.GetBatchBlockRange(d.Ctx)
if err != nil {
return nil, nil, err
}
if big.NewInt(0).Sub(end, start).Cmp(big.NewInt(int64(d.Cfg.RollUpMinTxn))) >= 0 {
return start, end, nil
}
if start.Cmp(end) == 0 {
log.Info("MtBatcher Sequencer no updates", "start", start, "end", end)
continue
}
select {

case <-ticker.C:
if big.NewInt(0).Sub(end, start).Cmp(big.NewInt(int64(d.Cfg.RollUpMinTxn))) >= 0 {
return start, end, nil
}
if start.Cmp(end) == 0 {
log.Info("MtBatcher Sequencer no updates", "start", start, "end", end)
continue
}
case <-exit.C:
if big.NewInt(0).Sub(end, start).Cmp(big.NewInt(int64(d.Cfg.MinTimeoutRollupTxn))) >= 0 {
return start, end, nil
}
return nil, nil, errors.Errorf("error: Timeout txn < MinTimeoutRollupTxn")
// timeout exit
case <-ticker.C:
return nil, nil, errors.Errorf("error: Timeout txn less than MinTimeoutRollupTxn")
case err := <-d.Ctx.Done():
log.Error("MtBatcher get block range timeout error", "err", err)
return nil, nil, errors.New("MtBatcher get block range timeout error")
}
}
}
Expand All @@ -798,10 +801,9 @@ func (d *Driver) RollupMainWorker() {
for {
select {
case <-ticker.C:

start, end, err := d.GetBatchBlockRangeWithTimeout(d.Ctx)
if err != nil {
log.Error("MtBatcher Sequencer unable to get block range", "err", err)
log.Warn("MtBatcher Sequencer unable to get block range", "err", err)
continue
}
log.Info("MtBatcher get batch block range", "start", start, "end", end)
Expand Down

0 comments on commit 10f6f93

Please sign in to comment.