[#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 <ekaterina.lebedeva@yadro.com>
This commit is contained in:
Ekaterina Lebedeva 2024-02-06 02:58:00 +03:00
parent d7838790c6
commit b5622ebead
4 changed files with 56 additions and 17 deletions

View file

@ -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),
)

View file

@ -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),

View file

@ -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

View file

@ -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 := &notaryInfo{
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 {