Skip to content

Commit

Permalink
fix(das): Clarify logs for historic headers that are skipped (#3380)
Browse files Browse the repository at this point in the history
Fix is kind of ugly but there needs to be a way to bubble up to worker
that the header is skipped vs being sampled successfully.

Resolves #3194
  • Loading branch information
renaynay authored and Wondertan committed May 20, 2024
1 parent 72111f4 commit e40a109
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion das/daser.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import (

var log = logging.Logger("das")

// errOutsideSamplingWindow is an error used to inform
// the caller of Sample that the given header is outside
// the sampling window.
var errOutsideSamplingWindow = fmt.Errorf("skipping header outside of sampling window")

// DASer continuously validates availability of data committed to headers.
type DASer struct {
params Parameters
Expand Down Expand Up @@ -160,7 +165,7 @@ func (d *DASer) sample(ctx context.Context, h *header.ExtendedHeader) error {
if !d.isWithinSamplingWindow(h) {
log.Debugw("skipping header outside sampling window", "height", h.Height(),
"time", h.Time())
return nil
return errOutsideSamplingWindow
}

err := d.da.SharesAvailable(ctx, h)
Expand Down
13 changes: 13 additions & 0 deletions das/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,18 @@ func (w *worker) run(ctx context.Context, timeout time.Duration, resultCh chan<-
jobStart := time.Now()
log.Debugw("start sampling worker", "from", w.state.from, "to", w.state.to)

skipped := 0

for curr := w.state.from; curr <= w.state.to; curr++ {
err := w.sample(ctx, timeout, curr)
if errors.Is(err, context.Canceled) {
// sampling worker will resume upon restart
return
}
if errors.Is(err, errOutsideSamplingWindow) {
skipped++
err = nil
}
w.setResult(curr, err)
}

Expand All @@ -91,6 +97,7 @@ func (w *worker) run(ctx context.Context, timeout time.Duration, resultCh chan<-
"from", w.state.from,
"to", w.state.curr,
"errors", len(w.state.failed),
"# of headers skipped as outside of sampling window", skipped,
"finished (s)", time.Since(jobStart),
)
}
Expand All @@ -112,6 +119,12 @@ func (w *worker) sample(ctx context.Context, timeout time.Duration, height uint6
defer cancel()

err = w.sampleFn(ctx, h)
if errors.Is(err, errOutsideSamplingWindow) {
// if header is outside sampling window, do not log
// or record it.
return err
}

w.metrics.observeSample(ctx, h, time.Since(start), w.state.jobType, err)
if err != nil {
if !errors.Is(err, context.Canceled) {
Expand Down

0 comments on commit e40a109

Please sign in to comment.