Skip to content

Commit

Permalink
Erigon 3: Fix occassional need for reorgs (during first sync in polyg…
Browse files Browse the repository at this point in the history
…on) through a "safety" threshold (#11819)

Always save last 8 blocks of a "block batch"
  • Loading branch information
Giulio2002 authored Sep 2, 2024
1 parent 9ab5bbd commit a8e795d
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions eth/stagedsync/exec3.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ var (
mxExecBlocks = metrics.NewGauge("exec_blocks")
)

const changesetBlockRange = 1_000 // Generate changeset only if execution of blocks <= changesetBlockRange
const (
changesetBlockRange = 1_000 // Generate changeset only if execution of blocks <= changesetBlockRange
changesetSafeRange = 32 // Safety net for long-sync, keep last 32 changesets
)

func NewProgress(prevOutputBlockNum, commitThreshold uint64, workersCount int, updateMetrics bool, logPrefix string, logger log.Logger) *Progress {
return &Progress{prevTime: time.Now(), prevOutputBlockNum: prevOutputBlockNum, commitThreshold: commitThreshold, workersCount: workersCount, logPrefix: logPrefix, logger: logger}
Expand Down Expand Up @@ -674,6 +677,21 @@ func ExecV3(ctx context.Context,

Loop:
for ; blockNum <= maxBlockNum; blockNum++ {
// set shouldGenerateChangesets=true if we are at last n blocks from maxBlockNum. this is as a safety net in chains
// where during initial sync we can expect bogus blocks to be imported.
if !shouldGenerateChangesets && blockNum > cfg.blockReader.FrozenBlocks() && blockNum+changesetSafeRange >= maxBlockNum {
aggTx := applyTx.(state2.HasAggTx).AggTx().(*state2.AggregatorRoTx)
aggTx.RestrictSubsetFileDeletions(true)
start := time.Now()
doms.SetChangesetAccumulator(nil) // Make sure we don't have an active changeset accumulator
// First compute and commit the progress done so far
if _, err := doms.ComputeCommitment(ctx, true, blockNum, execStage.LogPrefix()); err != nil {
return err
}
ts += time.Since(start)
aggTx.RestrictSubsetFileDeletions(false)
shouldGenerateChangesets = true // now we can generate changesets for the safety net
}
changeset := &state2.StateChangeSet{}
if shouldGenerateChangesets && blockNum > 0 {
doms.SetChangesetAccumulator(changeset)
Expand Down Expand Up @@ -916,7 +934,6 @@ Loop:
return err
}
}

doms.SetChangesetAccumulator(nil)
}

Expand Down

0 comments on commit a8e795d

Please sign in to comment.