[#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

@ -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