2020-07-30 12:19:06 +01:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package satellitedb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"storj.io/common/pb"
|
2021-07-07 20:20:23 +01:00
|
|
|
"storj.io/storj/satellite/reputation"
|
2020-07-30 12:19:06 +01:00
|
|
|
)
|
|
|
|
|
2022-05-07 18:43:32 +01:00
|
|
|
func mergeAuditHistory(ctx context.Context, oldHistory []byte, addHistory []*pb.AuditWindow, config reputation.AuditHistoryConfig) (res *reputation.UpdateAuditHistoryResponse, err error) {
|
2020-12-21 17:26:07 +00:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
2022-05-04 22:12:01 +01:00
|
|
|
history := &pb.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 {
|
2022-05-07 18:43:32 +01:00
|
|
|
return nil, Error.Wrap(err)
|
2020-07-30 12:19:06 +01:00
|
|
|
}
|
|
|
|
|
2022-05-07 18:43:32 +01:00
|
|
|
trackingPeriodFull := reputation.MergeAuditHistories(history, addHistory, config)
|
2020-07-30 12:19:06 +01:00
|
|
|
|
2022-05-07 18:43:32 +01:00
|
|
|
historyBytes, err := pb.Marshal(history)
|
2020-07-30 12:19:06 +01:00
|
|
|
if err != nil {
|
2022-05-07 18:43:32 +01:00
|
|
|
return nil, Error.Wrap(err)
|
2020-07-30 12:19:06 +01:00
|
|
|
}
|
|
|
|
|
2022-05-07 18:43:32 +01:00
|
|
|
return &reputation.UpdateAuditHistoryResponse{
|
|
|
|
NewScore: history.Score,
|
|
|
|
TrackingPeriodFull: trackingPeriodFull,
|
|
|
|
History: historyBytes,
|
|
|
|
}, nil
|
2020-12-21 17:26:07 +00:00
|
|
|
}
|