-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Borevent snapshot validation (#9436)
This adds integrity checking for borevents in the following places 1. Stage Bor Heimdall - check that the event occurs withing the expected time window 2. Dump Events to snapshots - check that the event ids are continuous in and between blocks (will add a time window tests) 3. Index event snapshots - check that the event ids are continuous in and between blocks It also adds an external integrity checker which runs on snapshots checking for continuity and timeliness of events. This can be called using the following command: `erigon snapshots integrity --datadir=~/snapshots/bor-mainnet-patch-1 --from=45500000` (--to specifies an end block) This also now fixes the long running issue with bor events causing unexpected fails in executions: the problem event validation uncovered was a follows: The **kv.BorEventNums** mapping table currently keeps the mapping first event id->block. The code which produces bor-event snapshots to determine which events to put into the snapshot. however if no additional blocks have events by the time the block is stored in the snapshot, the snapshot creation code does not know which events to include - so drops them. This causes problems in two places: * RPC queries & re-execution from snapshots can't find these dropped events * Depending on purge timing these events may erroneously get inserted into future blocks The code change in this PR fixes that bug. It has been tested by running: ``` erigon --datadir=~/chains/e3/amoy --chain=amoy --bor.heimdall=https://heimdall-api-amoy.polygon.technology --db.writemap=false --txpool.disable --no-downloader --bor.milestone=false ``` with validation in place and the confimed by running the following: ``` erigon snapshots rm-all-state-snapshots --datadir=~/chains/e3/amoy rm ~/chains/e3/amoy/chaindata/ erigon --datadir=~/chains/e3/amoy --chain=amoy --bor-heimdall=https://heimdall-api-amoy.polygon.technology --db.writemap=false --no-downloader --bor.milestone=false ``` To recreate the chain from snapshots. It has also been checked with: ``` erigon snapshots integrity --datadir=~/chains/e3/amoy --check=NoBorEventGaps --failFast=true" ``` --------- Co-authored-by: alex.sharov <[email protected]> Co-authored-by: Mark Holt <[email protected]>
- Loading branch information
1 parent
48544c9
commit e4eb9fc
Showing
14 changed files
with
558 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,7 @@ | |
build/_vendor/pkg | ||
/*.a | ||
docs/readthedocs/build | ||
/.VSCodeCounter/ | ||
|
||
/.VSCodeCounter | ||
#* | ||
.#* | ||
*# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package integrity | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/erigontech/erigon-lib/chain" | ||
"github.com/erigontech/erigon-lib/kv" | ||
"github.com/erigontech/erigon-lib/log/v3" | ||
"github.com/erigontech/erigon/core" | ||
"github.com/erigontech/erigon/eth/stagedsync/stages" | ||
"github.com/erigontech/erigon/polygon/bor/borcfg" | ||
"github.com/erigontech/erigon/turbo/services" | ||
"github.com/erigontech/erigon/turbo/snapshotsync/freezeblocks" | ||
) | ||
|
||
func NoGapsInBorEvents(ctx context.Context, db kv.RoDB, blockReader services.FullBlockReader, from, to uint64, failFast bool) (err error) { | ||
defer func() { | ||
log.Info("[integrity] NoGapsInBorEvents: done", "err", err) | ||
}() | ||
|
||
var cc *chain.Config | ||
|
||
if db == nil { | ||
genesis := core.BorMainnetGenesisBlock() | ||
cc = genesis.Config | ||
} else { | ||
err = db.View(ctx, func(tx kv.Tx) error { | ||
cc, err = chain.GetConfig(tx, nil) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}) | ||
|
||
if err != nil { | ||
err = fmt.Errorf("cant read chain config from db: %w", err) | ||
return err | ||
} | ||
} | ||
|
||
if cc.BorJSON == nil { | ||
return err | ||
} | ||
|
||
config := &borcfg.BorConfig{} | ||
|
||
if err := json.Unmarshal(cc.BorJSON, config); err != nil { | ||
err = fmt.Errorf("invalid chain config 'bor' JSON: %w", err) | ||
return err | ||
} | ||
|
||
logEvery := time.NewTicker(10 * time.Second) | ||
defer logEvery.Stop() | ||
|
||
snapshots := blockReader.BorSnapshots().(*freezeblocks.BorRoSnapshots) | ||
|
||
var prevEventId uint64 | ||
var maxBlockNum uint64 | ||
|
||
if to > 0 { | ||
maxBlockNum = to | ||
} else { | ||
maxBlockNum = snapshots.SegmentsMax() | ||
} | ||
|
||
view := snapshots.View() | ||
defer view.Close() | ||
|
||
for _, eventSegment := range view.Events() { | ||
|
||
if from > 0 && eventSegment.From() < from { | ||
continue | ||
} | ||
|
||
if to > 0 && eventSegment.From() > to { | ||
break | ||
} | ||
|
||
prevEventId, err = freezeblocks.ValidateBorEvents(ctx, config, db, blockReader, eventSegment, prevEventId, maxBlockNum, failFast, logEvery) | ||
|
||
if err != nil && failFast { | ||
return err | ||
} | ||
} | ||
|
||
if db != nil { | ||
err = db.View(ctx, func(tx kv.Tx) error { | ||
if false { | ||
lastEventId, _, err := blockReader.LastEventId(ctx, tx) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
borHeimdallProgress, err := stages.GetStageProgress(tx, stages.BorHeimdall) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
bodyProgress, err := stages.GetStageProgress(tx, stages.Bodies) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Info("[integrity] LAST Event", "event", lastEventId, "bor-progress", borHeimdallProgress, "body-progress", bodyProgress) | ||
|
||
if bodyProgress > borHeimdallProgress { | ||
for blockNum := maxBlockNum + 1; blockNum <= bodyProgress; blockNum++ { | ||
|
||
} | ||
} | ||
} | ||
|
||
return nil | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
log.Info("[integrity] done checking bor events", "event", prevEventId) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,7 @@ func MiningBorHeimdallForward( | |
logger, | ||
lastStateSyncEventID, | ||
) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
Oops, something went wrong.