2020-09-03 14:55:11 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/innerring/invoke"
|
|
|
|
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
|
|
|
"go.uber.org/zap"
|
2020-10-20 10:50:35 +00:00
|
|
|
"google.golang.org/protobuf/proto"
|
2020-09-03 14:55:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Process add peer notification by sanity check of new node
|
|
|
|
// local epoch timer.
|
|
|
|
func (np *Processor) processAddPeer(node []byte) {
|
|
|
|
if !np.activeState.IsActive() {
|
|
|
|
np.log.Info("passive mode, ignore new peer notification")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// unmarshal grpc (any transport) version of node info from API v2
|
|
|
|
nodeInfo := new(netmap.NodeInfo)
|
|
|
|
|
2020-10-20 10:50:35 +00:00
|
|
|
err := proto.Unmarshal(node, nodeInfo)
|
2020-09-03 14:55:11 +00:00
|
|
|
if err != nil {
|
|
|
|
// it will be nice to have tx id at event structure to log it
|
|
|
|
np.log.Warn("can't parse network map candidate")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-10-29 16:01:35 +00:00
|
|
|
keyString := hex.EncodeToString(nodeInfo.PublicKey)
|
2020-09-03 14:55:11 +00:00
|
|
|
np.log.Info("approving network map candidate",
|
2020-10-29 16:01:35 +00:00
|
|
|
zap.String("key", keyString))
|
2020-09-03 14:55:11 +00:00
|
|
|
|
2020-10-29 16:01:35 +00:00
|
|
|
exists := np.netmapSnapshot.touch(keyString, np.epochState.EpochCounter())
|
|
|
|
if !exists {
|
|
|
|
err = invoke.ApprovePeer(np.morphClient, np.netmapContract, node)
|
|
|
|
if err != nil {
|
|
|
|
np.log.Error("can't invoke netmap.AddPeer", zap.Error(err))
|
|
|
|
}
|
2020-09-03 14:55:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-29 16:04:17 +00:00
|
|
|
// Process update peer notification by sending approval tx to the smart contract.
|
2020-09-03 14:55:11 +00:00
|
|
|
func (np *Processor) processUpdatePeer(ev netmapEvent.UpdatePeer) {
|
|
|
|
if !np.activeState.IsActive() {
|
|
|
|
np.log.Info("passive mode, ignore new epoch tick")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// better use unified enum from neofs-api-go/v2/netmap package
|
|
|
|
if ev.Status() != uint32(netmap.NodeInfo_OFFLINE) {
|
|
|
|
np.log.Warn("node proposes unknown state",
|
|
|
|
zap.String("key", hex.EncodeToString(ev.PublicKey().Bytes())),
|
|
|
|
zap.Uint32("status", ev.Status()),
|
|
|
|
)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-10-29 16:04:17 +00:00
|
|
|
// flag node to remove from local view, so it can be re-bootstrapped
|
|
|
|
// again before new epoch will tick
|
|
|
|
np.netmapSnapshot.flag(ev.PublicKey().String())
|
|
|
|
|
2020-09-03 14:55:11 +00:00
|
|
|
err := invoke.UpdatePeerState(np.morphClient, np.netmapContract,
|
|
|
|
&invoke.UpdatePeerArgs{
|
|
|
|
Key: ev.PublicKey(),
|
|
|
|
Status: ev.Status(),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
np.log.Error("can't invoke netmap.UpdatePeer", zap.Error(err))
|
|
|
|
}
|
|
|
|
}
|