[#613] pkg/innerring: Add sanity check of GlobalTrust
Add sanity checks of GlobalTrust value: check if "got manager" is real manager for peer with building managers for peer. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
6b176e8769
commit
ed9a5e44b6
3 changed files with 44 additions and 5 deletions
|
@ -36,6 +36,7 @@ import (
|
||||||
audittask "github.com/nspcc-dev/neofs-node/pkg/services/audit/taskmanager"
|
audittask "github.com/nspcc-dev/neofs-node/pkg/services/audit/taskmanager"
|
||||||
control "github.com/nspcc-dev/neofs-node/pkg/services/control/ir"
|
control "github.com/nspcc-dev/neofs-node/pkg/services/control/ir"
|
||||||
controlsrv "github.com/nspcc-dev/neofs-node/pkg/services/control/ir/server"
|
controlsrv "github.com/nspcc-dev/neofs-node/pkg/services/control/ir/server"
|
||||||
|
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
|
||||||
util2 "github.com/nspcc-dev/neofs-node/pkg/util"
|
util2 "github.com/nspcc-dev/neofs-node/pkg/util"
|
||||||
utilConfig "github.com/nspcc-dev/neofs-node/pkg/util/config"
|
utilConfig "github.com/nspcc-dev/neofs-node/pkg/util/config"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/precision"
|
"github.com/nspcc-dev/neofs-node/pkg/util/precision"
|
||||||
|
@ -626,8 +627,6 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: create reputation processor
|
|
||||||
|
|
||||||
// create mainnnet neofs processor
|
// create mainnnet neofs processor
|
||||||
neofsProcessor, err := neofs.New(&neofs.Params{
|
neofsProcessor, err := neofs.New(&neofs.Params{
|
||||||
Log: log,
|
Log: log,
|
||||||
|
@ -682,6 +681,11 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
EpochState: server,
|
EpochState: server,
|
||||||
AlphabetState: server,
|
AlphabetState: server,
|
||||||
ReputationWrapper: repClient,
|
ReputationWrapper: repClient,
|
||||||
|
ManagerBuilder: reputationcommon.NewManagerBuilder(
|
||||||
|
reputationcommon.ManagersPrm{
|
||||||
|
NetMapSource: nmClient,
|
||||||
|
},
|
||||||
|
),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -1,14 +1,20 @@
|
||||||
package reputation
|
package reputation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/reputation"
|
apireputation "github.com/nspcc-dev/neofs-api-go/pkg/reputation"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (rp *Processor) processPut(epoch uint64, id reputation.PeerID, value reputation.GlobalTrust) {
|
var errWrongManager = errors.New("got manager that is incorrect for peer")
|
||||||
|
|
||||||
|
func (rp *Processor) processPut(epoch uint64, id apireputation.PeerID, value apireputation.GlobalTrust) {
|
||||||
if !rp.alphabetState.IsAlphabet() {
|
if !rp.alphabetState.IsAlphabet() {
|
||||||
rp.log.Info("non alphabet mode, ignore reputation put notification")
|
rp.log.Info("non alphabet mode, ignore reputation put notification")
|
||||||
return
|
return
|
||||||
|
@ -34,7 +40,14 @@ func (rp *Processor) processPut(epoch uint64, id reputation.PeerID, value reputa
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: do sanity checks of value
|
// check if manager is correct
|
||||||
|
if err := rp.checkManagers(epoch, *value.Manager(), id); err != nil {
|
||||||
|
rp.log.Info("ignore reputation value",
|
||||||
|
zap.String("reason", "wrong manager"),
|
||||||
|
zap.String("error", err.Error()))
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
args := wrapper.PutArgs{}
|
args := wrapper.PutArgs{}
|
||||||
args.SetEpoch(epoch)
|
args.SetEpoch(epoch)
|
||||||
|
@ -48,3 +61,18 @@ func (rp *Processor) processPut(epoch uint64, id reputation.PeerID, value reputa
|
||||||
zap.String("error", err.Error()))
|
zap.String("error", err.Error()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rp *Processor) checkManagers(e uint64, mng apireputation.PeerID, peer apireputation.PeerID) error {
|
||||||
|
mm, err := rp.mngBuilder.BuildManagers(e, reputation.PeerIDFromBytes(peer.ToV2().GetPublicKey()))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not build managers: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, m := range mm {
|
||||||
|
if bytes.Equal(mng.ToV2().GetPublicKey(), m.PublicKey()) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return errWrongManager
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
reputationWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper"
|
reputationWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||||
reputationEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/reputation"
|
reputationEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/reputation"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
|
||||||
"github.com/panjf2000/ants/v2"
|
"github.com/panjf2000/ants/v2"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -34,6 +35,8 @@ type (
|
||||||
alphabetState AlphabetState
|
alphabetState AlphabetState
|
||||||
|
|
||||||
reputationWrp *reputationWrapper.ClientWrapper
|
reputationWrp *reputationWrapper.ClientWrapper
|
||||||
|
|
||||||
|
mngBuilder common.ManagerBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
// Params of the processor constructor.
|
// Params of the processor constructor.
|
||||||
|
@ -44,6 +47,7 @@ type (
|
||||||
EpochState EpochState
|
EpochState EpochState
|
||||||
AlphabetState AlphabetState
|
AlphabetState AlphabetState
|
||||||
ReputationWrapper *reputationWrapper.ClientWrapper
|
ReputationWrapper *reputationWrapper.ClientWrapper
|
||||||
|
ManagerBuilder common.ManagerBuilder
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -62,6 +66,8 @@ func New(p *Params) (*Processor, error) {
|
||||||
return nil, errors.New("ir/reputation: global state is not set")
|
return nil, errors.New("ir/reputation: global state is not set")
|
||||||
case p.ReputationWrapper == nil:
|
case p.ReputationWrapper == nil:
|
||||||
return nil, errors.New("ir/reputation: reputation contract wrapper is not set")
|
return nil, errors.New("ir/reputation: reputation contract wrapper is not set")
|
||||||
|
case p.ManagerBuilder == nil:
|
||||||
|
return nil, errors.New("ir/reputation: manager builder is not set")
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Log.Debug("reputation worker pool", zap.Int("size", p.PoolSize))
|
p.Log.Debug("reputation worker pool", zap.Int("size", p.PoolSize))
|
||||||
|
@ -78,6 +84,7 @@ func New(p *Params) (*Processor, error) {
|
||||||
epochState: p.EpochState,
|
epochState: p.EpochState,
|
||||||
alphabetState: p.AlphabetState,
|
alphabetState: p.AlphabetState,
|
||||||
reputationWrp: p.ReputationWrapper,
|
reputationWrp: p.ReputationWrapper,
|
||||||
|
mngBuilder: p.ManagerBuilder,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue