frostfs-node/pkg/innerring/processors/netmap/nodevalidation/subnet/calls.go
Alex Vanin 20de74a505 Rename package name
Due to source code relocation from GitHub.

Signed-off-by: Alex Vanin <a.vanin@yadro.com>
2023-03-07 16:38:26 +03:00

42 lines
1 KiB
Go

package subnet
import (
"fmt"
morphsubnet "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/subnet"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
subnetid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/subnet/id"
)
// VerifyAndUpdate calls subnet contract's `NodeAllowed` method.
// Removes subnets that have not been approved by the contract.
func (v *Validator) VerifyAndUpdate(n *netmap.NodeInfo) error {
prm := morphsubnet.NodeAllowedPrm{}
err := n.IterateSubnets(func(id subnetid.ID) error {
// every node can be bootstrapped
// to the zero subnetwork
if subnetid.IsZero(id) {
return nil
}
prm.SetID(id.Marshal())
prm.SetNode(n.PublicKey())
res, err := v.subnetClient.NodeAllowed(prm)
if err != nil {
return fmt.Errorf("could not call `NodeAllowed` contract method: %w", err)
}
if !res.Allowed() {
return netmap.ErrRemoveSubnet
}
return nil
})
if err != nil {
return fmt.Errorf("could not verify subnet entrance of the node: %w", err)
}
return nil
}