Skip to content

Commit

Permalink
ir: Check that just bootstrapped SN is available
Browse files Browse the repository at this point in the history
Closes nspcc-dev#2475.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
  • Loading branch information
carpawell committed Sep 1, 2023
1 parent 9871712 commit 8f93a19
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ minor release, the component will be purged, so be prepared (see `Updating` sect
- `neofs-cli object nodes` command to get SNs for an object (#2512)
- Fetching container estimations via iterators to prevent NeoVM stack overflow (#2173)
- `neofs-adm morph netmap-candidates` CLI command (#1889)
- SN network validation (is available by its announced addresses) on bootstrap by IR (#2475)

### Fixed
- `neo-go` RPC connection loss handling (#1337)
Expand Down
1 change: 1 addition & 0 deletions pkg/core/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Client interface {
AnnounceLocalTrust(ctx context.Context, epoch uint64, trusts []reputationSDK.Trust, prm client.PrmAnnounceLocalTrust) error
AnnounceIntermediateTrust(ctx context.Context, epoch uint64, trust reputationSDK.PeerToPeerTrust, prm client.PrmAnnounceIntermediateTrust) error
ExecRaw(f func(client *rawclient.Client) error) error
EndpointInfo(ctx context.Context, prm client.PrmEndpointInfo) (*client.ResEndpointInfo, error)
Close() error
}

Expand Down
1 change: 1 addition & 0 deletions pkg/innerring/innerring.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper, errChan chan<-
locodeValidator,
),
NodeStateSettings: netSettings,
ClientSource: clientCache,
})
if err != nil {
return nil, err
Expand Down
26 changes: 26 additions & 0 deletions pkg/innerring/processors/netmap/process_peers.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package netmap

import (
"context"
"encoding/hex"

clientcore "github.com/nspcc-dev/neofs-node/pkg/core/client"
netmapCore "github.com/nspcc-dev/neofs-node/pkg/core/netmap"
netmapclient "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
"github.com/nspcc-dev/neofs-sdk-go/client"
"github.com/nspcc-dev/neofs-sdk-go/netmap"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -47,6 +51,28 @@ func (np *Processor) processAddPeer(ev netmapEvent.AddPeer) {
return
}

var info clientcore.NodeInfo
err = clientcore.NodeInfoFromRawNetmapElement(&info, netmapCore.Node(nodeInfo))
if err != nil {
np.log.Warn("could not convert node info: %w", zap.Error(err))
return
}

c, err := np.clientSource.Get(info)
if err != nil {
np.log.Warn("could not create client to the node: %w",
zap.Error(err),
zap.String("node", hex.EncodeToString(info.PublicKey())))
return
}

_, err = c.EndpointInfo(context.Background(), client.PrmEndpointInfo{})
if err != nil {
np.log.Warn("could not ping node with network info",
zap.Error(err),
zap.String("node", hex.EncodeToString(info.PublicKey())))
}

// sort attributes to make it consistent
nodeInfo.SortAttributes()

Expand Down
14 changes: 14 additions & 0 deletions pkg/innerring/processors/netmap/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/nspcc-dev/neo-go/pkg/core/mempoolevent"
clientcore "github.com/nspcc-dev/neofs-node/pkg/core/client"
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap/nodevalidation/state"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
nmClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
Expand Down Expand Up @@ -49,6 +50,11 @@ type (
VerifyAndUpdate(*netmap.NodeInfo) error
}

// ClientSource must provide working [clientcore.Client].
ClientSource interface {
Get(clientcore.NodeInfo) (clientcore.Client, error)
}

// Processor of events produced by network map contract
// and new epoch ticker, because it is related to contract.
Processor struct {
Expand All @@ -71,6 +77,8 @@ type (
nodeValidator NodeValidator

nodeStateSettings state.NetworkSettings

clientSource ClientSource
}

// Params of the processor constructor.
Expand All @@ -93,6 +101,8 @@ type (
NodeValidator NodeValidator

NodeStateSettings state.NetworkSettings

ClientSource ClientSource
}
)

Expand Down Expand Up @@ -126,6 +136,8 @@ func New(p *Params) (*Processor, error) {
return nil, errors.New("ir/netmap: node validator is not set")
case p.NodeStateSettings == nil:
return nil, errors.New("ir/netmap: node state settings is not set")
case p.ClientSource == nil:
return nil, errors.New("ir/netmap: client source is not set")
}

p.Log.Debug("netmap worker pool", zap.Int("size", p.PoolSize))
Expand Down Expand Up @@ -155,6 +167,8 @@ func New(p *Params) (*Processor, error) {
nodeValidator: p.NodeValidator,

nodeStateSettings: p.NodeStateSettings,

clientSource: p.ClientSource,
}, nil
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/network/cache/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ func (x *multiClient) ObjectSearchInit(ctx context.Context, containerID cid.ID,
return
}

func (x *multiClient) EndpointInfo(ctx context.Context, prm client.PrmEndpointInfo) (res *client.ResEndpointInfo, err error) {
err = x.iterateClients(ctx, func(c clientcore.Client) error {
res, err = c.EndpointInfo(ctx, prm)
return err
})

return
}

func (x *multiClient) AnnounceLocalTrust(ctx context.Context, epoch uint64, trusts []reputationSDK.Trust, prm client.PrmAnnounceLocalTrust) error {
return x.iterateClients(ctx, func(c clientcore.Client) error {
return c.AnnounceLocalTrust(ctx, epoch, trusts, prm)
Expand Down

0 comments on commit 8f93a19

Please sign in to comment.