Skip to content

Commit

Permalink
feat(availability): env var to disable pruning (celestiaorg#3949)
Browse files Browse the repository at this point in the history
This trick allowed me to reuse an old 8mb snapshot, even though it is already far beyond the availability window. I think it is helpful to add it to main.
  • Loading branch information
Wondertan authored Dec 3, 2024
1 parent 61d9a32 commit d726f11
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion share/availability/window.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package availability

import "time"
import (
"os"
"time"
)

const (
RequestWindow = 30 * 24 * time.Hour
Expand All @@ -11,8 +14,33 @@ const (
// given AvailabilityWindow. If the window is disabled (0), it returns true for
// every timestamp.
func IsWithinWindow(t time.Time, window time.Duration) bool {
if windowOverride {
window = windowOverrideDur
}
if window == time.Duration(0) {
return true
}
return time.Since(t) <= window
}

// windowOverride is a flag that overrides the availability window. This flag is intended for
// testing purposes only.
var (
windowOverride bool
windowOverrideDur time.Duration
)

func init() {
durationRaw, ok := os.LookupEnv("CELESTIA_OVERRIDE_AVAILABILITY_WINDOW")
if !ok {
return
}

duration, err := time.ParseDuration(durationRaw)
if err != nil {
panic("failed to parse CELESTIA_OVERRIDE_AVAILABILITY_WINDOW: " + err.Error())
}

windowOverride = true
windowOverrideDur = duration
}

0 comments on commit d726f11

Please sign in to comment.