Skip to content

Commit 3f88803

Browse files
authored
Allow execution to short circuit to the last downloaded batch (0xPolygonHermez#1432)
1 parent 41a3543 commit 3f88803

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

cmd/utils/flags.go

+5
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,11 @@ var (
410410
Usage: "The time to wait for data to arrive from the stream before reporting an error (0s doesn't check)",
411411
Value: "3s",
412412
}
413+
L2ShortCircuitToVerifiedBatchFlag = cli.BoolFlag{
414+
Name: "zkevm.l2-short-circuit-to-verified-batch",
415+
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",
416+
Value: true,
417+
}
413418
L1SyncStartBlock = cli.Uint64Flag{
414419
Name: "zkevm.l1-sync-start-block",
415420
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",

eth/ethconfig/config_zkevm.go

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Zk struct {
1212
L2RpcUrl string
1313
L2DataStreamerUrl string
1414
L2DataStreamerTimeout time.Duration
15+
L2ShortCircuitToVerifiedBatch bool
1516
L1SyncStartBlock uint64
1617
L1SyncStopBatch uint64
1718
L1ChainId uint64

eth/stagedsync/stage_execute_zkevm.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func getExecRange(cfg ExecuteBlockCfg, tx kv.RwTx, stageProgress, toBlock uint64
264264
return to, total, nil
265265
}
266266

267-
shouldShortCircuit, noProgressTo, err := utils.ShouldShortCircuitExecution(tx, logPrefix)
267+
shouldShortCircuit, noProgressTo, err := utils.ShouldShortCircuitExecution(tx, logPrefix, cfg.zk.L2ShortCircuitToVerifiedBatch)
268268
if err != nil {
269269
return 0, 0, err
270270
}

turbo/cli/default_flags.go

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ var DefaultFlags = []cli.Flag{
175175
&utils.L2RpcUrlFlag,
176176
&utils.L2DataStreamerUrlFlag,
177177
&utils.L2DataStreamerTimeout,
178+
&utils.L2ShortCircuitToVerifiedBatchFlag,
178179
&utils.L1SyncStartBlock,
179180
&utils.L1SyncStopBatch,
180181
&utils.L1ChainIdFlag,

turbo/cli/flags_zkevm.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import (
88

99
"time"
1010

11+
"strconv"
12+
1113
libcommon "github.com/ledgerwatch/erigon-lib/common"
1214
"github.com/ledgerwatch/erigon/cmd/utils"
1315
"github.com/ledgerwatch/erigon/eth/ethconfig"
1416
"github.com/ledgerwatch/erigon/zk/sequencer"
1517
utils2 "github.com/ledgerwatch/erigon/zk/utils"
1618
"github.com/urfave/cli/v2"
17-
"strconv"
1819
)
1920

2021
var DeprecatedFlags = map[string]string{
@@ -70,6 +71,8 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) {
7071
panic(fmt.Sprintf("could not parse l2 datastreamer timeout value %s", l2DataStreamTimeoutVal))
7172
}
7273

74+
l2ShortCircuitToVerifiedBatchVal := ctx.Bool(utils.L2ShortCircuitToVerifiedBatchFlag.Name)
75+
7376
sequencerBlockSealTimeVal := ctx.String(utils.SequencerBlockSealTime.Name)
7477
sequencerBlockSealTime, err := time.ParseDuration(sequencerBlockSealTimeVal)
7578
if err != nil {
@@ -133,6 +136,7 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) {
133136
L2RpcUrl: ctx.String(utils.L2RpcUrlFlag.Name),
134137
L2DataStreamerUrl: ctx.String(utils.L2DataStreamerUrlFlag.Name),
135138
L2DataStreamerTimeout: l2DataStreamTimeout,
139+
L2ShortCircuitToVerifiedBatch: l2ShortCircuitToVerifiedBatchVal,
136140
L1SyncStartBlock: ctx.Uint64(utils.L1SyncStartBlock.Name),
137141
L1SyncStopBatch: ctx.Uint64(utils.L1SyncStopBatch.Name),
138142
L1ChainId: ctx.Uint64(utils.L1ChainIdFlag.Name),

zk/utils/utils.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
// if current sync is before verified batch - short circuit to verified batch, otherwise to enx of next batch
2121
// if there is no new fully downloaded batch - do not short circuit
2222
// returns (shouldShortCircuit, blockNumber, error)
23-
func ShouldShortCircuitExecution(tx kv.RwTx, logPrefix string) (bool, uint64, error) {
23+
func ShouldShortCircuitExecution(tx kv.RwTx, logPrefix string, l2ShortCircuitToVerifiedBatch bool) (bool, uint64, error) {
2424
hermezDb := hermez_db.NewHermezDb(tx)
2525

2626
// get highest verified batch
@@ -48,18 +48,18 @@ func ShouldShortCircuitExecution(tx kv.RwTx, logPrefix string) (bool, uint64, er
4848
var shortCircuitBatch, shortCircuitBlock, cycle uint64
4949

5050
// this is so empty batches work
51-
for shortCircuitBlock == 0 {
51+
for shortCircuitBlock == 0 || (!l2ShortCircuitToVerifiedBatch && executedBatch+cycle < downloadedBatch) {
5252
cycle++
53-
// if executed lower than verified, short curcuit up to verified
54-
if executedBatch < highestVerifiedBatchNo {
53+
// if executed lower than verified, short circuit up to verified (only if l2ShortCircuitToVerifiedBatch is true)
54+
if executedBatch < highestVerifiedBatchNo && l2ShortCircuitToVerifiedBatch {
5555
if downloadedBatch < highestVerifiedBatchNo {
5656
shortCircuitBatch = downloadedBatch
5757
} else {
5858
shortCircuitBatch = highestVerifiedBatchNo
5959
}
6060
} else if executedBatch+cycle <= downloadedBatch { // else short circuit up to next downloaded batch
6161
shortCircuitBatch = executedBatch + cycle
62-
} else { // if we don't have at least one more full downlaoded batch, don't short circuit and just execute to latest block
62+
} else { // if we don't have at least one more full downloaded batch, don't short circuit and just execute to latest block
6363
return false, 0, nil
6464
}
6565

0 commit comments

Comments
 (0)