From cbfaceb95666f911409c8491274ebd2237b88ed0 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 9 Feb 2021 17:36:43 +0300 Subject: [PATCH] [#316] ir/netmap: Validate network map candidates in Netmap processor Define NodeValidator interface of the entity that checks and finalizes NodeInfo structure. Add NodeValidator to Netmap processor. Pass NodeInfo structures of network map candidates to NodeValidator in order to verify it and prepare to final state required by network. Signed-off-by: Leonard Lyubich --- .../processors/netmap/process_peers.go | 10 ++++++++ pkg/innerring/processors/netmap/processor.go | 24 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/pkg/innerring/processors/netmap/process_peers.go b/pkg/innerring/processors/netmap/process_peers.go index 5b9453c41..045fda352 100644 --- a/pkg/innerring/processors/netmap/process_peers.go +++ b/pkg/innerring/processors/netmap/process_peers.go @@ -25,6 +25,16 @@ func (np *Processor) processAddPeer(node []byte) { return } + // validate and update node info + err := np.nodeValidator.VerifyAndUpdate(nodeInfo) + if err != nil { + np.log.Warn("could not verify and update information about network map candidate", + zap.String("error", err.Error()), + ) + + return + } + keyString := hex.EncodeToString(nodeInfo.PublicKey()) exists := np.netmapSnapshot.touch(keyString, np.epochState.EpochCounter()) diff --git a/pkg/innerring/processors/netmap/processor.go b/pkg/innerring/processors/netmap/processor.go index b84e40dc3..9f3c62714 100644 --- a/pkg/innerring/processors/netmap/processor.go +++ b/pkg/innerring/processors/netmap/processor.go @@ -2,6 +2,7 @@ package netmap import ( "github.com/nspcc-dev/neo-go/pkg/util" + "github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-node/pkg/morph/client" container "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper" "github.com/nspcc-dev/neofs-node/pkg/morph/event" @@ -28,6 +29,21 @@ type ( IsActive() bool } + // NodeValidator wraps basic method of checking the correctness + // of information about the node and its finalization for adding + // to the network map. + NodeValidator interface { + // Must verify and update NodeInfo structure. + // + // Must return an error if NodeInfo input is invalid. + // Must return an error if it is not possible to correctly + // change the structure for sending to the network map. + // + // If no error occurs, the parameter must point to the + // ready-made NodeInfo structure. + VerifyAndUpdate(*netmap.NodeInfo) error + } + // Processor of events produced by network map contract // and new epoch ticker, because it is related to contract. Processor struct { @@ -45,6 +61,8 @@ type ( handleNewAudit event.Handler handleAuditSettlements event.Handler + + nodeValidator NodeValidator } // Params of the processor constructor. @@ -62,6 +80,8 @@ type ( HandleAudit event.Handler AuditSettlementsHandler event.Handler + + NodeValidator NodeValidator } ) @@ -90,6 +110,8 @@ func New(p *Params) (*Processor, error) { return nil, errors.New("ir/netmap: audit settlement handler is not set") case p.ContainerWrapper == nil: return nil, errors.New("ir/netmap: container contract wrapper is not set") + case p.NodeValidator == nil: + return nil, errors.New("ir/netmap: node validator is not set") } p.Log.Debug("netmap worker pool", zap.Int("size", p.PoolSize)) @@ -112,6 +134,8 @@ func New(p *Params) (*Processor, error) { handleNewAudit: p.HandleAudit, handleAuditSettlements: p.AuditSettlementsHandler, + + nodeValidator: p.NodeValidator, }, nil }