From 53b4d6d6d001392c833b846ac800f12f37a6741b Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Sun, 21 Feb 2021 12:26:18 +0300 Subject: [PATCH] [#396] ir: Support working with sidechain only NeoFS contract can be deployed in sidechain instead of main chain. Add `without_mainnet` config flag that can switch IR node to work with sidechain only. By default this flag is unset. Signed-off-by: Leonard Lyubich --- cmd/neofs-ir/defaults.go | 2 ++ pkg/innerring/innerring.go | 30 +++++++++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/cmd/neofs-ir/defaults.go b/cmd/neofs-ir/defaults.go index 1a48dbbe5..504871141 100644 --- a/cmd/neofs-ir/defaults.go +++ b/cmd/neofs-ir/defaults.go @@ -47,6 +47,8 @@ func defaultConfiguration(cfg *viper.Viper) { cfg.SetDefault("metrics.address", ":9090") cfg.SetDefault("metrics.shutdown_ttl", "30s") + cfg.SetDefault("without_mainnet", false) + cfg.SetDefault("morph.endpoint.client", "") cfg.SetDefault("morph.endpoint.notification", "") cfg.SetDefault("morph.dial_timeout", "10s") diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 9f44a3c3f..c4a4b94a7 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -238,19 +238,27 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error return nil, err } - mainnetChain := morphChain - mainnetChain.name = mainnetPrefix + if cfg.GetBool("without_mainnet") { + // This works as long as event Listener starts listening loop once, + // otherwise Server.Start will run two similar routines. + // This behavior most likely will not change. + server.mainnetListener = server.morphListener + server.mainnetClient = server.morphClient + } else { + mainnetChain := morphChain + mainnetChain.name = mainnetPrefix - // create mainnet listener - server.mainnetListener, err = createListener(ctx, mainnetChain) - if err != nil { - return nil, err - } + // create mainnet listener + server.mainnetListener, err = createListener(ctx, mainnetChain) + if err != nil { + return nil, err + } - // create mainnet client - server.mainnetClient, err = createClient(ctx, mainnetChain) - if err != nil { - return nil, err + // create mainnet client + server.mainnetClient, err = createClient(ctx, mainnetChain) + if err != nil { + return nil, err + } } server.pubKey = crypto.MarshalPublicKey(&server.key.PublicKey)