Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag for bor waypoint types #10281

Merged
merged 2 commits into from
May 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
@@ -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"
)
@@ -1578,6 +1579,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)
cfg.PolygonSyncStage = ctx.Bool(PolygonSyncStageFlag.Name)
}
2 changes: 1 addition & 1 deletion migrations/prohibit_new_downloads2.go
Original file line number Diff line number Diff line change
@@ -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())
}

23 changes: 20 additions & 3 deletions polygon/bor/snaptype/types.go
Original file line number Diff line number Diff line change
@@ -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)
@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

global variables are not friendly for unit-tests. same as init funcs.


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()
6 changes: 3 additions & 3 deletions turbo/snapshotsync/freezeblocks/bor_snapshots.go
Original file line number Diff line number Diff line change
@@ -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
@@ -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 {
@@ -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
}