Skip to content

Commit

Permalink
chore: start serve-snapshots from second latest snapshot (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
troykessler authored Jan 13, 2025
1 parent 6a08a5f commit 15a090f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion app/collector/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,15 @@ func (collector *KyveSnapshotCollector) GetInterval() int64 {
return collector.interval
}

func (collector *KyveSnapshotCollector) GetSnapshotHeight(targetHeight int64) int64 {
func (collector *KyveSnapshotCollector) GetSnapshotHeight(targetHeight int64, isServeSnapshot bool) int64 {
// if no target height was given the snapshot height is the latest available,
// also if the target height is greater than the latest available height
if targetHeight == 0 || targetHeight > collector.latestAvailableHeight {
// if we run the serve-snapshot command we actually do not want to sync to the latest available height
// or else the node operator has to wait until the next snapshot is created in order to join the pool.
if isServeSnapshot && collector.latestAvailableHeight > collector.interval {
return collector.latestAvailableHeight - collector.interval
}
return collector.latestAvailableHeight
}

Expand Down
2 changes: 1 addition & 1 deletion sync/heightsync/heightsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func Start() error {
return fmt.Errorf("failed to init kyve block collector: %w", err)
}

snapshotHeight := snapshotCollector.GetSnapshotHeight(flags.TargetHeight)
snapshotHeight := snapshotCollector.GetSnapshotHeight(flags.TargetHeight, false)
metrics.SetSnapshotHeight(snapshotHeight)

canApplySnapshot := snapshotHeight > 0 && app.IsReset()
Expand Down
4 changes: 3 additions & 1 deletion sync/servesnapshots/servesnapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ func Start() error {
return fmt.Errorf("failed to init kyve block collector: %w", err)
}

snapshotHeight := snapshotCollector.GetSnapshotHeight(flags.StartHeight)
snapshotHeight := snapshotCollector.GetSnapshotHeight(flags.StartHeight, true)
if snapshotHeight < flags.StartHeight {
}
metrics.SetSnapshotHeight(snapshotHeight)

canApplySnapshot := snapshotHeight > 0 && app.IsReset()
Expand Down
2 changes: 1 addition & 1 deletion sync/statesync/statesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Start() error {
return fmt.Errorf("failed to init kyve snapshot collector: %w", err)
}

snapshotHeight := snapshotCollector.GetSnapshotHeight(flags.TargetHeight)
snapshotHeight := snapshotCollector.GetSnapshotHeight(flags.TargetHeight, false)
metrics.SetSnapshotHeight(snapshotHeight)

if snapshotHeight == 0 {
Expand Down
2 changes: 1 addition & 1 deletion types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type SnapshotCollector interface {

// GetSnapshotHeight gets the exact height of the nearest snapshot before the target
// height
GetSnapshotHeight(targetHeight int64) int64
GetSnapshotHeight(targetHeight int64, isServeSnapshot bool) int64

// GetSnapshotFromBundleId gets the snapshot from the given bundle
GetSnapshotFromBundleId(bundleId int64) (*SnapshotDataItem, error)
Expand Down

0 comments on commit 15a090f

Please sign in to comment.