[#746] morph: Add error return of MagicNumber method

Since morph `Client` works in multi-client mode, there is an error case when
we can not get network magic when all endpoints are unavailable.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-08-26 11:17:31 +03:00 committed by Alex Vanin
parent ad7ad12a0c
commit 85bd2a1cdf
2 changed files with 12 additions and 14 deletions

View file

@ -261,14 +261,19 @@ type netInfo struct {
netState netmap.State netState netmap.State
magic interface { magic interface {
MagicNumber() uint64 MagicNumber() (uint64, error)
} }
} }
func (n *netInfo) Dump() (*netmapV2.NetworkInfo, error) { func (n *netInfo) Dump() (*netmapV2.NetworkInfo, error) {
magic, err := n.magic.MagicNumber()
if err != nil {
return nil, err
}
ni := new(netmapV2.NetworkInfo) ni := new(netmapV2.NetworkInfo)
ni.SetCurrentEpoch(n.netState.CurrentEpoch()) ni.SetCurrentEpoch(n.netState.CurrentEpoch())
ni.SetMagicNumber(n.magic.MagicNumber()) ni.SetMagicNumber(magic)
return ni, nil return ni, nil
} }

View file

@ -390,22 +390,15 @@ func toStackParameter(value interface{}) (sc.Parameter, error) {
// to which the underlying RPC node client is connected. // to which the underlying RPC node client is connected.
// //
// Returns 0 in case of connection problems. // Returns 0 in case of connection problems.
func (c *Client) MagicNumber() (res uint64) { func (c *Client) MagicNumber() (res uint64, err error) {
if c.multiClient != nil { if c.multiClient != nil {
err := c.multiClient.iterateClients(func(c *Client) error { return res, c.multiClient.iterateClients(func(c *Client) error {
res = c.MagicNumber() res, err = c.MagicNumber()
return nil return err
}) })
if err != nil {
c.logger.Debug("iterate over client failure",
zap.String("error", err.Error()),
)
} }
return return uint64(c.client.GetNetwork()), nil
}
return uint64(c.client.GetNetwork())
} }
// BlockCount returns block count of the network // BlockCount returns block count of the network