From 8e7e7b7674fa4fef44fc8803e08f5a1ace7a4f9a Mon Sep 17 00:00:00 2001 From: Moreti Georgiev Date: Thu, 5 Dec 2024 14:21:13 +0200 Subject: [PATCH] feat: add flag for empty block close time --- cmd/utils/flags.go | 5 +++++ eth/ethconfig/config_zkevm.go | 1 + turbo/cli/default_flags.go | 1 + turbo/cli/flags_zkevm.go | 17 +++++++++++++---- zk/stages/stage_sequence_execute.go | 11 +++++++++-- zk/stages/stage_sequence_execute_utils.go | 11 +++++------ 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index c670d212209..d37d7dc5881 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -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", diff --git a/eth/ethconfig/config_zkevm.go b/eth/ethconfig/config_zkevm.go index 3142a368e57..fb42bbdbcf9 100644 --- a/eth/ethconfig/config_zkevm.go +++ b/eth/ethconfig/config_zkevm.go @@ -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 diff --git a/turbo/cli/default_flags.go b/turbo/cli/default_flags.go index 35a753021c2..2d56f860fb9 100644 --- a/turbo/cli/default_flags.go +++ b/turbo/cli/default_flags.go @@ -205,6 +205,7 @@ var DefaultFlags = []cli.Flag{ &utils.IncrementTreeAlways, &utils.SmtRegenerateInMemory, &utils.SequencerBlockSealTime, + &utils.SequencerEmptyBlockSealTime, &utils.SequencerBatchSealTime, &utils.SequencerBatchVerificationTimeout, &utils.SequencerBatchVerificationRetries, diff --git a/turbo/cli/flags_zkevm.go b/turbo/cli/flags_zkevm.go index e71fb621ecc..7d0cb9325d3 100644 --- a/turbo/cli/flags_zkevm.go +++ b/turbo/cli/flags_zkevm.go @@ -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" @@ -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 { @@ -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), diff --git a/zk/stages/stage_sequence_execute.go b/zk/stages/stage_sequence_execute.go index 1fe337c4397..a330827717e 100644 --- a/zk/stages/stage_sequence_execute.go +++ b/zk/stages/stage_sequence_execute.go @@ -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)) @@ -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) @@ -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: diff --git a/zk/stages/stage_sequence_execute_utils.go b/zk/stages/stage_sequence_execute_utils.go index 62460830fc5..a2d5ebce646 100644 --- a/zk/stages/stage_sequence_execute_utils.go +++ b/zk/stages/stage_sequence_execute_utils.go @@ -2,6 +2,8 @@ package stages import ( "context" + "fmt" + "math/big" "time" "github.com/c2h5oh/datasize" @@ -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" @@ -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