Skip to content

Commit

Permalink
agg layer network sync fixes
Browse files Browse the repository at this point in the history
handles pre etrog events properly and filters on rollup
  • Loading branch information
revitteth authored and hexoscott committed Oct 30, 2024
1 parent 434376b commit 88ba898
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 17 deletions.
5 changes: 5 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,11 @@ var (
Usage: "The multiplier to reduce the SMT depth by when calculating virtual counters",
Value: 0.6,
}
BadBatches = cli.StringFlag{
Name: "zkevm.bad-batches",
Usage: "A comma separated list of batch numbers that are known bad on the L1. These will automatically be marked as bad during L1 recovery",
Value: "",
}
InitialBatchCfgFile = cli.StringFlag{
Name: "zkevm.initial-batch.config",
Usage: "The file that contains the initial (injected) batch data.",
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 @@ -87,6 +87,7 @@ type Zk struct {

TxPoolRejectSmartContractDeployments bool

BadBatches []uint64
InitialBatchCfgFile string
ACLPrintHistory 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 @@ -281,6 +281,7 @@ var DefaultFlags = []cli.Flag{
&utils.DisableVirtualCounters,
&utils.DAUrl,
&utils.VirtualCountersSmtReduction,
&utils.BadBatches,
&utils.InitialBatchCfgFile,

&utils.ACLPrintHistory,
Expand Down
17 changes: 17 additions & 0 deletions turbo/cli/flags_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ledgerwatch/erigon/zk/sequencer"
utils2 "github.com/ledgerwatch/erigon/zk/utils"
"github.com/urfave/cli/v2"
"strconv"
)

var DeprecatedFlags = map[string]string{
Expand Down Expand Up @@ -112,6 +113,21 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) {

witnessMemSize := utils.DatasizeFlagValue(ctx, utils.WitnessMemdbSize.Name)

badBatchStrings := strings.Split(ctx.String(utils.BadBatches.Name), ",")
badBatches := make([]uint64, 0)
for _, s := range badBatchStrings {
if s == "" {
// if there are no entries then we can just ignore it and move on
continue
}
// parse the string as uint64
val, err := strconv.ParseUint(s, 10, 64)
if err != nil {
panic(fmt.Sprintf("could not parse bad batch number %s", s))
}
badBatches = append(badBatches, val)
}

cfg.Zk = &ethconfig.Zk{
L2ChainId: ctx.Uint64(utils.L2ChainIdFlag.Name),
L2RpcUrl: ctx.String(utils.L2RpcUrlFlag.Name),
Expand Down Expand Up @@ -184,6 +200,7 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) {
DataStreamWriteTimeout: ctx.Duration(utils.DataStreamWriteTimeout.Name),
DataStreamInactivityTimeout: ctx.Duration(utils.DataStreamInactivityTimeout.Name),
VirtualCountersSmtReduction: ctx.Float64(utils.VirtualCountersSmtReduction.Name),
BadBatches: badBatches,
InitialBatchCfgFile: ctx.String(utils.InitialBatchCfgFile.Name),
ACLPrintHistory: ctx.Int(utils.ACLPrintHistory.Name),
}
Expand Down
20 changes: 18 additions & 2 deletions zk/stages/stage_sequence_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,24 @@ func sequencingBatchStep(
return nil
}

if handled, err := doCheckForBadBatch(batchContext, batchState, executionAt); err != nil || handled {
return err
bad := false
for _, batch := range cfg.zk.BadBatches {
if batch == batchState.batchNumber {
bad = true
break
}
}

// if we aren't forcing a bad batch then check it
if !bad {
bad, err = doCheckForBadBatch(batchContext, batchState, executionAt)
if err != nil {
return err
}
}

if bad {
return writeBadBatchDetails(batchContext, batchState, executionAt)
}
}

Expand Down
28 changes: 14 additions & 14 deletions zk/stages/stage_sequence_execute_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,28 @@ func doCheckForBadBatch(batchContext *BatchContext, batchState *BatchState, this
return false, err
}

if !badBatch {
return false, nil
}
return badBatch, nil
}

func writeBadBatchDetails(batchContext *BatchContext, batchState *BatchState, blockNumber uint64) error {
log.Info(fmt.Sprintf("[%s] Skipping bad batch %d...", batchContext.s.LogPrefix(), batchState.batchNumber))
// store the fact that this batch was invalid during recovery - will be used for the stream later
if err = batchContext.sdb.hermezDb.WriteInvalidBatch(batchState.batchNumber); err != nil {
return false, err
if err := batchContext.sdb.hermezDb.WriteInvalidBatch(batchState.batchNumber); err != nil {
return err
}
if err = batchContext.sdb.hermezDb.WriteBatchCounters(currentBlock.NumberU64(), []int{}); err != nil {
return false, err
if err := batchContext.sdb.hermezDb.WriteBatchCounters(blockNumber, []int{}); err != nil {
return err
}
if err = stages.SaveStageProgress(batchContext.sdb.tx, stages.HighestSeenBatchNumber, batchState.batchNumber); err != nil {
return false, err
if err := stages.SaveStageProgress(batchContext.sdb.tx, stages.HighestSeenBatchNumber, batchState.batchNumber); err != nil {
return err
}
if err = batchContext.sdb.hermezDb.WriteForkId(batchState.batchNumber, batchState.forkId); err != nil {
return false, err
if err := batchContext.sdb.hermezDb.WriteForkId(batchState.batchNumber, batchState.forkId); err != nil {
return err
}
if err = batchContext.sdb.tx.Commit(); err != nil {
return false, err
if err := batchContext.sdb.tx.Commit(); err != nil {
return err
}
return true, nil
return nil
}

func updateStreamAndCheckRollback(
Expand Down
2 changes: 1 addition & 1 deletion zk/stages/stage_sequence_execute_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (bs *BatchState) getBlockHeaderForcedTimestamp() uint64 {
}

func (bs *BatchState) getCoinbase(cfg *SequenceBlockCfg) common.Address {
if bs.isL1Recovery() {
if bs.batchNumber > 1 && bs.isL1Recovery() {
return bs.batchL1RecoveryData.recoveredBatchData.Coinbase
}

Expand Down

0 comments on commit 88ba898

Please sign in to comment.