diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 1c8ece0b9c6..756b1b9628c 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -410,6 +410,11 @@ var ( Usage: "The time to wait for data to arrive from the stream before reporting an error (0s doesn't check)", Value: "3s", } + L2ShortCircuitToVerifiedBatchFlag = cli.BoolFlag{ + Name: "zkevm.l2-short-circuit-to-verified-batch", + Usage: "Short circuit block execution up to the batch after the latest verified batch (default: true). When disabled, the sequencer will execute all downloaded batches", + Value: true, + } L1SyncStartBlock = cli.Uint64Flag{ Name: "zkevm.l1-sync-start-block", Usage: "Designed for recovery of the network from the L1 batch data, slower mode of operation than the datastream. If set the datastream will not be used", diff --git a/eth/ethconfig/config_zkevm.go b/eth/ethconfig/config_zkevm.go index 8cd78e64753..93a539b49a1 100644 --- a/eth/ethconfig/config_zkevm.go +++ b/eth/ethconfig/config_zkevm.go @@ -12,6 +12,7 @@ type Zk struct { L2RpcUrl string L2DataStreamerUrl string L2DataStreamerTimeout time.Duration + L2ShortCircuitToVerifiedBatch bool L1SyncStartBlock uint64 L1SyncStopBatch uint64 L1ChainId uint64 diff --git a/eth/stagedsync/stage_execute_zkevm.go b/eth/stagedsync/stage_execute_zkevm.go index 2cbe839888b..6debcc4ed88 100644 --- a/eth/stagedsync/stage_execute_zkevm.go +++ b/eth/stagedsync/stage_execute_zkevm.go @@ -264,7 +264,7 @@ func getExecRange(cfg ExecuteBlockCfg, tx kv.RwTx, stageProgress, toBlock uint64 return to, total, nil } - shouldShortCircuit, noProgressTo, err := utils.ShouldShortCircuitExecution(tx, logPrefix) + shouldShortCircuit, noProgressTo, err := utils.ShouldShortCircuitExecution(tx, logPrefix, cfg.zk.L2ShortCircuitToVerifiedBatch) if err != nil { return 0, 0, err } diff --git a/turbo/cli/default_flags.go b/turbo/cli/default_flags.go index b8dd0f6463e..9e9c9ba7af9 100644 --- a/turbo/cli/default_flags.go +++ b/turbo/cli/default_flags.go @@ -175,6 +175,7 @@ var DefaultFlags = []cli.Flag{ &utils.L2RpcUrlFlag, &utils.L2DataStreamerUrlFlag, &utils.L2DataStreamerTimeout, + &utils.L2ShortCircuitToVerifiedBatchFlag, &utils.L1SyncStartBlock, &utils.L1SyncStopBatch, &utils.L1ChainIdFlag, diff --git a/turbo/cli/flags_zkevm.go b/turbo/cli/flags_zkevm.go index 56ec8ec0bee..cc8416d4e40 100644 --- a/turbo/cli/flags_zkevm.go +++ b/turbo/cli/flags_zkevm.go @@ -8,13 +8,14 @@ import ( "time" + "strconv" + libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon/cmd/utils" "github.com/ledgerwatch/erigon/eth/ethconfig" "github.com/ledgerwatch/erigon/zk/sequencer" utils2 "github.com/ledgerwatch/erigon/zk/utils" "github.com/urfave/cli/v2" - "strconv" ) var DeprecatedFlags = map[string]string{ @@ -70,6 +71,8 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) { panic(fmt.Sprintf("could not parse l2 datastreamer timeout value %s", l2DataStreamTimeoutVal)) } + l2ShortCircuitToVerifiedBatchVal := ctx.Bool(utils.L2ShortCircuitToVerifiedBatchFlag.Name) + sequencerBlockSealTimeVal := ctx.String(utils.SequencerBlockSealTime.Name) sequencerBlockSealTime, err := time.ParseDuration(sequencerBlockSealTimeVal) if err != nil { @@ -133,6 +136,7 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) { L2RpcUrl: ctx.String(utils.L2RpcUrlFlag.Name), L2DataStreamerUrl: ctx.String(utils.L2DataStreamerUrlFlag.Name), L2DataStreamerTimeout: l2DataStreamTimeout, + L2ShortCircuitToVerifiedBatch: l2ShortCircuitToVerifiedBatchVal, L1SyncStartBlock: ctx.Uint64(utils.L1SyncStartBlock.Name), L1SyncStopBatch: ctx.Uint64(utils.L1SyncStopBatch.Name), L1ChainId: ctx.Uint64(utils.L1ChainIdFlag.Name), diff --git a/zk/utils/utils.go b/zk/utils/utils.go index 10eac499aed..4a10cfaa0a8 100644 --- a/zk/utils/utils.go +++ b/zk/utils/utils.go @@ -20,7 +20,7 @@ import ( // if current sync is before verified batch - short circuit to verified batch, otherwise to enx of next batch // if there is no new fully downloaded batch - do not short circuit // returns (shouldShortCircuit, blockNumber, error) -func ShouldShortCircuitExecution(tx kv.RwTx, logPrefix string) (bool, uint64, error) { +func ShouldShortCircuitExecution(tx kv.RwTx, logPrefix string, l2ShortCircuitToVerifiedBatch bool) (bool, uint64, error) { hermezDb := hermez_db.NewHermezDb(tx) // get highest verified batch @@ -48,10 +48,10 @@ func ShouldShortCircuitExecution(tx kv.RwTx, logPrefix string) (bool, uint64, er var shortCircuitBatch, shortCircuitBlock, cycle uint64 // this is so empty batches work - for shortCircuitBlock == 0 { + for shortCircuitBlock == 0 || (!l2ShortCircuitToVerifiedBatch && executedBatch+cycle < downloadedBatch) { cycle++ - // if executed lower than verified, short curcuit up to verified - if executedBatch < highestVerifiedBatchNo { + // if executed lower than verified, short circuit up to verified (only if l2ShortCircuitToVerifiedBatch is true) + if executedBatch < highestVerifiedBatchNo && l2ShortCircuitToVerifiedBatch { if downloadedBatch < highestVerifiedBatchNo { shortCircuitBatch = downloadedBatch } else { @@ -59,7 +59,7 @@ func ShouldShortCircuitExecution(tx kv.RwTx, logPrefix string) (bool, uint64, er } } else if executedBatch+cycle <= downloadedBatch { // else short circuit up to next downloaded batch shortCircuitBatch = executedBatch + cycle - } else { // if we don't have at least one more full downlaoded batch, don't short circuit and just execute to latest block + } else { // if we don't have at least one more full downloaded batch, don't short circuit and just execute to latest block return false, 0, nil }