The ApplyUpdates() method on the reputation.DB interface acts like the similar Update() method, but can allow for applying the changes from multiple audit events, instead of only one. This will be necessary for the reputation write cache, which will batch up changes to each node's reputation in order to flush them periodically. Refs: https://github.com/storj/storj/issues/4601 Change-Id: I44cc47767ea2d9423166bb8fed080c8a11182041
35 lines
879 B
Go
35 lines
879 B
Go
// Copyright (C) 2020 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package satellitedb
|
|
|
|
import (
|
|
"context"
|
|
|
|
"storj.io/common/pb"
|
|
"storj.io/storj/satellite/reputation"
|
|
)
|
|
|
|
func mergeAuditHistory(ctx context.Context, oldHistory []byte, addHistory []*pb.AuditWindow, config reputation.AuditHistoryConfig) (res *reputation.UpdateAuditHistoryResponse, err error) {
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
history := &pb.AuditHistory{}
|
|
err = pb.Unmarshal(oldHistory, history)
|
|
if err != nil {
|
|
return nil, Error.Wrap(err)
|
|
}
|
|
|
|
trackingPeriodFull := reputation.MergeAuditHistories(history, addHistory, config)
|
|
|
|
historyBytes, err := pb.Marshal(history)
|
|
if err != nil {
|
|
return nil, Error.Wrap(err)
|
|
}
|
|
|
|
return &reputation.UpdateAuditHistoryResponse{
|
|
NewScore: history.Score,
|
|
TrackingPeriodFull: trackingPeriodFull,
|
|
History: historyBytes,
|
|
}, nil
|
|
}
|