From e21d054fe23caa0b62ca0527ae894ac956c457e2 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Sat, 29 Jan 2022 15:42:48 +0300 Subject: [PATCH] [#749] morph/client: set group signer scope Signed-off-by: Evgenii Stratonikov --- .../internal/modules/morph/subnet.go | 3 +++ cmd/neofs-node/morph.go | 3 +++ pkg/innerring/innerring.go | 3 +++ pkg/morph/client/nns.go | 24 +++++++++++++++++-- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/cmd/neofs-adm/internal/modules/morph/subnet.go b/cmd/neofs-adm/internal/modules/morph/subnet.go index 9430f39b7..4b036744a 100644 --- a/cmd/neofs-adm/internal/modules/morph/subnet.go +++ b/cmd/neofs-adm/internal/modules/morph/subnet.go @@ -140,6 +140,9 @@ func initSubnetClientCheckNotary(c *morphsubnet.Client, key *keys.PrivateKey, ch return err } + // Error means group was not set in NNS, continue with Global scope in this case. + _ = cMorph.SetGroupSignerScope() + // read contract address contractAddr, err := cMorph.NNSContractAddress(client.NNSSubnetworkContractName) if err != nil { diff --git a/cmd/neofs-node/morph.go b/cmd/neofs-node/morph.go index 810e15017..cc1c83a4d 100644 --- a/cmd/neofs-node/morph.go +++ b/cmd/neofs-node/morph.go @@ -51,6 +51,9 @@ func initMorphComponents(c *cfg) { client.WithMaxConnectionPerHost(morphconfig.MaxConnPerHost(c.appCfg)), ) if err == nil { + if err := cli.SetGroupSignerScope(); err != nil { + c.log.Info("failed to set group signer scope, continue with Global", zap.Error(err)) + } handler(cli) return diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 85fd92691..24792458f 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -364,6 +364,9 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error if err != nil { return nil, err } + if err := server.morphClient.SetGroupSignerScope(); err != nil { + morphChain.log.Info("failed to set group signer scope, continue with Global", zap.Error(err)) + } server.withoutMainNet = cfg.GetBool("without_mainnet") diff --git a/pkg/morph/client/nns.go b/pkg/morph/client/nns.go index 9a6017ce2..562f77002 100644 --- a/pkg/morph/client/nns.go +++ b/pkg/morph/client/nns.go @@ -6,6 +6,7 @@ import ( "strconv" nns "github.com/nspcc-dev/neo-go/examples/nft-nd-nns" + "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/rpc/client" "github.com/nspcc-dev/neo-go/pkg/smartcontract" @@ -175,8 +176,27 @@ func exists(c *client.Client, nnsHash util.Uint160, domain string) (bool, error) return !available, nil } -// ContractGroupKey returns public key designating NeoFS contract group. -func (c *Client) ContractGroupKey() (*keys.PublicKey, error) { +// SetGroupSignerScope makes the default signer scope include all NeoFS contracts. +// Should be called for side-chain client only. +func (c *Client) SetGroupSignerScope() error { + if c.multiClient != nil { + return c.multiClient.iterateClients(func(c *Client) error { + return wrapNeoFSError(c.SetGroupSignerScope()) + }) + } + + pub, err := c.contractGroupKey() + if err != nil { + return err + } + + c.signer.Scopes = transaction.CustomGroups + c.signer.AllowedGroups = []*keys.PublicKey{pub} + return nil +} + +// contractGroupKey returns public key designating NeoFS contract group. +func (c *Client) contractGroupKey() (*keys.PublicKey, error) { if c.groupKey != nil { return c.groupKey, nil }