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

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