2021-11-28 12:56:46 +00:00
|
|
|
package subnet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
morphsubnet "github.com/TrueCloudLab/frostfs-node/pkg/morph/client/subnet"
|
|
|
|
"github.com/TrueCloudLab/frostfs-sdk-go/netmap"
|
|
|
|
subnetid "github.com/TrueCloudLab/frostfs-sdk-go/subnet/id"
|
2021-11-28 12:56:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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 {
|
2021-12-01 09:01:50 +00:00
|
|
|
// every node can be bootstrapped
|
|
|
|
// to the zero subnetwork
|
|
|
|
if subnetid.IsZero(id) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-06-15 08:08:10 +00:00
|
|
|
prm.SetID(id.Marshal())
|
2021-11-28 12:56:46 +00:00
|
|
|
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
|
|
|
|
}
|