2ee9463e34
The two protobuf types are identical except that one is in our common/pb package, and the other is in internalpb. Since the type is public already, and there is no difference in the internal one, it seems better to use the public one for all satellite needs. There is also another type which is essentially identical, but which is not a protobuf type, also called "AuditHistory". It looks like we don't ever actually need to have a separate type from the protobuf one. This change makes us use "storj/common/pb".AuditHistory for all of our AuditHistory needs. Refs: https://github.com/storj/storj/issues/4601 Change-Id: If845fde21bb31c801db6d67ffc9a146d1617b991
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
// Copyright (C) 2020 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package satellitedb
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"storj.io/common/pb"
|
|
"storj.io/storj/satellite/reputation"
|
|
)
|
|
|
|
func updateAuditHistory(ctx context.Context, oldHistory []byte, config reputation.AuditHistoryConfig, online bool, auditTime time.Time) (res *reputation.UpdateAuditHistoryResponse, err error) {
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
res = &reputation.UpdateAuditHistoryResponse{
|
|
NewScore: 1,
|
|
TrackingPeriodFull: false,
|
|
}
|
|
|
|
// deserialize node audit history
|
|
history := &pb.AuditHistory{}
|
|
err = pb.Unmarshal(oldHistory, history)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
|
|
err = reputation.AddAuditToHistory(history, online, auditTime, config)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
|
|
res.History, err = pb.Marshal(history)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
|
|
windowsPerTrackingPeriod := int(config.TrackingPeriod.Seconds() / config.WindowSize.Seconds())
|
|
res.TrackingPeriodFull = len(history.Windows)-1 >= windowsPerTrackingPeriod
|
|
res.NewScore = history.Score
|
|
return res, nil
|
|
}
|