From 0f4e8d2362ae9a478414a8fdc6096c8b05d9aeb4 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 1 Jun 2021 17:58:40 +0300 Subject: [PATCH] [#496] cmd/node: Use new config for morph and mainchain configuration Signed-off-by: Alex Vanin --- cmd/neofs-node/config.go | 13 ------------- cmd/neofs-node/morph.go | 37 +++++++++---------------------------- 2 files changed, 9 insertions(+), 41 deletions(-) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index 2f56f15de..d56cf028b 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -58,15 +58,6 @@ const ( // config keys for API client cache cfgAPIClientDialTimeout = "apiclient.dial_timeout" - // config keys for cfgMorph - cfgMorphRPCAddress = "morph.rpc_endpoint" - - cfgMorphNotifyRPCAddress = "morph.notification_endpoint" - cfgMorphNotifyDialTimeout = "morph.dial_timeout" - - cfgMainChainRPCAddress = "mainchain.rpc_endpoint" - cfgMainChainDialTimeout = "mainchain.dial_timeout" - cfgPolicerHeadTimeout = "policer.head_timeout" cfgReplicatorPutTimeout = "replicator.put_timeout" @@ -378,10 +369,6 @@ func initViper(path string) *viper.Viper { } func defaultConfiguration(v *viper.Viper) { - v.SetDefault(cfgMorphRPCAddress, []string{}) - v.SetDefault(cfgMorphNotifyRPCAddress, []string{}) - v.SetDefault(cfgMorphNotifyDialTimeout, 5*time.Second) - v.SetDefault(cfgAPIClientDialTimeout, 5*time.Second) v.SetDefault(cfgPolicerHeadTimeout, 5*time.Second) diff --git a/cmd/neofs-node/morph.go b/cmd/neofs-node/morph.go index 7135dc5c6..07adc34b9 100644 --- a/cmd/neofs-node/morph.go +++ b/cmd/neofs-node/morph.go @@ -2,12 +2,13 @@ package main import ( "context" - "errors" "fmt" "time" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/util" + mainchainconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/mainchain" + morphconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/morph" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper" "github.com/nspcc-dev/neofs-node/pkg/morph/event" @@ -19,31 +20,15 @@ import ( const newEpochNotification = "NewEpoch" -var ( - errNoRPCEndpoints = errors.New("NEO RPC endpoints are not specified in config") - errNoWSEndpoints = errors.New("websocket NEO listener endpoints are not specified in config") -) - func initMorphComponents(c *cfg) { var err error - fn := func(endpointCfg, dialTOCfg string, handler func(*client.Client), required bool) { - addresses := c.viper.GetStringSlice(endpointCfg) - if required && len(addresses) == 0 { - fatalOnErr(errNoRPCEndpoints) - } - + fn := func(addresses []string, dialTimeout time.Duration, handler func(*client.Client)) { crand := rand.New() // math/rand with cryptographic source crand.Shuffle(len(addresses), func(i, j int) { addresses[i], addresses[j] = addresses[j], addresses[i] }) - var dialTimeout time.Duration - - if dialTOCfg != "" { - dialTimeout = c.viper.GetDuration(dialTOCfg) - } - for i := range addresses { cli, err := client.New(c.key, addresses[i], client.WithDialTimeout(dialTimeout)) if err == nil { @@ -65,13 +50,13 @@ func initMorphComponents(c *cfg) { // replace to a separate initialing block during refactoring // since current function initializes sidechain components - fn(cfgMainChainRPCAddress, cfgMainChainDialTimeout, func(cli *client.Client) { + fn(mainchainconfig.RPCEndpoint(c.appCfg), mainchainconfig.DialTimeout(c.appCfg), func(cli *client.Client) { c.mainChainClient = cli - }, false) + }) - fn(cfgMorphRPCAddress, "", func(cli *client.Client) { + fn(morphconfig.RPCEndpoint(c.appCfg), morphconfig.DialTimeout(c.appCfg), func(cli *client.Client) { c.cfgMorph.client = cli - }, true) + }) wrap, err := wrapper.NewFromMorph(c.cfgMorph.client, c.cfgNetmap.scriptHash, 0) fatalOnErr(err) @@ -86,12 +71,8 @@ func listenMorphNotifications(c *cfg) { subs subscriber.Subscriber ) - endpoints := c.viper.GetStringSlice(cfgMorphNotifyRPCAddress) - if len(endpoints) == 0 { - fatalOnErr(errNoWSEndpoints) - } - - timeout := c.viper.GetDuration(cfgMorphNotifyDialTimeout) + endpoints := morphconfig.NotificationEndpoint(c.appCfg) + timeout := morphconfig.DialTimeout(c.appCfg) crand := rand.New() // math/rand with cryptographic source crand.Shuffle(len(endpoints), func(i, j int) {