Skip to content

Commit

Permalink
feat: add flag for empty block close time
Browse files Browse the repository at this point in the history
  • Loading branch information
MorettiGeorgiev committed Dec 5, 2024
1 parent f4f6201 commit 8e7e7b7
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
5 changes: 5 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,11 @@ var (
Usage: "Block seal time. Defaults to 6s",
Value: "6s",
}
SequencerEmptyBlockSealTime = cli.StringFlag{
Name: "zkevm.sequencer-empty-block-seal-time",
Usage: "Empty block seal time. Defaults to zkevm.sequencer-block-seal-time",
Value: "",
}
SequencerBatchSealTime = cli.StringFlag{
Name: "zkevm.sequencer-batch-seal-time",
Usage: "Batch seal time. Defaults to 12s",
Expand Down
1 change: 1 addition & 0 deletions eth/ethconfig/config_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Zk struct {
RpcGetBatchWitnessConcurrencyLimit int
DatastreamVersion int
SequencerBlockSealTime time.Duration
SequencerEmptyBlockSealTime time.Duration
SequencerBatchSealTime time.Duration
SequencerBatchVerificationTimeout time.Duration
SequencerBatchVerificationRetries int
Expand Down
1 change: 1 addition & 0 deletions turbo/cli/default_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ var DefaultFlags = []cli.Flag{
&utils.IncrementTreeAlways,
&utils.SmtRegenerateInMemory,
&utils.SequencerBlockSealTime,
&utils.SequencerEmptyBlockSealTime,
&utils.SequencerBatchSealTime,
&utils.SequencerBatchVerificationTimeout,
&utils.SequencerBatchVerificationRetries,
Expand Down
17 changes: 13 additions & 4 deletions turbo/cli/flags_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ package cli
import (
"fmt"
"math"

"strconv"
"strings"

"time"

"strconv"

libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/cmd/utils"
"github.com/ledgerwatch/erigon/eth/ethconfig"
Expand Down Expand Up @@ -79,6 +76,17 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) {
panic(fmt.Sprintf("could not parse sequencer block seal time timeout value %s", sequencerBlockSealTimeVal))
}

var sequencerEmptyBlockSealTime time.Duration
sequencerEmptyBlockSealTimeVal := ctx.String(utils.SequencerEmptyBlockSealTime.Name)
if sequencerEmptyBlockSealTimeVal == "" {
sequencerEmptyBlockSealTime = sequencerBlockSealTime
} else {
sequencerEmptyBlockSealTime, err = time.ParseDuration(sequencerEmptyBlockSealTimeVal)
if err != nil {
panic(fmt.Sprintf("could not parse sequencer empty block seal time timeout value %s", sequencerEmptyBlockSealTimeVal))
}
}

sequencerBatchSealTimeVal := ctx.String(utils.SequencerBatchSealTime.Name)
sequencerBatchSealTime, err := time.ParseDuration(sequencerBatchSealTimeVal)
if err != nil {
Expand Down Expand Up @@ -179,6 +187,7 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) {
IncrementTreeAlways: ctx.Bool(utils.IncrementTreeAlways.Name),
SmtRegenerateInMemory: ctx.Bool(utils.SmtRegenerateInMemory.Name),
SequencerBlockSealTime: sequencerBlockSealTime,
SequencerEmptyBlockSealTime: sequencerEmptyBlockSealTime,
SequencerBatchSealTime: sequencerBatchSealTime,
SequencerBatchVerificationTimeout: sequencerBatchVerificationTimeout,
SequencerBatchVerificationRetries: ctx.Int(utils.SequencerBatchVerificationRetries.Name),
Expand Down
11 changes: 9 additions & 2 deletions zk/stages/stage_sequence_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,11 @@ func sequencingBatchStep(
}
}

batchTicker, logTicker, blockTicker, infoTreeTicker := prepareTickers(batchContext.cfg)
batchTicker, logTicker, blockTicker, emptyBlockTicker, infoTreeTicker := prepareTickers(batchContext.cfg)
defer batchTicker.Stop()
defer logTicker.Stop()
defer blockTicker.Stop()
defer emptyBlockTicker.Stop()
defer infoTreeTicker.Stop()

log.Info(fmt.Sprintf("[%s] Starting batch %d...", logPrefix, batchState.batchNumber))
Expand All @@ -236,6 +237,7 @@ func sequencingBatchStep(
log.Info(fmt.Sprintf("[%s] Starting block %d (forkid %v)...", logPrefix, blockNumber, batchState.forkId))
logTicker.Reset(10 * time.Second)
blockTicker.Reset(cfg.zk.SequencerBlockSealTime)
emptyBlockTicker.Reset(cfg.zk.SequencerEmptyBlockSealTime)

if batchState.isL1Recovery() {
blockNumbersInBatchSoFar, err := batchContext.sdb.hermezDb.GetL2BlockNosByBatch(batchState.batchNumber)
Expand Down Expand Up @@ -322,7 +324,12 @@ func sequencingBatchStep(
log.Info(fmt.Sprintf("[%s] Waiting some more for txs from the pool...", logPrefix))
}
case <-blockTicker.C:
if !batchState.isAnyRecovery() {
if len(batchState.blockState.transactionHashesToSlots) > 0 && !batchState.isAnyRecovery() {
break OuterLoopTransactions
}

case <-emptyBlockTicker.C:
if len(batchState.blockState.transactionHashesToSlots) == 0 && !batchState.isAnyRecovery() {
break OuterLoopTransactions
}
case <-batchTicker.C:
Expand Down
11 changes: 5 additions & 6 deletions zk/stages/stage_sequence_execute_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package stages

import (
"context"
"fmt"
"math/big"
"time"

"github.com/c2h5oh/datasize"
Expand All @@ -10,10 +12,6 @@ import (
"github.com/ledgerwatch/erigon-lib/kv"
libstate "github.com/ledgerwatch/erigon-lib/state"

"math/big"

"fmt"

"github.com/ledgerwatch/erigon-lib/chain"
"github.com/ledgerwatch/erigon/common/math"
"github.com/ledgerwatch/erigon/consensus"
Expand Down Expand Up @@ -338,13 +336,14 @@ func prepareL1AndInfoTreeRelatedStuff(sdb *stageDb, batchState *BatchState, prop
return
}

func prepareTickers(cfg *SequenceBlockCfg) (*time.Ticker, *time.Ticker, *time.Ticker, *time.Ticker) {
func prepareTickers(cfg *SequenceBlockCfg) (*time.Ticker, *time.Ticker, *time.Ticker, *time.Ticker, *time.Ticker) {
batchTicker := time.NewTicker(cfg.zk.SequencerBatchSealTime)
logTicker := time.NewTicker(10 * time.Second)
blockTicker := time.NewTicker(cfg.zk.SequencerBlockSealTime)
emptyBlockTicker := time.NewTicker(cfg.zk.SequencerEmptyBlockSealTime)
infoTreeTicker := time.NewTicker(cfg.zk.InfoTreeUpdateInterval)

return batchTicker, logTicker, blockTicker, infoTreeTicker
return batchTicker, logTicker, blockTicker, emptyBlockTicker, infoTreeTicker
}

// will be called at the start of every new block created within a batch to figure out if there is a new GER
Expand Down

0 comments on commit 8e7e7b7

Please sign in to comment.