[#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) { 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 := c.prm
prm.SetSatisfactory(err == nil) prm.SetSatisfactory(sat)
prm.SetEpoch(c.cons.netState.CurrentEpoch()) prm.SetEpoch(currEpoch)
c.cons.trustStorage.Update(prm) c.cons.trustStorage.Update(prm)
} }

View file

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

View file

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

View file

@ -1,12 +1,15 @@
package intermediate package intermediate
import ( import (
"encoding/hex"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation" "github.com/nspcc-dev/neofs-node/pkg/services/reputation"
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust" "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust"
eigencalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator" 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" consumerstorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/storage/consumers"
"github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-node/pkg/util/logger"
"go.uber.org/zap"
) )
var ErrIncorrectContextPanicMsg = "could not write intermediate trust: passed context incorrect" 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 { 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 := eigentrust.IterationTrust{Trust: t}
trust.SetEpoch(w.eiCtx.Epoch()) trust.SetEpoch(w.eiCtx.Epoch())

View file

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

View file

@ -1,10 +1,13 @@
package intermediate package intermediate
import ( import (
"encoding/hex"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation" "github.com/nspcc-dev/neofs-node/pkg/services/reputation"
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" 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/services/reputation/eigentrust/storage/daughters"
"github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-node/pkg/util/logger"
"go.uber.org/zap"
) )
// DaughterStorageWriterProvider is implementation of reputation.WriterProvider // DaughterStorageWriterProvider is implementation of reputation.WriterProvider
@ -24,6 +27,12 @@ type DaughterTrustWriter struct {
} }
func (w *DaughterTrustWriter) Write(t reputation.Trust) error { 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) w.storage.Put(w.ctx.Epoch(), t)
return nil return nil
} }

View file

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

View file

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

View file

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

View file

@ -10,6 +10,7 @@ import (
trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller" trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller"
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage" truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
"github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-node/pkg/util/logger"
"go.uber.org/zap"
) )
type TrustStorage struct { type TrustStorage struct {
@ -23,7 +24,13 @@ type TrustStorage struct {
} }
func (s *TrustStorage) InitIterator(ctx reputationcommon.Context) (trustcontroller.Iterator, error) { 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) { if err != nil && !errors.Is(err, truststorage.ErrNoPositiveTrust) {
return nil, err return nil, err
} }

View file

@ -108,7 +108,7 @@ func (c *announceContext) announce() {
return return
} }
c.log.Debug("announcement successfully finished") c.log.Debug("trust announcement successfully finished")
} }
func (c *Controller) acquireAnnouncement(prm StartPrm) *announceContext { func (c *Controller) acquireAnnouncement(prm StartPrm) *announceContext {
@ -163,9 +163,9 @@ func (c *commonContext) freeAnnouncement() {
c.ctrl.announceMtx.Unlock() c.ctrl.announceMtx.Unlock()
if stopped { if stopped {
c.log.Debug("announcement successfully interrupted") c.log.Debug("trust announcement successfully interrupted")
} else { } 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() c.ctrl.reportMtx.Unlock()
if stopped { if stopped {
c.log.Debug("announcement successfully interrupted") c.log.Debug("trust announcement successfully interrupted")
} else { } 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 ( import (
"bytes" "bytes"
"encoding/hex"
"fmt" "fmt"
"github.com/nspcc-dev/hrw" "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 // BuildManagers sorts nodes in NetMap with HRW algorithms and
// takes the next node after the current one as the only manager. // takes the next node after the current one as the only manager.
func (mb *managerBuilder) BuildManagers(epoch uint64, p reputation.PeerID) ([]ServerInfo, error) { 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) nm, err := mb.nmSrc.GetNetMapByEpoch(epoch)
if err != nil { if err != nil {
return nil, err return nil, err

View file

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

View file

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

View file

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