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
Show file tree
Hide file tree
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
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 @@ -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)
}
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
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()
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
Loading