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 Apr 10, 2024
1 parent 172e236 commit dccf56d
Show file tree
Hide file tree
Showing 2 changed files with 7 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

0 comments on commit dccf56d

Please sign in to comment.