[#1570] Upgrade NeoFS SDK Go with changed reputation API

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-07-04 16:24:51 +03:00 committed by LeL
parent 9a6da336db
commit 9a11a75b77
28 changed files with 146 additions and 158 deletions

View file

@ -9,6 +9,7 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust"
eigencalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator"
eigentrustctrl "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/controller"
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
)
// InitialTrustSource is an implementation of the
@ -20,7 +21,7 @@ type InitialTrustSource struct {
var ErrEmptyNetMap = errors.New("empty NepMap")
// InitialTrust returns `initialTrust` as an initial trust value.
func (i InitialTrustSource) InitialTrust(reputation.PeerID) (reputation.TrustValue, error) {
func (i InitialTrustSource) InitialTrust(apireputation.PeerID) (reputation.TrustValue, error) {
nm, err := i.NetMap.GetNetMap(1)
if err != nil {
return reputation.TrustZero, fmt.Errorf("failed to get NetMap: %w", err)

View file

@ -1,8 +1,6 @@
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"
@ -34,8 +32,8 @@ 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())),
zap.Stringer("trusting_peer", t.TrustingPeer()),
zap.Stringer("trusted_peer", t.Peer()),
)
trust := eigentrust.IterationTrust{Trust: t}

View file

@ -2,13 +2,13 @@ package intermediate
import (
"crypto/ecdsa"
"encoding/hex"
"fmt"
repClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust"
eigentrustcalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
neofsecdsa "github.com/nspcc-dev/neofs-sdk-go/crypto/ecdsa"
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
"go.uber.org/zap"
)
@ -75,27 +75,23 @@ func (fw FinalWriter) WriteIntermediateTrust(t eigentrust.IterationTrust) error
args := repClient.PutPrm{}
var trustedPublicKey [33]byte
copy(trustedPublicKey[:], t.Peer().Bytes())
apiTrustedPeerID := t.Peer()
apiTrustedPeerID := apireputation.NewPeerID()
apiTrustedPeerID.SetPublicKey(trustedPublicKey)
apiTrust := apireputation.NewTrust()
var apiTrust apireputation.Trust
apiTrust.SetValue(t.Value().Float64())
apiTrust.SetPeer(apiTrustedPeerID)
apiTrust.SetPeer(t.Peer())
var managerPublicKey [33]byte
copy(managerPublicKey[:], fw.pubKey)
apiMangerPeerID := apireputation.NewPeerID()
apiMangerPeerID.SetPublicKey(managerPublicKey)
var apiMangerPeerID apireputation.PeerID
apiMangerPeerID.SetPublicKey(managerPublicKey[:])
gTrust := apireputation.NewGlobalTrust()
var gTrust apireputation.GlobalTrust
gTrust.SetTrust(apiTrust)
gTrust.SetManager(apiMangerPeerID)
err := gTrust.Sign(fw.privatKey)
err := gTrust.Sign(neofsecdsa.Signer(*fw.privatKey))
if err != nil {
fw.l.Debug(
"failed to sign global trust",
@ -105,8 +101,8 @@ func (fw FinalWriter) WriteIntermediateTrust(t eigentrust.IterationTrust) error
}
args.SetEpoch(t.Epoch())
args.SetValue(*gTrust)
args.SetPeerID(*apiTrustedPeerID)
args.SetValue(gTrust)
args.SetPeerID(apiTrustedPeerID)
err = fw.client.Put(
args,
@ -123,7 +119,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())),
zap.Stringer("peer", t.Peer()),
)
return nil

View file

@ -1,8 +1,6 @@
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"
@ -29,8 +27,8 @@ 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())),
zap.Stringer("trusting_peer", t.TrustingPeer()),
zap.Stringer("trusted_peer", t.Peer()),
)
w.storage.Put(w.ctx.Epoch(), t)

View file

@ -2,7 +2,6 @@ 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"
@ -95,22 +94,16 @@ func (rtp *RemoteTrustWriter) Write(t reputation.Trust) error {
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())),
zap.Stringer("trusting_peer", t.TrustingPeer()),
zap.Stringer("trusted_peer", t.Peer()),
)
apiTrustingPeer := reputationapi.NewPeerID()
apiTrustingPeer.SetPublicKey(t.TrustingPeer())
apiTrustedPeer := reputationapi.NewPeerID()
apiTrustedPeer.SetPublicKey(t.Peer())
apiTrust := reputationapi.NewTrust()
var apiTrust reputationapi.Trust
apiTrust.SetValue(t.Value().Float64())
apiTrust.SetPeer(apiTrustedPeer)
apiTrust.SetPeer(t.Peer())
apiPeerToPeerTrust := reputationapi.NewPeerToPeerTrust()
apiPeerToPeerTrust.SetTrustingPeer(apiTrustingPeer)
var apiPeerToPeerTrust reputationapi.PeerToPeerTrust
apiPeerToPeerTrust.SetTrustingPeer(t.TrustingPeer())
apiPeerToPeerTrust.SetTrust(apiTrust)
var p internalclient.AnnounceIntermediatePrm
@ -119,7 +112,7 @@ func (rtp *RemoteTrustWriter) Write(t reputation.Trust) error {
p.SetClient(rtp.client)
p.SetEpoch(epoch)
p.SetIteration(i)
p.SetTrust(*apiPeerToPeerTrust)
p.SetTrust(apiPeerToPeerTrust)
_, err := internalclient.AnnounceIntermediate(p)

View file

@ -1,13 +1,12 @@
package intermediate
import (
"encoding/hex"
"fmt"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
eigentrustcalc "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/services/reputation/eigentrust/storage/daughters"
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
)
// DaughterTrustIteratorProvider is an implementation of the
@ -20,15 +19,12 @@ type DaughterTrustIteratorProvider struct {
// InitDaughterIterator returns an iterator over the received
// local trusts for ctx.Epoch() epoch from daughter p.
func (ip *DaughterTrustIteratorProvider) InitDaughterIterator(ctx eigentrustcalc.Context,
p reputation.PeerID) (eigentrustcalc.TrustIterator, error) {
p apireputation.PeerID) (eigentrustcalc.TrustIterator, error) {
epoch := ctx.Epoch()
daughterIterator, ok := ip.DaughterStorage.DaughterTrusts(epoch, p)
if !ok {
return nil, fmt.Errorf("no data in %d epoch for daughter: %s",
epoch,
hex.EncodeToString(p.Bytes()),
)
return nil, fmt.Errorf("no data in %d epoch for daughter: %s", epoch, p)
}
return daughterIterator, nil