Skip to content

Commit

Permalink
chore(das): clean up daser recency check
Browse files Browse the repository at this point in the history
  • Loading branch information
renaynay committed Mar 18, 2024
1 parent dfe415f commit ffab4a1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 1 addition & 9 deletions das/daser.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (d *DASer) Stop(ctx context.Context) error {
func (d *DASer) sample(ctx context.Context, h *header.ExtendedHeader) error {
// short-circuit if pruning is enabled and the header is outside the
// availability window
if !d.isWithinSamplingWindow(h) {
if !pruner.IsWithinAvailabilityWindow(h.Time(), pruner.AvailabilityWindow(d.params.SamplingWindow)) {
log.Debugw("skipping header outside sampling window", "height", h.Height(),
"time", h.Time())
return nil
Expand All @@ -171,14 +171,6 @@ func (d *DASer) sample(ctx context.Context, h *header.ExtendedHeader) error {
return nil
}

func (d *DASer) isWithinSamplingWindow(eh *header.ExtendedHeader) bool {
// if sampling window is not set, then all headers are within the window
if d.params.SamplingWindow == 0 {
return true
}
return pruner.IsWithinAvailabilityWindow(eh.Time(), pruner.AvailabilityWindow(d.params.SamplingWindow))
}

// SamplingStats returns the current statistics over the DA sampling process.
func (d *DASer) SamplingStats(ctx context.Context) (SamplingStats, error) {
return d.sampler.stats(ctx)
Expand Down
7 changes: 6 additions & 1 deletion das/daser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/header/headertest"
headerfraud "github.com/celestiaorg/celestia-node/header/headertest/fraud"
"github.com/celestiaorg/celestia-node/pruner"
"github.com/celestiaorg/celestia-node/share"
"github.com/celestiaorg/celestia-node/share/availability/full"
"github.com/celestiaorg/celestia-node/share/availability/light"
Expand Down Expand Up @@ -275,7 +276,11 @@ func TestDASer_SamplingWindow(t *testing.T) {
eh := headertest.RandExtendedHeader(t)
eh.RawHeader.Time = tt.timestamp

assert.Equal(t, tt.withinWindow, daser.isWithinSamplingWindow(eh))
assert.Equal(
t,
tt.withinWindow,
pruner.IsWithinAvailabilityWindow(eh.Time(), pruner.AvailabilityWindow(daser.params.SamplingWindow)),
)
})
}

Expand Down
3 changes: 3 additions & 0 deletions pruner/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ import (
type AvailabilityWindow time.Duration

func IsWithinAvailabilityWindow(t time.Time, window AvailabilityWindow) bool {
if window == AvailabilityWindow(time.Duration(0)) {
return true
}
return time.Since(t) <= time.Duration(window)
}

0 comments on commit ffab4a1

Please sign in to comment.