From b18da34b551dafb2392dc5eb7178d63ad1f9047e Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 31 Mar 2021 18:41:47 +0300 Subject: [PATCH] [#452] innerring: Use reputation processor Signed-off-by: Alex Vanin --- cmd/neofs-ir/defaults.go | 2 ++ pkg/innerring/innerring.go | 43 +++++++++++++++++++++++++++----- pkg/innerring/invoke/enhanced.go | 17 +++++++++++++ 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/cmd/neofs-ir/defaults.go b/cmd/neofs-ir/defaults.go index 3b51fdb27..d04ba6a3c 100644 --- a/cmd/neofs-ir/defaults.go +++ b/cmd/neofs-ir/defaults.go @@ -67,6 +67,7 @@ func defaultConfiguration(cfg *viper.Viper) { cfg.SetDefault("contracts.container", "") cfg.SetDefault("contracts.audit", "") cfg.SetDefault("contracts.proxy", "") + cfg.SetDefault("contracts.reputation", "") // alphabet contracts cfg.SetDefault("contracts.alphabet.amount", 7) @@ -87,6 +88,7 @@ func defaultConfiguration(cfg *viper.Viper) { cfg.SetDefault("workers.neofs", "10") cfg.SetDefault("workers.container", "10") cfg.SetDefault("workers.alphabet", "10") + cfg.SetDefault("workers.reputation", "10") cfg.SetDefault("netmap_cleaner.enabled", false) cfg.SetDefault("netmap_cleaner.threshold", 3) diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index ef992d7a1..bc6b99091 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -19,6 +19,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/governance" "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/neofs" "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap" + "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/reputation" "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement" auditSettlement "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement/audit" "github.com/nspcc-dev/neofs-node/pkg/innerring/timers" @@ -86,12 +87,13 @@ type ( } contracts struct { - neofs util.Uint160 // in mainnet - netmap util.Uint160 // in morph - balance util.Uint160 // in morph - container util.Uint160 // in morph - audit util.Uint160 // in morph - proxy util.Uint160 // in morph + neofs util.Uint160 // in mainnet + netmap util.Uint160 // in morph + balance util.Uint160 // in morph + container util.Uint160 // in morph + audit util.Uint160 // in morph + proxy util.Uint160 // in morph + reputation util.Uint160 // in morph alphabet alphabetContracts // in morph } @@ -329,6 +331,11 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error return nil, err } + repClient, err := invoke.NewReputationClient(server.morphClient, server.contracts.reputation) + if err != nil { + return nil, err + } + // create global runtime config reader globalConfig := config.NewGlobalConfigReader(cfg, nmClient) @@ -551,6 +558,24 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error return nil, err } + // create reputation processor + reputationProcessor, err := reputation.New(&reputation.Params{ + Log: log, + PoolSize: cfg.GetInt("workers.reputation"), + ReputationContract: server.contracts.reputation, + EpochState: server, + AlphabetState: server, + ReputationWrapper: repClient, + }) + if err != nil { + return nil, err + } + + err = bindMorphProcessor(reputationProcessor, server) + if err != nil { + return nil, err + } + // todo: create vivid id component // initialize epoch timers @@ -642,6 +667,7 @@ func parseContracts(cfg *viper.Viper) (*contracts, error) { containerContractStr := cfg.GetString("contracts.container") auditContractStr := cfg.GetString("contracts.audit") proxyContractStr := cfg.GetString("contracts.proxy") + reputationContractStr := cfg.GetString("contracts.reputation") result.netmap, err = util.Uint160DecodeStringLE(netmapContractStr) if err != nil { @@ -673,6 +699,11 @@ func parseContracts(cfg *viper.Viper) (*contracts, error) { return nil, errors.Wrap(err, "ir: can't read proxy script-hash") } + result.reputation, err = util.Uint160DecodeStringLE(reputationContractStr) + if err != nil { + return nil, errors.Wrap(err, "ir: can't read reputation script-hash") + } + result.alphabet, err = parseAlphabetContracts(cfg) if err != nil { return nil, err diff --git a/pkg/innerring/invoke/enhanced.go b/pkg/innerring/invoke/enhanced.go index 1b2880bbb..6cc909834 100644 --- a/pkg/innerring/invoke/enhanced.go +++ b/pkg/innerring/invoke/enhanced.go @@ -13,6 +13,8 @@ import ( wrapContainer "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper" morphNetmap "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap" wrapNetmap "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper" + "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation" + reputationWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper" "github.com/pkg/errors" ) @@ -70,3 +72,18 @@ func NewBalanceClient(cli *client.Client, contract util.Uint160) (*balanceWrappe return balanceWrapper.New(enhancedBalanceClient) } + +// NewReputationClient creates wrapper to work with reputation contract. +func NewReputationClient(cli *client.Client, contract util.Uint160) (*reputationWrapper.ClientWrapper, error) { + staticClient, err := client.NewStatic(cli, contract, 0) + if err != nil { + return nil, errors.Wrap(err, "could not create static client of reputation contract") + } + + enhancedRepurationClient, err := reputation.New(staticClient) + if err != nil { + return nil, errors.Wrap(err, "could not create reputation contract client") + } + + return reputationWrapper.WrapClient(enhancedRepurationClient), nil +}