From b5622ebead8ffa921db91e994bfdb1cedca7f19c Mon Sep 17 00:00:00 2001 From: Ekaterina Lebedeva Date: Tue, 6 Feb 2024 02:58:00 +0300 Subject: [PATCH] [#905] Make notary support enabled by default In morph client notary support is enabled by default. Added method to disable notary support. Removed usage of deprecated method enabling notary support from code where it's possible. Signed-off-by: Ekaterina Lebedeva --- cmd/frostfs-node/morph.go | 9 ------ pkg/innerring/initialization.go | 9 +----- pkg/morph/client/constructor.go | 4 +++ pkg/morph/client/notary.go | 51 +++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 17 deletions(-) diff --git a/cmd/frostfs-node/morph.go b/cmd/frostfs-node/morph.go index 698fb3b83..0c99f7e87 100644 --- a/cmd/frostfs-node/morph.go +++ b/cmd/frostfs-node/morph.go @@ -72,15 +72,6 @@ func initMorphComponents(ctx context.Context, c *cfg) { lookupScriptHashesInNNS(c) // smart contract auto negotiation - if c.cfgMorph.notaryEnabled { - err = c.cfgMorph.client.EnableNotarySupport( - client.WithProxyContract( - c.cfgMorph.proxyScriptHash, - ), - ) - fatalOnErr(err) - } - c.log.Info(logs.FrostFSNodeNotarySupport, zap.Bool("sidechain_enabled", c.cfgMorph.notaryEnabled), ) diff --git a/pkg/innerring/initialization.go b/pkg/innerring/initialization.go index f4d9b4169..8b1294914 100644 --- a/pkg/innerring/initialization.go +++ b/pkg/innerring/initialization.go @@ -118,18 +118,11 @@ func (s *Server) initMainnet(ctx context.Context, cfg *viper.Viper, morphChain * } func (s *Server) enableNotarySupport() error { - // enable notary support in the side client - err := s.morphClient.EnableNotarySupport( - client.WithProxyContract(s.contracts.proxy), - ) - if err != nil { - return fmt.Errorf("could not enable side chain notary support: %w", err) - } - s.morphListener.EnableNotarySupport(s.contracts.proxy, s.morphClient.Committee, s.morphClient) if !s.mainNotaryConfig.disabled { // enable notary support in the main client + //lint:ignore SA1019 we need notary support enabled in main chain err := s.mainnetClient.EnableNotarySupport( client.WithProxyContract(s.contracts.processing), client.WithAlphabetSource(s.morphClient.Committee), diff --git a/pkg/morph/client/constructor.go b/pkg/morph/client/constructor.go index 50a9572d4..f09af0f87 100644 --- a/pkg/morph/client/constructor.go +++ b/pkg/morph/client/constructor.go @@ -157,6 +157,10 @@ func New(ctx context.Context, key *keys.PrivateKey, opts ...Option) (*Client, er } cli.setActor(act) + if err = cli.enableNotarySupport(); err != nil { + return nil, err + } + go cli.closeWaiter(ctx) return cli, nil diff --git a/pkg/morph/client/notary.go b/pkg/morph/client/notary.go index 5b817a805..87592841e 100644 --- a/pkg/morph/client/notary.go +++ b/pkg/morph/client/notary.go @@ -78,6 +78,43 @@ func defaultNotaryConfig(c *Client) *notaryCfg { // EnableNotarySupport creates notary structure in client that provides // ability for client to get alphabet keys from committee or provided source // and use proxy contract script hash to create tx for notary contract. +func (c *Client) enableNotarySupport(opts ...NotaryOption) error { + c.switchLock.RLock() + defer c.switchLock.RUnlock() + + if c.inactive { + return ErrConnectionLost + } + + cfg := defaultNotaryConfig(c) + + for _, opt := range opts { + opt(cfg) + } + + if cfg.proxy.Equals(util.Uint160{}) { + var err error + + cfg.proxy, err = c.NNSContractAddress(NNSProxyContractName) + if err != nil { + return fmt.Errorf("get proxy contract addess from NNS: %w", err) + } + } + + notaryCfg := ¬aryInfo{ + proxy: cfg.proxy, + txValidTime: cfg.txValidTime, + roundTime: cfg.roundTime, + alphabetSource: cfg.alphabetSource, + notary: notary.Hash, + } + + c.notary = notaryCfg + + return nil +} + +// Deprecated: Notary support is enabled by default during client construction. func (c *Client) EnableNotarySupport(opts ...NotaryOption) error { c.switchLock.RLock() defer c.switchLock.RUnlock() @@ -114,6 +151,20 @@ func (c *Client) EnableNotarySupport(opts ...NotaryOption) error { return nil } +// DisableNotarySupport removes notary structure in client. +func (c *Client) DisableNotarySupport() error { + c.switchLock.Lock() + defer c.switchLock.Unlock() + + if c.inactive { + return ErrConnectionLost + } + + c.notary = nil + + return nil +} + // IsNotaryEnabled returns true if EnableNotarySupport has been successfully // called before. func (c *Client) IsNotaryEnabled() bool {