[#496] cmd/node: Use new config for morph and mainchain configuration

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-06-01 17:58:40 +03:00 committed by Alex Vanin
parent 4ef968aa06
commit 0f4e8d2362
2 changed files with 9 additions and 41 deletions

View file

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

View file

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