[#338] ir: Always enable notary on sidechain
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
81718afb39
commit
0ab589dd52
5 changed files with 32 additions and 51 deletions
|
@ -22,7 +22,7 @@ type contracts struct {
|
|||
alphabet AlphabetContracts // in morph
|
||||
}
|
||||
|
||||
func parseContracts(cfg *viper.Viper, morph nnsResolver, withoutMainNet, withoutMainNotary, withoutSideNotary bool) (*contracts, error) {
|
||||
func parseContracts(cfg *viper.Viper, morph nnsResolver, withoutMainNet, withoutMainNotary bool) (*contracts, error) {
|
||||
var (
|
||||
result = new(contracts)
|
||||
err error
|
||||
|
@ -42,12 +42,10 @@ func parseContracts(cfg *viper.Viper, morph nnsResolver, withoutMainNet, without
|
|||
}
|
||||
}
|
||||
|
||||
if !withoutSideNotary {
|
||||
result.proxy, err = parseContract(cfg, morph, "contracts.proxy", client.NNSProxyContractName)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't get proxy script hash: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
targets := [...]struct {
|
||||
cfgName string
|
||||
|
|
|
@ -35,7 +35,7 @@ contracts:
|
|||
|
||||
t.Run("all enabled", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
c, err := parseContracts(v, nil, false, false, false)
|
||||
c, err := parseContracts(v, nil, false, false)
|
||||
require.NoError(t, err, "failed to parse contracts")
|
||||
|
||||
frostfsExp, _ := util.Uint160DecodeStringLE("ee3dee6d05dc79c24a5b8f6985e10d68b7cacc62")
|
||||
|
@ -70,7 +70,7 @@ contracts:
|
|||
|
||||
t.Run("all disabled", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
c, err := parseContracts(v, nil, true, true, true)
|
||||
c, err := parseContracts(v, nil, true, true)
|
||||
require.NoError(t, err, "failed to parse contracts")
|
||||
|
||||
require.Equal(t, util.Uint160{}, c.frostfs, "invalid frostfs")
|
||||
|
@ -89,7 +89,8 @@ contracts:
|
|||
netmapIDExp, _ := util.Uint160DecodeStringLE("83c600c81d47a1b1b7cf58eb49ae7ee7240dc742")
|
||||
require.Equal(t, netmapIDExp, c.netmap, "invalid netmap")
|
||||
|
||||
require.Equal(t, util.Uint160{}, c.proxy, "invalid proxy")
|
||||
proxyExp, _ := util.Uint160DecodeStringLE("abc8794bb40a21f2db5f21ae62741eb46c8cad1c")
|
||||
require.Equal(t, proxyExp, c.proxy, "invalid proxy")
|
||||
|
||||
require.Equal(t, 2, len(c.alphabet), "invalid alphabet contracts length")
|
||||
|
||||
|
@ -100,9 +101,9 @@ contracts:
|
|||
require.Equal(t, bukyExp, c.alphabet[buky], "invalid buky")
|
||||
})
|
||||
|
||||
t.Run("main notary & side notary disabled", func(t *testing.T) {
|
||||
t.Run("main notary disabled", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
c, err := parseContracts(v, nil, false, true, true)
|
||||
c, err := parseContracts(v, nil, false, true)
|
||||
require.NoError(t, err, "failed to parse contracts")
|
||||
|
||||
frostfsExp, _ := util.Uint160DecodeStringLE("ee3dee6d05dc79c24a5b8f6985e10d68b7cacc62")
|
||||
|
@ -122,7 +123,8 @@ contracts:
|
|||
netmapIDExp, _ := util.Uint160DecodeStringLE("83c600c81d47a1b1b7cf58eb49ae7ee7240dc742")
|
||||
require.Equal(t, netmapIDExp, c.netmap, "invalid netmap")
|
||||
|
||||
require.Equal(t, util.Uint160{}, c.proxy, "invalid proxy")
|
||||
proxyExp, _ := util.Uint160DecodeStringLE("abc8794bb40a21f2db5f21ae62741eb46c8cad1c")
|
||||
require.Equal(t, proxyExp, c.proxy, "invalid proxy")
|
||||
|
||||
require.Equal(t, 2, len(c.alphabet), "invalid alphabet contracts length")
|
||||
|
||||
|
@ -159,7 +161,7 @@ contracts:
|
|||
err := v.ReadConfig(file)
|
||||
require.NoError(t, err, "read config file failed")
|
||||
|
||||
_, err = parseContracts(v, nil, false, false, false)
|
||||
_, err = parseContracts(v, nil, false, false)
|
||||
require.Error(t, err, "unexpected success")
|
||||
})
|
||||
|
||||
|
@ -196,7 +198,7 @@ contracts:
|
|||
},
|
||||
}
|
||||
|
||||
_, err = parseContracts(v, morph, false, false, false)
|
||||
_, err = parseContracts(v, morph, false, false)
|
||||
require.ErrorContains(t, err, "could not read all contracts: required 3, read 2", "unexpected success")
|
||||
})
|
||||
}
|
||||
|
|
|
@ -116,7 +116,6 @@ func (s *Server) initMainnet(ctx context.Context, cfg *viper.Viper, morphChain *
|
|||
}
|
||||
|
||||
func (s *Server) enableNotarySupport() error {
|
||||
if !s.sideNotaryConfig.disabled {
|
||||
// enable notary support in the side client
|
||||
err := s.morphClient.EnableNotarySupport(
|
||||
client.WithProxyContract(s.contracts.proxy),
|
||||
|
@ -126,7 +125,6 @@ func (s *Server) enableNotarySupport() error {
|
|||
}
|
||||
|
||||
s.morphListener.EnableNotarySupport(s.contracts.proxy, s.morphClient.Committee, s.morphClient)
|
||||
}
|
||||
|
||||
if !s.mainNotaryConfig.disabled {
|
||||
// enable notary support in the main client
|
||||
|
@ -143,13 +141,12 @@ func (s *Server) enableNotarySupport() error {
|
|||
}
|
||||
|
||||
func (s *Server) initNotaryConfig() {
|
||||
s.mainNotaryConfig, s.sideNotaryConfig = notaryConfigs(
|
||||
s.morphClient.ProbeNotary(),
|
||||
s.mainNotaryConfig = notaryConfigs(
|
||||
!s.withoutMainNet && s.mainnetClient.ProbeNotary(), // if mainnet disabled then notary flag must be disabled too
|
||||
)
|
||||
|
||||
s.log.Info(logs.InnerringNotarySupport,
|
||||
zap.Bool("sidechain_enabled", !s.sideNotaryConfig.disabled),
|
||||
zap.Bool("sidechain_enabled", true),
|
||||
zap.Bool("mainchain_enabled", !s.mainNotaryConfig.disabled),
|
||||
)
|
||||
}
|
||||
|
@ -500,7 +497,6 @@ func (s *Server) initContracts(cfg *viper.Viper) error {
|
|||
s.morphClient,
|
||||
s.withoutMainNet,
|
||||
s.mainNotaryConfig.disabled,
|
||||
s.sideNotaryConfig.disabled,
|
||||
)
|
||||
|
||||
return err
|
||||
|
|
|
@ -63,7 +63,6 @@ type (
|
|||
// notary configuration
|
||||
feeConfig *config.FeeConfig
|
||||
mainNotaryConfig *notaryConfig
|
||||
sideNotaryConfig *notaryConfig
|
||||
|
||||
// internal variables
|
||||
key *keys.PrivateKey
|
||||
|
@ -267,14 +266,11 @@ func (s *Server) initMainNotary(ctx context.Context) error {
|
|||
}
|
||||
|
||||
func (s *Server) initSideNotary(ctx context.Context) error {
|
||||
if !s.sideNotaryConfig.disabled {
|
||||
return s.initNotary(ctx,
|
||||
s.depositSideNotary,
|
||||
s.awaitSideNotaryDeposit,
|
||||
"waiting to accept side notary deposit",
|
||||
)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) tickInitialExpoch() {
|
||||
|
|
|
@ -57,12 +57,9 @@ func (s *Server) notaryHandler(_ event.Event) {
|
|||
}
|
||||
}
|
||||
|
||||
if !s.sideNotaryConfig.disabled {
|
||||
_, err := s.depositSideNotary()
|
||||
if err != nil {
|
||||
if _, err := s.depositSideNotary(); err != nil {
|
||||
s.log.Error(logs.InnerringCantMakeNotaryDepositInSideChain, zap.Error(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) awaitMainNotaryDeposit(ctx context.Context, tx util.Uint256) error {
|
||||
|
@ -115,16 +112,8 @@ func awaitNotaryDepositInClient(ctx context.Context, cli *client.Client, txHash
|
|||
return errDepositTimeout
|
||||
}
|
||||
|
||||
func notaryConfigs(withSideNotary, withMainNotary bool) (main, side *notaryConfig) {
|
||||
func notaryConfigs(withMainNotary bool) (main *notaryConfig) {
|
||||
main = new(notaryConfig)
|
||||
side = new(notaryConfig)
|
||||
|
||||
if !withSideNotary {
|
||||
main.disabled = true
|
||||
side.disabled = true
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
main.disabled = !withMainNotary
|
||||
|
||||
|
|
Loading…
Reference in a new issue