diff --git a/cmd/neofs-node/reputation.go b/cmd/neofs-node/reputation.go index 76675157..25094e50 100644 --- a/cmd/neofs-node/reputation.go +++ b/cmd/neofs-node/reputation.go @@ -415,7 +415,8 @@ func (s *reputationServer) SendLocalTrust(ctx context.Context, req *v2reputation } for _, trust := range body.GetTrusts() { - if err = s.processTrust(body.GetEpoch(), apiToLocalTrust(trust), passedRoute, w); err != nil { + err = s.processTrust(body.GetEpoch(), apiToLocalTrust(trust, passedRoute[0].PublicKey()), passedRoute, w) + if err != nil { return nil, errors.Wrap(err, "could not write one of trusts") } } @@ -434,18 +435,20 @@ func (s *reputationServer) SendIntermediateResult(_ context.Context, req *v2repu return resp, nil } -func apiToLocalTrust(t *v2reputation.Trust) reputation.Trust { +// apiToLocalTrust converts v2 Trust to local reputation.Trust, adding trustingPeer. +func apiToLocalTrust(t *v2reputation.Trust, trustingPeer []byte) reputation.Trust { localTrust := reputation.Trust{} localTrust.SetValue(reputation.TrustValueFromFloat64(t.GetValue())) localTrust.SetPeer(reputation.PeerIDFromBytes(t.GetPeer().GetValue())) + localTrust.SetTrustingPeer(reputation.PeerIDFromBytes(trustingPeer)) return localTrust } func (s *reputationServer) processTrust(epoch uint64, t reputation.Trust, passedRoute []reputationroute.ServerInfo, w trustcontroller.Writer) error { - err := reputationroute.CheckRoute(s.routeBuilder, epoch, reputation.PeerIDFromBytes(passedRoute[0].PublicKey()), passedRoute) + err := reputationroute.CheckRoute(s.routeBuilder, epoch, t, passedRoute) if err != nil { return errors.Wrap(err, "wrong route of reputation trust value") } diff --git a/pkg/services/reputation/local/route/calls.go b/pkg/services/reputation/local/route/calls.go index 7ebcf866..f3d276eb 100644 --- a/pkg/services/reputation/local/route/calls.go +++ b/pkg/services/reputation/local/route/calls.go @@ -69,9 +69,7 @@ func (w *trustWriter) Write(t reputation.Trust) error { w.routeMtx.Lock() defer w.routeMtx.Unlock() - localPeerID := reputation.PeerIDFromBytes(w.router.localSrvInfo.PublicKey()) - - route, err := w.router.routeBuilder.NextStage(w.ctx.Epoch(), localPeerID, w.ctx.passedRoute) + route, err := w.router.routeBuilder.NextStage(w.ctx.Epoch(), t, w.ctx.passedRoute) if err != nil { return err } else if len(route) == 0 { diff --git a/pkg/services/reputation/local/route/deps.go b/pkg/services/reputation/local/route/deps.go index 701441df..e689b09f 100644 --- a/pkg/services/reputation/local/route/deps.go +++ b/pkg/services/reputation/local/route/deps.go @@ -22,13 +22,13 @@ type ServerInfo interface { // Builder groups methods to route values in the network. type Builder interface { // NextStage must return next group of route points - // for passed epoch and PeerID of the current route point. + // for passed epoch and trust values. // Implementation must take into account already passed route points. // // Empty passed list means being at the starting point of the route. // // Must return empty list and no error if the endpoint of the route is reached. - NextStage(epoch uint64, p reputation.PeerID, passed []ServerInfo) ([]ServerInfo, error) + NextStage(epoch uint64, t reputation.Trust, passed []ServerInfo) ([]ServerInfo, error) } // RemoteWriterProvider describes the component diff --git a/pkg/services/reputation/local/route/managers/calls.go b/pkg/services/reputation/local/route/managers/calls.go index 0dcd3abe..0e5e8e13 100644 --- a/pkg/services/reputation/local/route/managers/calls.go +++ b/pkg/services/reputation/local/route/managers/calls.go @@ -9,12 +9,12 @@ import ( // NextStage builds Manager list for node and returns it directly. // // If passed route has more than one point, then endpoint of the route is reached. -func (b *Builder) NextStage(epoch uint64, p reputation.PeerID, passed []reputationroute.ServerInfo) ([]reputationroute.ServerInfo, error) { +func (b *Builder) NextStage(epoch uint64, t reputation.Trust, passed []reputationroute.ServerInfo) ([]reputationroute.ServerInfo, error) { if len(passed) > 1 { return nil, nil } - route, err := b.managerBuilder.BuildManagers(epoch, p) + route, err := b.managerBuilder.BuildManagers(epoch, t.TrustingPeer()) if err != nil { return nil, errors.Wrapf(err, "could not build managers for epoch: %d", epoch) } diff --git a/pkg/services/reputation/local/route/util.go b/pkg/services/reputation/local/route/util.go index a700a506..e3de88c8 100644 --- a/pkg/services/reputation/local/route/util.go +++ b/pkg/services/reputation/local/route/util.go @@ -12,9 +12,9 @@ var errWrongRoute = errors.New("wrong route") // CheckRoute checks if the route is a route correctly constructed by the builder for value a. // // Returns nil if route is correct, otherwise an error clarifying the inconsistency. -func CheckRoute(builder Builder, epoch uint64, peer reputation.PeerID, route []ServerInfo) error { +func CheckRoute(builder Builder, epoch uint64, t reputation.Trust, route []ServerInfo) error { for i := 1; i < len(route); i++ { - servers, err := builder.NextStage(epoch, peer, route[:i]) + servers, err := builder.NextStage(epoch, t, route[:i]) if err != nil { return err } else if len(servers) == 0 {