Skip to content

Commit

Permalink
fix: set sample duration into status
Browse files Browse the repository at this point in the history
  • Loading branch information
nugaon committed Sep 26, 2023
1 parent f89ad31 commit 654aaa0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pkg/storageincentives/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,17 @@ func (a *Agent) handleSample(ctx context.Context, round uint64) (bool, error) {
return false, nil
}

t := time.Now()
sample, err := a.makeSample(ctx, storageRadius)
if err != nil {
return false, err
}
dur := time.Since(t)
a.metrics.SampleDuration.Set(dur.Seconds())

a.logger.Info("produced sample", "hash", sample.ReserveSampleHash, "radius", sample.StorageRadius, "round", round)

a.state.SetSampleData(round, sample)
a.state.SetSampleData(round, sample, dur)

return true, nil
}
Expand All @@ -452,13 +455,10 @@ func (a *Agent) makeSample(ctx context.Context, storageRadius uint8) (SampleData
return SampleData{}, err
}

t := time.Now()
rSample, err := a.store.ReserveSample(ctx, salt, storageRadius, uint64(timeLimiter), a.minBatchBalance())
if err != nil {
return SampleData{}, err
}
dur := time.Since(t)
a.metrics.SampleDuration.Set(dur.Seconds())

sampleHash, err := sampleHash(rSample.Items)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/storageincentives/redistributionstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,14 @@ func (r *RedistributionState) SampleData(round uint64) (SampleData, bool) {
return *rd.SampleData, true
}

func (r *RedistributionState) SetSampleData(round uint64, sd SampleData) {
func (r *RedistributionState) SetSampleData(round uint64, sd SampleData, dur time.Duration) {
r.mtx.Lock()
defer r.mtx.Unlock()

rd := r.status.RoundData[round]
rd.SampleData = &sd
r.status.RoundData[round] = rd
r.status.SampleDuration = dur

r.save()
}
Expand Down

0 comments on commit 654aaa0

Please sign in to comment.