2020-07-30 12:19:06 +01:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package satellitedb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"storj.io/common/pb"
|
2020-10-30 13:30:11 +00:00
|
|
|
"storj.io/storj/satellite/internalpb"
|
2021-07-07 20:20:23 +01:00
|
|
|
"storj.io/storj/satellite/reputation"
|
2020-07-30 12:19:06 +01:00
|
|
|
)
|
|
|
|
|
2022-05-04 22:15:29 +01:00
|
|
|
func updateAuditHistory(ctx context.Context, oldHistory []byte, config reputation.AuditHistoryConfig, online bool, auditTime time.Time) (res *reputation.UpdateAuditHistoryResponse, err error) {
|
2020-12-21 17:26:07 +00:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
2021-07-07 20:20:23 +01:00
|
|
|
res = &reputation.UpdateAuditHistoryResponse{
|
2020-12-21 17:26:07 +00:00
|
|
|
NewScore: 1,
|
|
|
|
TrackingPeriodFull: false,
|
|
|
|
}
|
|
|
|
|
2021-07-28 23:29:46 +01:00
|
|
|
// deserialize node audit history
|
2020-10-30 13:30:11 +00:00
|
|
|
history := &internalpb.AuditHistory{}
|
2021-07-28 23:29:46 +01:00
|
|
|
err = pb.Unmarshal(oldHistory, history)
|
2020-07-30 12:19:06 +01:00
|
|
|
if err != nil {
|
2020-12-21 17:26:07 +00:00
|
|
|
return res, err
|
2020-07-30 12:19:06 +01:00
|
|
|
}
|
|
|
|
|
2022-05-04 22:15:29 +01:00
|
|
|
err = reputation.AddAuditToHistory(history, online, auditTime, config)
|
2020-07-30 12:19:06 +01:00
|
|
|
if err != nil {
|
2020-12-21 17:26:07 +00:00
|
|
|
return res, err
|
2020-07-30 12:19:06 +01:00
|
|
|
}
|
|
|
|
|
2021-07-28 23:29:46 +01:00
|
|
|
res.History, err = pb.Marshal(history)
|
2020-07-30 12:19:06 +01:00
|
|
|
if err != nil {
|
2020-12-21 17:26:07 +00:00
|
|
|
return res, err
|
2020-07-30 12:19:06 +01:00
|
|
|
}
|
|
|
|
|
2020-12-21 17:26:07 +00:00
|
|
|
windowsPerTrackingPeriod := int(config.TrackingPeriod.Seconds() / config.WindowSize.Seconds())
|
|
|
|
res.TrackingPeriodFull = len(history.Windows)-1 >= windowsPerTrackingPeriod
|
|
|
|
res.NewScore = history.Score
|
2021-08-04 03:01:19 +01:00
|
|
|
return res, nil
|
2020-12-21 17:26:07 +00:00
|
|
|
}
|