Skip to content

Commit

Permalink
Add flag for bor waypoint types (#10281)
Browse files Browse the repository at this point in the history
This adds additional flag processing to disable waypoint snaps is
`bor.waypoints` is not set

Co-authored-by: alex.sharov <AskAlexSharov@gmail.com>
  • Loading branch information
2 people authored and yperbasis committed May 27, 2024
1 parent c0be07d commit 38d5672
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 2 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import (
"github.com/ledgerwatch/erigon/p2p/nat"
"github.com/ledgerwatch/erigon/p2p/netutil"
"github.com/ledgerwatch/erigon/params"
borsnaptype "github.com/ledgerwatch/erigon/polygon/bor/snaptype"
"github.com/ledgerwatch/erigon/rpc/rpccfg"
"github.com/ledgerwatch/erigon/turbo/logging"
)
Expand Down Expand Up @@ -1583,6 +1584,7 @@ func setBorConfig(ctx *cli.Context, cfg *ethconfig.Config) {
cfg.WithoutHeimdall = ctx.Bool(WithoutHeimdallFlag.Name)
cfg.WithHeimdallMilestones = ctx.Bool(WithHeimdallMilestones.Name)
cfg.WithHeimdallWaypointRecording = ctx.Bool(WithHeimdallWaypoints.Name)
borsnaptype.RecordWayPoints(cfg.WithHeimdallWaypointRecording)
cfg.PolygonSync = ctx.Bool(PolygonSyncFlag.Name)
}

Expand Down
2 changes: 1 addition & 1 deletion migrations/prohibit_new_downloads2.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var ProhibitNewDownloadsLock2 = Migration{
locked = append(locked, t.Name())
}

for _, t := range borsnaptype.BorSnapshotTypes {
for _, t := range borsnaptype.BorSnapshotTypes() {
locked = append(locked, t.Name())
}

Expand Down
23 changes: 20 additions & 3 deletions polygon/bor/snaptype/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ import (
)

func init() {
borTypes := append(coresnaptype.BlockSnapshotTypes, BorSnapshotTypes...)
initTypes()
}

func initTypes() {
borTypes := append(coresnaptype.BlockSnapshotTypes, BorSnapshotTypes()...)

snapcfg.RegisterKnownTypes(networkname.MumbaiChainName, borTypes)
snapcfg.RegisterKnownTypes(networkname.AmoyChainName, borTypes)
Expand Down Expand Up @@ -402,10 +406,23 @@ var (
return buildValueIndex(ctx, sn, salt, d, firstMilestoneId, tmpDir, p, lvl, logger)
}),
)

BorSnapshotTypes = []snaptype.Type{BorEvents, BorSpans, BorCheckpoints, BorMilestones}
)

var recordWaypoints bool

func RecordWayPoints(value bool) {
recordWaypoints = value
initTypes()
}

func BorSnapshotTypes() []snaptype.Type {
if recordWaypoints {
return []snaptype.Type{BorEvents, BorSpans, BorCheckpoints, BorMilestones}
}

return []snaptype.Type{BorEvents, BorSpans}
}

func extractValueRange(ctx context.Context, table string, valueFrom, valueTo uint64, db kv.RoDB, collect func([]byte) error, workers int, lvl log.Lvl, logger log.Logger) (uint64, error) {
logEvery := time.NewTicker(20 * time.Second)
defer logEvery.Stop()
Expand Down
6 changes: 3 additions & 3 deletions turbo/snapshotsync/freezeblocks/bor_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (br *BlockRetire) retireBorBlocks(ctx context.Context, minBlockNum uint64,
return nil
}

err := merger.Merge(ctx, &snapshots.RoSnapshots, borsnaptype.BorSnapshotTypes, rangesToMerge, snapshots.Dir(), true /* doIndex */, onMerge, onDelete)
err := merger.Merge(ctx, &snapshots.RoSnapshots, borsnaptype.BorSnapshotTypes(), rangesToMerge, snapshots.Dir(), true /* doIndex */, onMerge, onDelete)

if err != nil {
return blocksRetired, err
Expand All @@ -127,7 +127,7 @@ type BorRoSnapshots struct {
// - gaps are not allowed
// - segment have [from:to] semantic
func NewBorRoSnapshots(cfg ethconfig.BlocksFreezing, snapDir string, segmentsMin uint64, logger log.Logger) *BorRoSnapshots {
return &BorRoSnapshots{*newRoSnapshots(cfg, snapDir, borsnaptype.BorSnapshotTypes, segmentsMin, logger)}
return &BorRoSnapshots{*newRoSnapshots(cfg, snapDir, borsnaptype.BorSnapshotTypes(), segmentsMin, logger)}
}

func (s *BorRoSnapshots) Ranges() []Range {
Expand Down Expand Up @@ -199,7 +199,7 @@ func removeBorOverlaps(dir string, active []snaptype.FileInfo, max uint64) {
}

func (s *BorRoSnapshots) ReopenFolder() error {
files, _, err := typedSegments(s.dir, s.segmentsMin.Load(), borsnaptype.BorSnapshotTypes, false)
files, _, err := typedSegments(s.dir, s.segmentsMin.Load(), borsnaptype.BorSnapshotTypes(), false)
if err != nil {
return err
}
Expand Down

0 comments on commit 38d5672

Please sign in to comment.