From 73ba35b379302b4a79a23bf146cf121cdcb64f69 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 22 Jul 2021 12:45:25 +0300 Subject: [PATCH] [#705] pkg/innerring: Fix disable notary mode Get innerring list and committee in innerring indexer from interfaces, not from structs. Passing IR fetcher to indexer constructor depends on having Notary contract in sidechain(use NeoFS role or netmap contract). Signed-off-by: Pavel Karpy --- pkg/innerring/indexer.go | 29 +++++++++++++++++++---------- pkg/innerring/innerring.go | 21 +++++++++++++++------ 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/pkg/innerring/indexer.go b/pkg/innerring/indexer.go index ae644d0b1..ac5fb93ef 100644 --- a/pkg/innerring/indexer.go +++ b/pkg/innerring/indexer.go @@ -7,16 +7,24 @@ import ( "time" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" - "github.com/nspcc-dev/neofs-node/pkg/morph/client" ) type ( + irFetcher interface { + InnerRingKeys() (keys.PublicKeys, error) + } + + committeeFetcher interface { + Committee() (keys.PublicKeys, error) + } + innerRingIndexer struct { sync.RWMutex - cli *client.Client - key *keys.PublicKey - timeout time.Duration + irFetcher irFetcher + commFetcher committeeFetcher + key *keys.PublicKey + timeout time.Duration ind indexes @@ -29,11 +37,12 @@ type ( } ) -func newInnerRingIndexer(cli *client.Client, key *keys.PublicKey, to time.Duration) *innerRingIndexer { +func newInnerRingIndexer(comf committeeFetcher, irf irFetcher, key *keys.PublicKey, to time.Duration) *innerRingIndexer { return &innerRingIndexer{ - cli: cli, - key: key, - timeout: to, + irFetcher: irf, + commFetcher: comf, + key: key, + timeout: to, } } @@ -54,7 +63,7 @@ func (s *innerRingIndexer) update() (ind indexes, err error) { return s.ind, nil } - innerRing, err := s.cli.NeoFSAlphabetList() + innerRing, err := s.irFetcher.InnerRingKeys() if err != nil { return indexes{}, err } @@ -62,7 +71,7 @@ func (s *innerRingIndexer) update() (ind indexes, err error) { s.ind.innerRingIndex = keyPosition(s.key, innerRing) s.ind.innerRingSize = int32(len(innerRing)) - alphabet, err := s.cli.Committee() + alphabet, err := s.commFetcher.Committee() if err != nil { return indexes{}, err } diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 5be3fdcbe..43cea11d6 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -375,12 +375,6 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error server.pubKey = server.key.PublicKey().Bytes() - server.statusIndex = newInnerRingIndexer( - server.morphClient, - server.key.PublicKey(), - cfg.GetDuration("indexer.cache_timeout"), - ) - auditPool, err := ants.NewPool(cfg.GetInt("audit.task.exec_pool_size")) if err != nil { return nil, err @@ -426,6 +420,21 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error return nil, err } + var irf irFetcher + + if server.morphClient.ProbeNotary() { + irf = NewIRFetcherWithNotary(server.morphClient) + } else { + irf = NewIRFetcherWithoutNotary(server.netmapClient) + } + + server.statusIndex = newInnerRingIndexer( + server.morphClient, + irf, + server.key.PublicKey(), + cfg.GetDuration("indexer.cache_timeout"), + ) + // create global runtime config reader globalConfig := config.NewGlobalConfigReader(cfg, server.netmapClient)