[#1210] reputation: Improve debug logs

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-03-01 22:01:45 +03:00 committed by Alex Vanin
parent 0adb29c035
commit 13af4e6046
17 changed files with 188 additions and 60 deletions

View file

@ -431,9 +431,18 @@ type reputationClient struct {
}
func (c *reputationClient) submitResult(err error) {
currEpoch := c.cons.netState.CurrentEpoch()
sat := err == nil
c.cons.log.Debug(
"writing local reputation values",
zap.Uint64("epoch", currEpoch),
zap.Bool("satisfactory", sat),
)
prm := c.prm
prm.SetSatisfactory(err == nil)
prm.SetEpoch(c.cons.netState.CurrentEpoch())
prm.SetSatisfactory(sat)
prm.SetEpoch(currEpoch)
c.cons.trustStorage.Update(prm)
}

View file

@ -59,8 +59,11 @@ func initReputationService(c *cfg) {
Storage: consumerStorage,
}
localTrustLogger := c.log.With(zap.String("trust_type", "local"))
intermediateTrustLogger := c.log.With(zap.String("trust_type", "intermediate"))
localTrustStorage := &localreputation.TrustStorage{
Log: c.log,
Log: localTrustLogger,
Storage: c.cfgReputation.localTrustStorage,
NmSrc: nmSrc,
LocalKey: localKey,
@ -76,12 +79,14 @@ func initReputationService(c *cfg) {
localRouteBuilder := localroutes.New(
localroutes.Prm{
ManagerBuilder: managerBuilder,
Log: localTrustLogger,
},
)
intermediateRouteBuilder := intermediateroutes.New(
intermediateroutes.Prm{
ManagerBuilder: managerBuilder,
Log: intermediateTrustLogger,
},
)
@ -93,8 +98,10 @@ func initReputationService(c *cfg) {
WriterProvider: localreputation.NewRemoteProvider(
localreputation.RemoteProviderPrm{
Key: &c.key.PrivateKey,
Log: localTrustLogger,
},
),
Log: localTrustLogger,
},
)
@ -106,8 +113,10 @@ func initReputationService(c *cfg) {
WriterProvider: intermediatereputation.NewRemoteProvider(
intermediatereputation.RemoteProviderPrm{
Key: &c.key.PrivateKey,
Log: intermediateTrustLogger,
},
),
Log: intermediateTrustLogger,
},
)
@ -117,7 +126,7 @@ func initReputationService(c *cfg) {
RemoteWriterProvider: remoteLocalTrustProvider,
Builder: localRouteBuilder,
},
)
reputationrouter.WithLogger(localTrustLogger))
intermediateTrustRouter := reputationrouter.New(
reputationrouter.Prm{
@ -125,6 +134,7 @@ func initReputationService(c *cfg) {
RemoteWriterProvider: remoteIntermediateTrustProvider,
Builder: intermediateRouteBuilder,
},
reputationrouter.WithLogger(intermediateTrustLogger),
)
eigenTrustCalculator := eigentrustcalc.New(
@ -159,6 +169,7 @@ func initReputationService(c *cfg) {
IterationsProvider: c.cfgNetmap.wrapper,
WorkerPool: c.cfgReputation.workerPool,
},
eigentrustctrl.WithLogger(c.log),
)
c.cfgReputation.localTrustCtrl = localtrustcontroller.New(
@ -166,11 +177,14 @@ func initReputationService(c *cfg) {
LocalTrustSource: localTrustStorage,
LocalTrustTarget: localTrustRouter,
},
localtrustcontroller.WithLogger(c.log),
)
addNewEpochAsyncNotificationHandler(
c,
func(ev event.Event) {
c.log.Debug("start reporting reputation on new epoch event")
var reportPrm localtrustcontroller.ReportPrm
// report collected values from previous epoch
@ -282,7 +296,7 @@ func (s *reputationServer) AnnounceIntermediateResult(ctx context.Context, req *
w, err := s.intermediateRouter.InitWriter(reputationrouter.NewRouteContext(eiCtx, passedRoute))
if err != nil {
return nil, fmt.Errorf("could not initialize intermediate trust writer: %w", err)
return nil, fmt.Errorf("could not initialize trust writer: %w", err)
}
v2Trust := body.GetTrust()
@ -291,7 +305,7 @@ func (s *reputationServer) AnnounceIntermediateResult(ctx context.Context, req *
err = w.Write(trust)
if err != nil {
return nil, fmt.Errorf("could not write intermediate trust: %w", err)
return nil, fmt.Errorf("could not write trust: %w", err)
}
resp := new(v2reputation.AnnounceIntermediateResultResponse)

View file

@ -8,6 +8,7 @@ import (
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
reputationrouter "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common/router"
trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
)
type clientCache interface {
@ -31,6 +32,7 @@ type remoteTrustProvider struct {
deadEndProvider reputationcommon.WriterProvider
clientCache clientCache
remoteProvider clientKeyRemoteProvider
log *logger.Logger
}
// RemoteProviderPrm groups the required parameters of the remoteTrustProvider's constructor.
@ -43,6 +45,7 @@ type RemoteProviderPrm struct {
DeadEndProvider reputationcommon.WriterProvider
ClientCache clientCache
WriterProvider clientKeyRemoteProvider
Log *logger.Logger
}
func NewRemoteTrustProvider(prm RemoteProviderPrm) reputationrouter.RemoteWriterProvider {
@ -55,6 +58,8 @@ func NewRemoteTrustProvider(prm RemoteProviderPrm) reputationrouter.RemoteWriter
PanicOnPrmValue("ClientCache", prm.ClientCache)
case prm.WriterProvider == nil:
PanicOnPrmValue("WriterProvider", prm.WriterProvider)
case prm.Log == nil:
PanicOnPrmValue("Logger", prm.Log)
}
return &remoteTrustProvider{
@ -62,16 +67,21 @@ func NewRemoteTrustProvider(prm RemoteProviderPrm) reputationrouter.RemoteWriter
deadEndProvider: prm.DeadEndProvider,
clientCache: prm.ClientCache,
remoteProvider: prm.WriterProvider,
log: prm.Log,
}
}
func (rtp *remoteTrustProvider) InitRemote(srv reputationcommon.ServerInfo) (reputationcommon.WriterProvider, error) {
rtp.log.Debug("initializing remote writer provider")
if srv == nil {
rtp.log.Debug("route has reached dead-end provider")
return rtp.deadEndProvider, nil
}
if rtp.netmapKeys.IsLocalKey(srv.PublicKey()) {
// if local => return no-op writer
rtp.log.Debug("initializing no-op writer provider")
return trustcontroller.SimpleWriterProvider(new(NopReputationWriter)), nil
}

View file

@ -1,12 +1,15 @@
package intermediate
import (
"encoding/hex"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust"
eigencalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator"
consumerstorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/storage/consumers"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
"go.uber.org/zap"
)
var ErrIncorrectContextPanicMsg = "could not write intermediate trust: passed context incorrect"
@ -28,6 +31,13 @@ type ConsumerTrustWriter struct {
}
func (w *ConsumerTrustWriter) Write(t reputation.Trust) error {
w.log.Debug("writing received consumer's trusts",
zap.Uint64("epoch", w.eiCtx.Epoch()),
zap.Uint32("iteration", w.eiCtx.I()),
zap.String("trusting_peer", hex.EncodeToString(t.TrustingPeer().Bytes())),
zap.String("trusted_peer", hex.EncodeToString(t.Peer().Bytes())),
)
trust := eigentrust.IterationTrust{Trust: t}
trust.SetEpoch(w.eiCtx.Epoch())

View file

@ -2,6 +2,7 @@ package intermediate
import (
"crypto/ecdsa"
"encoding/hex"
"fmt"
repClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation"
@ -70,6 +71,8 @@ type FinalWriter struct {
}
func (fw FinalWriter) WriteIntermediateTrust(t eigentrust.IterationTrust) error {
fw.l.Debug("start writing global trusts to contract")
args := repClient.PutPrm{}
var trustedPublicKey [33]byte
@ -120,6 +123,7 @@ func (fw FinalWriter) WriteIntermediateTrust(t eigentrust.IterationTrust) error
"sent global trust to contract",
zap.Uint64("epoch", t.Epoch()),
zap.Float64("value", t.Value().Float64()),
zap.String("peer", hex.EncodeToString(t.Peer().Bytes())),
)
return nil

View file

@ -1,10 +1,13 @@
package intermediate
import (
"encoding/hex"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/storage/daughters"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
"go.uber.org/zap"
)
// DaughterStorageWriterProvider is implementation of reputation.WriterProvider
@ -24,6 +27,12 @@ type DaughterTrustWriter struct {
}
func (w *DaughterTrustWriter) Write(t reputation.Trust) error {
w.log.Debug("writing received daughter's trusts",
zap.Uint64("epoch", w.ctx.Epoch()),
zap.String("trusting_peer", hex.EncodeToString(t.TrustingPeer().Bytes())),
zap.String("trusted_peer", hex.EncodeToString(t.Peer().Bytes())),
)
w.storage.Put(w.ctx.Epoch(), t)
return nil
}

View file

@ -2,6 +2,7 @@ package intermediate
import (
"crypto/ecdsa"
"encoding/hex"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/common"
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/internal/client"
@ -9,7 +10,9 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
eigentrustcalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
reputationapi "github.com/nspcc-dev/neofs-sdk-go/reputation"
"go.uber.org/zap"
)
// RemoteProviderPrm groups the required parameters of the RemoteProvider's constructor.
@ -19,6 +22,7 @@ import (
// failure (error or panic depending on the implementation).
type RemoteProviderPrm struct {
Key *ecdsa.PrivateKey
Log *logger.Logger
}
// NewRemoteProvider creates a new instance of the RemoteProvider.
@ -31,28 +35,34 @@ func NewRemoteProvider(prm RemoteProviderPrm) *RemoteProvider {
switch {
case prm.Key == nil:
common.PanicOnPrmValue("NetMapSource", prm.Key)
case prm.Log == nil:
common.PanicOnPrmValue("Logger", prm.Log)
}
return &RemoteProvider{
key: prm.Key,
log: prm.Log,
}
}
// RemoteProvider is an implementation of the clientKeyRemoteProvider interface.
type RemoteProvider struct {
key *ecdsa.PrivateKey
log *logger.Logger
}
func (rp RemoteProvider) WithClient(c coreclient.Client) reputationcommon.WriterProvider {
return &TrustWriterProvider{
client: c,
key: rp.key,
log: rp.log,
}
}
type TrustWriterProvider struct {
client coreclient.Client
key *ecdsa.PrivateKey
log *logger.Logger
}
func (twp *TrustWriterProvider) InitWriter(ctx reputationcommon.Context) (reputationcommon.Writer, error) {
@ -66,6 +76,7 @@ func (twp *TrustWriterProvider) InitWriter(ctx reputationcommon.Context) (reputa
eiCtx: eiContext,
client: twp.client,
key: twp.key,
log: twp.log,
}, nil
}
@ -73,10 +84,21 @@ type RemoteTrustWriter struct {
eiCtx eigentrustcalc.Context
client coreclient.Client
key *ecdsa.PrivateKey
log *logger.Logger
}
// Write sends trust value to remote node via ReputationService.AnnounceIntermediateResult RPC.
func (rtp *RemoteTrustWriter) Write(t reputation.Trust) error {
epoch := rtp.eiCtx.Epoch()
i := rtp.eiCtx.I()
rtp.log.Debug("announcing trust",
zap.Uint64("epoch", epoch),
zap.Uint32("iteration", i),
zap.String("trusting_peer", hex.EncodeToString(t.TrustingPeer().Bytes())),
zap.String("trusted_peer", hex.EncodeToString(t.Peer().Bytes())),
)
apiTrustingPeer := reputationapi.NewPeerID()
apiTrustingPeer.SetPublicKey(t.TrustingPeer())
@ -95,8 +117,8 @@ func (rtp *RemoteTrustWriter) Write(t reputation.Trust) error {
p.SetContext(rtp.eiCtx)
p.SetClient(rtp.client)
p.SetEpoch(rtp.eiCtx.Epoch())
p.SetIteration(rtp.eiCtx.I())
p.SetEpoch(epoch)
p.SetIteration(i)
p.SetTrust(*apiPeerToPeerTrust)
_, err := internalclient.AnnounceIntermediate(p)

View file

@ -17,34 +17,18 @@ type DaughterTrustIteratorProvider struct {
ConsumerStorage *consumerstorage.Storage
}
type ErrNoData struct {
hasDaughter bool
daughter reputation.PeerID
epoch uint64
}
func (e *ErrNoData) Error() string {
if e.hasDaughter {
return fmt.Sprintf("no data in %d epoch for peer: %s", e.epoch, hex.EncodeToString(e.daughter.Bytes()))
}
return fmt.Sprintf("no daughter data in %d epoch", e.epoch)
}
// InitDaughterIterator returns iterator over received
// local trusts for ctx.Epoch() epoch from daughter p.
//
// Returns ErrNoData if there is no trust data for
// specified epoch and daughter's PeerId.
func (ip *DaughterTrustIteratorProvider) InitDaughterIterator(ctx eigentrustcalc.Context,
p reputation.PeerID) (eigentrustcalc.TrustIterator, error) {
daughterIterator, ok := ip.DaughterStorage.DaughterTrusts(ctx.Epoch(), p)
epoch := ctx.Epoch()
daughterIterator, ok := ip.DaughterStorage.DaughterTrusts(epoch, p)
if !ok {
return nil, &ErrNoData{
daughter: p,
hasDaughter: true,
epoch: ctx.Epoch(),
}
return nil, fmt.Errorf("no data in %d epoch for daughter: %s",
epoch,
hex.EncodeToString(p.Bytes()),
)
}
return daughterIterator, nil
@ -53,14 +37,13 @@ func (ip *DaughterTrustIteratorProvider) InitDaughterIterator(ctx eigentrustcalc
// InitAllDaughtersIterator returns iterator over all
// daughters of the current node(manager) and all local
// trusts received from them for ctx.Epoch() epoch.
//
// Returns ErrNoData if there is no trust data for
// specified epoch.
func (ip *DaughterTrustIteratorProvider) InitAllDaughtersIterator(
ctx eigentrustcalc.Context) (eigentrustcalc.PeerTrustsIterator, error) {
iter, ok := ip.DaughterStorage.AllDaughterTrusts(ctx.Epoch())
epoch := ctx.Epoch()
iter, ok := ip.DaughterStorage.AllDaughterTrusts(epoch)
if !ok {
return nil, &ErrNoData{epoch: ctx.Epoch()}
return nil, fmt.Errorf("no data in %d epoch for daughters", epoch)
}
return iter, nil
@ -69,14 +52,16 @@ func (ip *DaughterTrustIteratorProvider) InitAllDaughtersIterator(
// InitConsumersIterator returns iterator over all daughters
// of the current node(manager) and all their consumers' local
// trusts for ctx.Epoch() epoch and ctx.I() iteration.
//
// Returns ErrNoData if there is no trust data for
// specified epoch and iteration.
func (ip *DaughterTrustIteratorProvider) InitConsumersIterator(
ctx eigentrustcalc.Context) (eigentrustcalc.PeerTrustsIterator, error) {
consumerIterator, ok := ip.ConsumerStorage.Consumers(ctx.Epoch(), ctx.I())
epoch, iter := ctx.Epoch(), ctx.I()
consumerIterator, ok := ip.ConsumerStorage.Consumers(epoch, iter)
if !ok {
return nil, &ErrNoData{epoch: ctx.Epoch()}
return nil, fmt.Errorf("no data for %d iteration in %d epoch for consumers's trusts",
iter,
epoch,
)
}
return consumerIterator, nil

View file

@ -8,7 +8,9 @@ import (
coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
reputationapi "github.com/nspcc-dev/neofs-sdk-go/reputation"
"go.uber.org/zap"
)
// RemoteProviderPrm groups the required parameters of the RemoteProvider's constructor.
@ -18,6 +20,7 @@ import (
// failure (error or panic depending on the implementation).
type RemoteProviderPrm struct {
Key *ecdsa.PrivateKey
Log *logger.Logger
}
// NewRemoteProvider creates a new instance of the RemoteProvider.
@ -30,28 +33,34 @@ func NewRemoteProvider(prm RemoteProviderPrm) *RemoteProvider {
switch {
case prm.Key == nil:
common.PanicOnPrmValue("NetMapSource", prm.Key)
case prm.Log == nil:
common.PanicOnPrmValue("Logger", prm.Log)
}
return &RemoteProvider{
key: prm.Key,
log: prm.Log,
}
}
// RemoteProvider is an implementation of the clientKeyRemoteProvider interface.
type RemoteProvider struct {
key *ecdsa.PrivateKey
log *logger.Logger
}
func (rp RemoteProvider) WithClient(c coreclient.Client) reputationcommon.WriterProvider {
return &TrustWriterProvider{
client: c,
key: rp.key,
log: rp.log,
}
}
type TrustWriterProvider struct {
client coreclient.Client
key *ecdsa.PrivateKey
log *logger.Logger
}
func (twp *TrustWriterProvider) InitWriter(ctx reputationcommon.Context) (reputationcommon.Writer, error) {
@ -59,6 +68,7 @@ func (twp *TrustWriterProvider) InitWriter(ctx reputationcommon.Context) (reputa
ctx: ctx,
client: twp.client,
key: twp.key,
log: twp.log,
}, nil
}
@ -66,6 +76,7 @@ type RemoteTrustWriter struct {
ctx reputationcommon.Context
client coreclient.Client
key *ecdsa.PrivateKey
log *logger.Logger
buf []reputationapi.Trust
}
@ -85,11 +96,17 @@ func (rtp *RemoteTrustWriter) Write(t reputation.Trust) error {
}
func (rtp *RemoteTrustWriter) Close() error {
epoch := rtp.ctx.Epoch()
rtp.log.Debug("announcing trusts",
zap.Uint64("epoch", epoch),
)
var prm internalclient.AnnounceLocalPrm
prm.SetContext(rtp.ctx)
prm.SetClient(rtp.client)
prm.SetEpoch(rtp.ctx.Epoch())
prm.SetEpoch(epoch)
prm.SetTrusts(rtp.buf)
_, err := internalclient.AnnounceLocal(prm)

View file

@ -10,6 +10,7 @@ import (
trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller"
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
"go.uber.org/zap"
)
type TrustStorage struct {
@ -23,7 +24,13 @@ type TrustStorage struct {
}
func (s *TrustStorage) InitIterator(ctx reputationcommon.Context) (trustcontroller.Iterator, error) {
epochStorage, err := s.Storage.DataForEpoch(ctx.Epoch())
epoch := ctx.Epoch()
s.Log.Debug("initializing iterator over trusts",
zap.Uint64("epoch", epoch),
)
epochStorage, err := s.Storage.DataForEpoch(epoch)
if err != nil && !errors.Is(err, truststorage.ErrNoPositiveTrust) {
return nil, err
}

View file

@ -108,7 +108,7 @@ func (c *announceContext) announce() {
return
}
c.log.Debug("announcement successfully finished")
c.log.Debug("trust announcement successfully finished")
}
func (c *Controller) acquireAnnouncement(prm StartPrm) *announceContext {
@ -163,9 +163,9 @@ func (c *commonContext) freeAnnouncement() {
c.ctrl.announceMtx.Unlock()
if stopped {
c.log.Debug("announcement successfully interrupted")
c.log.Debug("trust announcement successfully interrupted")
} else {
c.log.Debug("announcement is not started or already interrupted")
c.log.Debug("trust announcement is not started or already interrupted")
}
}
@ -254,9 +254,9 @@ func (c *commonContext) freeReport() {
c.ctrl.reportMtx.Unlock()
if stopped {
c.log.Debug("announcement successfully interrupted")
c.log.Debug("trust announcement successfully interrupted")
} else {
c.log.Debug("announcement is not started or already interrupted")
c.log.Debug("trust announcement is not started or already interrupted")
}
}

View file

@ -2,6 +2,7 @@ package common
import (
"bytes"
"encoding/hex"
"fmt"
"github.com/nspcc-dev/hrw"
@ -58,6 +59,11 @@ func NewManagerBuilder(prm ManagersPrm, opts ...MngOption) ManagerBuilder {
// BuildManagers sorts nodes in NetMap with HRW algorithms and
// takes the next node after the current one as the only manager.
func (mb *managerBuilder) BuildManagers(epoch uint64, p reputation.PeerID) ([]ServerInfo, error) {
mb.log.Debug("start building managers",
zap.Uint64("epoch", epoch),
zap.String("peer", hex.EncodeToString(p.Bytes())),
)
nm, err := mb.nmSrc.GetNetMapByEpoch(epoch)
if err != nil {
return nil, err

View file

@ -43,6 +43,11 @@ func (c *Calculator) Calculate(prm CalculatePrm) {
iter := ctx.I()
log := c.opts.log.With(
zap.Uint64("epoch", ctx.Epoch()),
zap.Uint32("iteration", iter),
)
if iter == 0 {
c.sendInitialValues(ctx)
return
@ -54,7 +59,7 @@ func (c *Calculator) Calculate(prm CalculatePrm) {
consumersIter, err := c.prm.DaughterTrustSource.InitConsumersIterator(ctx)
if err != nil {
c.opts.log.Debug("consumers trust iterator's init failure",
log.Debug("consumers trust iterator's init failure",
zap.String("error", err.Error()),
)
@ -74,7 +79,7 @@ func (c *Calculator) Calculate(prm CalculatePrm) {
})
})
if err != nil {
c.opts.log.Debug("worker pool submit failure",
log.Debug("worker pool submit failure",
zap.String("error", err.Error()),
)
}
@ -83,7 +88,7 @@ func (c *Calculator) Calculate(prm CalculatePrm) {
return nil
})
if err != nil {
c.opts.log.Debug("iterate daughters failed",
log.Debug("iterate daughter's consumers failed",
zap.String("error", err.Error()),
)
}
@ -156,7 +161,7 @@ func (c *Calculator) iterateDaughter(p iterDaughterPrm) {
if p.lastIter {
finalWriter, err := c.prm.FinalResultTarget.InitIntermediateWriter(p.ctx)
if err != nil {
c.opts.log.Debug("init intermediate writer failure",
c.opts.log.Debug("init writer failure",
zap.String("error", err.Error()),
)
@ -176,7 +181,7 @@ func (c *Calculator) iterateDaughter(p iterDaughterPrm) {
} else {
intermediateWriter, err := c.prm.IntermediateValueTarget.InitWriter(p.ctx)
if err != nil {
c.opts.log.Debug("init intermediate writer failure",
c.opts.log.Debug("init writer failure",
zap.String("error", err.Error()),
)
@ -197,7 +202,7 @@ func (c *Calculator) iterateDaughter(p iterDaughterPrm) {
err := intermediateWriter.Write(trust)
if err != nil {
c.opts.log.Debug("write intermediate value failure",
c.opts.log.Debug("write value failure",
zap.String("error", err.Error()),
)
}
@ -213,7 +218,7 @@ func (c *Calculator) iterateDaughter(p iterDaughterPrm) {
err = intermediateWriter.Close()
if err != nil {
c.opts.log.Error(
"could not close intermediate writer",
"could not close writer",
zap.String("error", err.Error()),
)
}
@ -232,7 +237,7 @@ func (c *Calculator) sendInitialValues(ctx Context) {
intermediateWriter, err := c.prm.IntermediateValueTarget.InitWriter(ctx)
if err != nil {
c.opts.log.Debug("init intermediate writer failure",
c.opts.log.Debug("init writer failure",
zap.String("error", err.Error()),
)
@ -259,7 +264,7 @@ func (c *Calculator) sendInitialValues(ctx Context) {
err = intermediateWriter.Write(trust)
if err != nil {
c.opts.log.Debug("write intermediate value failure",
c.opts.log.Debug("write value failure",
zap.String("error", err.Error()),
)
@ -277,7 +282,7 @@ func (c *Calculator) sendInitialValues(ctx Context) {
err = intermediateWriter.Close()
if err != nil {
c.opts.log.Debug("could not close intermediate writer",
c.opts.log.Debug("could not close writer",
zap.String("error", err.Error()),
)
}

View file

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
)
// Prm groups the required parameters of the Builder's constructor.
@ -16,6 +17,8 @@ type Prm struct {
//
// Must not be nil.
ManagerBuilder common.ManagerBuilder
Log *logger.Logger
}
// Builder represents component that routes node to its managers.
@ -26,6 +29,7 @@ type Prm struct {
// the Builder is immediately ready to work through API.
type Builder struct {
managerBuilder common.ManagerBuilder
log *logger.Logger
}
const invalidPrmValFmt = "invalid parameter %s (%T):%v"
@ -44,9 +48,12 @@ func New(prm Prm) *Builder {
switch {
case prm.ManagerBuilder == nil:
panicOnPrmValue("ManagerBuilder", prm.ManagerBuilder)
case prm.Log == nil:
panicOnPrmValue("Logger", prm.Log)
}
return &Builder{
managerBuilder: prm.ManagerBuilder,
log: prm.Log,
}
}

View file

@ -5,13 +5,21 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
"go.uber.org/zap"
)
// NextStage builds Manager list for trusted 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, t reputation.Trust, passed []common.ServerInfo) ([]common.ServerInfo, error) {
if len(passed) > 1 {
passedLen := len(passed)
b.log.Debug("building next stage for trust route",
zap.Uint64("epoch", epoch),
zap.Int("passed_length", passedLen),
)
if passedLen > 1 {
return nil, nil
}

View file

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
)
// Prm groups the required parameters of the Builder's constructor.
@ -16,6 +17,8 @@ type Prm struct {
//
// Must not be nil.
ManagerBuilder common.ManagerBuilder
Log *logger.Logger
}
// Builder represents component that routes node to its managers.
@ -26,6 +29,7 @@ type Prm struct {
// the Builder is immediately ready to work through API.
type Builder struct {
managerBuilder common.ManagerBuilder
log *logger.Logger
}
const invalidPrmValFmt = "invalid parameter %s (%T):%v"
@ -44,9 +48,12 @@ func New(prm Prm) *Builder {
switch {
case prm.ManagerBuilder == nil:
panicOnPrmValue("ManagerBuilder", prm.ManagerBuilder)
case prm.Log == nil:
panicOnPrmValue("Logger", prm.Log)
}
return &Builder{
managerBuilder: prm.ManagerBuilder,
log: prm.Log,
}
}

View file

@ -5,13 +5,21 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
"go.uber.org/zap"
)
// NextStage builds Manager list for trusting 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, t reputation.Trust, passed []common.ServerInfo) ([]common.ServerInfo, error) {
if len(passed) > 1 {
passedLen := len(passed)
b.log.Debug("building next stage for local trust route",
zap.Uint64("epoch", epoch),
zap.Int("passed_length", passedLen),
)
if passedLen > 1 {
return nil, nil
}