[#493] node: Connect to main chain
Establish client connection with main chain node on storage node startup. Client is configured simlarly to morph client. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
1fa49bca9c
commit
6339f1a468
2 changed files with 47 additions and 21 deletions
|
@ -80,6 +80,9 @@ const (
|
|||
cfgMorphNotifyRPCAddress = "morph.notification_endpoint"
|
||||
cfgMorphNotifyDialTimeout = "morph.dial_timeout"
|
||||
|
||||
cfgMainChainRPCAddress = "mainchain.rpc_endpoint"
|
||||
cfgMainChainDialTimeout = "mainchain.dial_timeout"
|
||||
|
||||
// config keys for cfgAccounting
|
||||
cfgAccountingContract = "accounting.scripthash"
|
||||
cfgAccountingFee = "accounting.fee"
|
||||
|
@ -219,6 +222,8 @@ type cfg struct {
|
|||
closers []func()
|
||||
|
||||
cfgReputation cfgReputation
|
||||
|
||||
mainChainClient *client.Client
|
||||
}
|
||||
|
||||
type cfgGRPC struct {
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
|
@ -27,7 +28,8 @@ var (
|
|||
func initMorphComponents(c *cfg) {
|
||||
var err error
|
||||
|
||||
addresses := c.viper.GetStringSlice(cfgMorphRPCAddress)
|
||||
fn := func(endpointCfg, dialTOCfg string, handler func(*client.Client)) {
|
||||
addresses := c.viper.GetStringSlice(endpointCfg)
|
||||
if len(addresses) == 0 {
|
||||
fatalOnErr(errNoRPCEndpoints)
|
||||
}
|
||||
|
@ -37,12 +39,20 @@ func initMorphComponents(c *cfg) {
|
|||
addresses[i], addresses[j] = addresses[j], addresses[i]
|
||||
})
|
||||
|
||||
var dialTimeout time.Duration
|
||||
|
||||
if dialTOCfg != "" {
|
||||
dialTimeout = c.viper.GetDuration(dialTOCfg)
|
||||
}
|
||||
|
||||
for i := range addresses {
|
||||
c.cfgMorph.client, err = client.New(c.key, addresses[i])
|
||||
cli, err := client.New(c.key, addresses[i], client.WithDialTimeout(dialTimeout))
|
||||
if err == nil {
|
||||
c.log.Info("neo RPC connection established",
|
||||
zap.String("endpoint", addresses[i]))
|
||||
|
||||
handler(cli)
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
|
@ -52,6 +62,17 @@ func initMorphComponents(c *cfg) {
|
|||
}
|
||||
|
||||
fatalOnErr(err)
|
||||
}
|
||||
|
||||
// replace to a separate initialing block during refactoring
|
||||
// since current function initializes sidechain components
|
||||
fn(cfgMainChainRPCAddress, cfgMainChainDialTimeout, func(cli *client.Client) {
|
||||
c.mainChainClient = cli
|
||||
})
|
||||
|
||||
fn(cfgMorphRPCAddress, "", func(cli *client.Client) {
|
||||
c.cfgMorph.client = cli
|
||||
})
|
||||
|
||||
staticClient, err := client.NewStatic(
|
||||
c.cfgMorph.client,
|
||||
|
|
Loading…
Reference in a new issue