diff --git a/cmd/neofs-adm/internal/modules/morph/subnet.go b/cmd/neofs-adm/internal/modules/morph/subnet.go index e8dc67c8d..e41e478fd 100644 --- a/cmd/neofs-adm/internal/modules/morph/subnet.go +++ b/cmd/neofs-adm/internal/modules/morph/subnet.go @@ -140,18 +140,13 @@ var cmdSubnetCreate = &cobra.Command{ for { num = rand.Uint32() - id.SetNumber(num) + id.SetNumeric(num) if !subnetid.IsZero(id) { break } } - binID, err := id.Marshal() - if err != nil { - return fmt.Errorf("marshal subnet ID: %w", err) - } - // declare creator ID and encode it var creator user.ID user.IDFromKey(&creator, key.PrivateKey.PublicKey) @@ -162,12 +157,7 @@ var cmdSubnetCreate = &cobra.Command{ info.SetID(id) info.SetOwner(creator) - binInfo, err := info.Marshal() - if err != nil { - return fmt.Errorf("marshal subnet info: %w", err) - } - - err = invokeMethod(key, true, "put", binID, key.PublicKey().Bytes(), binInfo) + err = invokeMethod(key, true, "put", id.Marshal(), key.PublicKey().Bytes(), info.Marshal()) if err != nil { return fmt.Errorf("morph invocation: %w", err) } @@ -210,7 +200,7 @@ var cmdSubnetRemove = &cobra.Command{ // read ID and encode it var id subnetid.ID - err = id.UnmarshalText([]byte(viper.GetString(flagSubnetRemoveID))) + err = id.DecodeString(viper.GetString(flagSubnetRemoveID)) if err != nil { return fmt.Errorf("decode ID text: %w", err) } @@ -219,12 +209,7 @@ var cmdSubnetRemove = &cobra.Command{ return errZeroSubnet } - binID, err := id.Marshal() - if err != nil { - return fmt.Errorf("marshal subnet ID: %w", err) - } - - err = invokeMethod(key, false, "delete", binID) + err = invokeMethod(key, false, "delete", id.Marshal()) if err != nil { return fmt.Errorf("morph invocation: %w", err) } @@ -254,7 +239,7 @@ var cmdSubnetGet = &cobra.Command{ // read ID and encode it var id subnetid.ID - err := id.UnmarshalText([]byte(viper.GetString(flagSubnetGetID))) + err := id.DecodeString(viper.GetString(flagSubnetGetID)) if err != nil { return fmt.Errorf("decode ID text: %w", err) } @@ -263,11 +248,6 @@ var cmdSubnetGet = &cobra.Command{ return errZeroSubnet } - binID, err := id.Marshal() - if err != nil { - return fmt.Errorf("marshal subnet ID: %w", err) - } - // use random key to fetch the data // we could use raw neo-go client to perform testInvoke // without keys, as it is done in other commands @@ -276,7 +256,7 @@ var cmdSubnetGet = &cobra.Command{ return fmt.Errorf("init subnet client: %w", err) } - res, err := testInvokeMethod(*key, "get", binID) + res, err := testInvokeMethod(*key, "get", id.Marshal()) if err != nil { return fmt.Errorf("morph invocation: %w", err) } @@ -297,11 +277,7 @@ var cmdSubnetGet = &cobra.Command{ } // print information - var ownerID user.ID - - info.ReadOwner(&ownerID) - - cmd.Printf("Owner: %s\n", &ownerID) + cmd.Printf("Owner: %s\n", info.Owner()) return nil }, @@ -350,7 +326,7 @@ func manageSubnetAdmins(cmd *cobra.Command, rm bool) error { // read ID and encode it var id subnetid.ID - err = id.UnmarshalText([]byte(viper.GetString(flagSubnetAdminSubnet))) + err = id.DecodeString(viper.GetString(flagSubnetAdminSubnet)) if err != nil { return fmt.Errorf("decode ID text: %w", err) } @@ -359,11 +335,6 @@ func manageSubnetAdmins(cmd *cobra.Command, rm bool) error { return errZeroSubnet } - binID, err := id.Marshal() - if err != nil { - return fmt.Errorf("marshal subnet ID: %w", err) - } - // read admin key and decode it binAdminKey, err := hex.DecodeString(viper.GetString(flagSubnetAdminID)) if err != nil { @@ -377,7 +348,7 @@ func manageSubnetAdmins(cmd *cobra.Command, rm bool) error { // prepare call parameters prm := make([]interface{}, 0, 3) - prm = append(prm, binID) + prm = append(prm, id.Marshal()) var method string @@ -497,7 +468,7 @@ func manageSubnetClients(cmd *cobra.Command, rm bool) error { // read ID and encode it var id subnetid.ID - err = id.UnmarshalText([]byte(viper.GetString(flagSubnetClientSubnet))) + err = id.DecodeString(viper.GetString(flagSubnetClientSubnet)) if err != nil { return fmt.Errorf("decode ID text: %w", err) } @@ -506,11 +477,6 @@ func manageSubnetClients(cmd *cobra.Command, rm bool) error { return errZeroSubnet } - binID, err := id.Marshal() - if err != nil { - return fmt.Errorf("marshal subnet ID: %w", err) - } - // read client ID and encode it var clientID user.ID @@ -539,7 +505,7 @@ func manageSubnetClients(cmd *cobra.Command, rm bool) error { method = "addUser" } - err = invokeMethod(key, false, method, binID, binGroupID, clientID.WalletBytes()) + err = invokeMethod(key, false, method, id.Marshal(), binGroupID, clientID.WalletBytes()) if err != nil { return fmt.Errorf("morph invocation: %w", err) } @@ -596,7 +562,7 @@ func manageSubnetNodes(cmd *cobra.Command, rm bool) error { // read ID and encode it var id subnetid.ID - err = id.UnmarshalText([]byte(viper.GetString(flagSubnetNodeSubnet))) + err = id.DecodeString(viper.GetString(flagSubnetNodeSubnet)) if err != nil { return fmt.Errorf("decode ID text: %w", err) } @@ -605,11 +571,6 @@ func manageSubnetNodes(cmd *cobra.Command, rm bool) error { return errZeroSubnet } - binID, err := id.Marshal() - if err != nil { - return fmt.Errorf("marshal subnet ID: %w", err) - } - // read node ID and encode it binNodeID, err := hex.DecodeString(viper.GetString(flagSubnetNode)) if err != nil { @@ -628,7 +589,7 @@ func manageSubnetNodes(cmd *cobra.Command, rm bool) error { method = "addNode" } - err = invokeMethod(key, false, method, binID, binNodeID) + err = invokeMethod(key, false, method, id.Marshal(), binNodeID) if err != nil { return fmt.Errorf("morph invocation: %w", err) } diff --git a/cmd/neofs-cli/modules/container.go b/cmd/neofs-cli/modules/container.go index 142b454c5..0acc2ea04 100644 --- a/cmd/neofs-cli/modules/container.go +++ b/cmd/neofs-cli/modules/container.go @@ -141,10 +141,12 @@ It will be stored in sidechain when inner ring will accepts it.`, placementPolicy, err := parseContainerPolicy(containerPolicy) common.ExitOnErr(cmd, "", err) - subnetID, err := parseSubnetID(containerSubnet) + var subnetID subnetid.ID + + err = subnetID.DecodeString(containerSubnet) common.ExitOnErr(cmd, "could not parse subnetID: %w", err) - placementPolicy.SetSubnetID(subnetID) + placementPolicy.SetSubnetID(&subnetID) attributes, err := parseAttributes(containerAttributes) common.ExitOnErr(cmd, "", err) @@ -596,16 +598,6 @@ func prettyPrintContainerList(cmd *cobra.Command, list []cid.ID) { } } -func parseSubnetID(val string) (sub *subnetid.ID, err error) { - sub = &subnetid.ID{} - - if val != "" { - err = sub.UnmarshalText([]byte(val)) - } - - return -} - func parseContainerPolicy(policyString string) (*netmap.PlacementPolicy, error) { _, err := os.Stat(policyString) // check if `policyString` is a path to file with placement policy if err == nil { diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index ac8879f87..f79d7145f 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -186,7 +186,7 @@ func readSubnetCfg(c *cfg) { ) subnetCfg.IterateSubnets(func(idTxt string) { - err = id.UnmarshalText([]byte(idTxt)) + err = id.DecodeString(idTxt) fatalOnErrDetails("parse subnet entry", err) c.cfgNodeInfo.localInfo.EnterSubnet(id) diff --git a/go.mod b/go.mod index 7012823f0..e582d4826 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5 // indirect github.com/nspcc-dev/neofs-api-go/v2 v2.12.2 github.com/nspcc-dev/neofs-contract v0.15.1 - github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220609064532-517d7a1e4a0f + github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220615085207-eb3b99081235 github.com/nspcc-dev/tzhash v1.5.2 github.com/panjf2000/ants/v2 v2.4.0 github.com/paulmach/orb v0.2.2 diff --git a/go.sum b/go.sum index 6c1c756e5..9eb96d598 100644 --- a/go.sum +++ b/go.sum @@ -409,8 +409,8 @@ github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnB github.com/nspcc-dev/neofs-crypto v0.3.0/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw= github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211201182451-a5b61c4f6477/go.mod h1:dfMtQWmBHYpl9Dez23TGtIUKiFvCIxUZq/CkSIhEpz4= github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659/go.mod h1:/jay1lr3w7NQd/VDBkEhkJmDmyPNsu4W+QV2obsUV40= -github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220609064532-517d7a1e4a0f h1:xqmVaOsc0CPXWVLqtVFfIHfHQtbm6XGlOwVNYCmOeYo= -github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220609064532-517d7a1e4a0f/go.mod h1:k58jgszGX3pws2yiOXu9m0i32BzRgi1T6Bpd/L1KrJU= +github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220615085207-eb3b99081235 h1:HmV0UTOusPLZ+YFUW+lLfpaFkLVy2MSUsNwgpTaXGCc= +github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220615085207-eb3b99081235/go.mod h1:k58jgszGX3pws2yiOXu9m0i32BzRgi1T6Bpd/L1KrJU= github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso= github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE= github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso= diff --git a/pkg/innerring/processors/container/process_container.go b/pkg/innerring/processors/container/process_container.go index bb464da58..d761f15d3 100644 --- a/pkg/innerring/processors/container/process_container.go +++ b/pkg/innerring/processors/container/process_container.go @@ -247,12 +247,7 @@ func checkSubnet(subCli *morphsubnet.Client, cnr *containerSDK.Container) error return nil } - rawSubID, err := subID.Marshal() - if err != nil { - return fmt.Errorf("could not marshal container subnetwork: %w", err) - } - - prm.SetID(rawSubID) + prm.SetID(subID.Marshal()) prm.SetClient(owner.WalletBytes()) res, err := subCli.UserAllowed(prm) diff --git a/pkg/innerring/processors/netmap/nodevalidation/subnet/calls.go b/pkg/innerring/processors/netmap/nodevalidation/subnet/calls.go index 70438de1b..399cf865f 100644 --- a/pkg/innerring/processors/netmap/nodevalidation/subnet/calls.go +++ b/pkg/innerring/processors/netmap/nodevalidation/subnet/calls.go @@ -20,12 +20,7 @@ func (v *Validator) VerifyAndUpdate(n *netmap.NodeInfo) error { return nil } - rawSubnetID, err := id.Marshal() - if err != nil { - return fmt.Errorf("could not marshal subnetwork ID: %w", err) - } - - prm.SetID(rawSubnetID) + prm.SetID(id.Marshal()) prm.SetNode(n.PublicKey()) res, err := v.subnetClient.NodeAllowed(prm) diff --git a/pkg/innerring/processors/netmap/process_peers.go b/pkg/innerring/processors/netmap/process_peers.go index 4777700b7..9edb87d51 100644 --- a/pkg/innerring/processors/netmap/process_peers.go +++ b/pkg/innerring/processors/netmap/process_peers.go @@ -166,7 +166,7 @@ func (np *Processor) processRemoveSubnetNode(ev subnetEvent.RemoveNode) { } rawSubnet := ev.SubnetworkID() - subnetToRemoveFrom := &subnetid.ID{} + var subnetToRemoveFrom subnetid.ID err = subnetToRemoveFrom.Unmarshal(rawSubnet) if err != nil { @@ -176,7 +176,7 @@ func (np *Processor) processRemoveSubnetNode(ev subnetEvent.RemoveNode) { return } - if subnetid.IsZero(*subnetToRemoveFrom) { + if subnetid.IsZero(subnetToRemoveFrom) { np.log.Warn("got zero subnet in remove node notification") return } diff --git a/pkg/innerring/processors/subnet/put.go b/pkg/innerring/processors/subnet/put.go index 7d4dc25d6..1b7f4905b 100644 --- a/pkg/innerring/processors/subnet/put.go +++ b/pkg/innerring/processors/subnet/put.go @@ -69,12 +69,12 @@ func (x PutValidator) Assert(event Put) error { } // check if the explicit ID equals to the one from info - if !subnet.IDEquals(info, id) { + if !subnet.AssertReference(info, id) { return errDiffID } // check if the explicit creator equals to the one from info - if !subnet.IsOwner(info, creator) { + if !subnet.AssertOwnership(info, creator) { return errDiffOwner } diff --git a/pkg/innerring/processors/subnet/put_test.go b/pkg/innerring/processors/subnet/put_test.go index 62452230b..d91521e2d 100644 --- a/pkg/innerring/processors/subnet/put_test.go +++ b/pkg/innerring/processors/subnet/put_test.go @@ -68,7 +68,7 @@ func TestPutValidator_Assert(t *testing.T) { require.ErrorAs(t, err, new(zeroSubnetOp)) const idNum = 13 - e.id.SetNumber(idNum) + e.id.SetNumeric(idNum) // read creator error e.creatorErr = errors.New("creator err") @@ -89,7 +89,7 @@ func TestPutValidator_Assert(t *testing.T) { // diff explicit ID and the one in info var id2 subnetid.ID - id2.SetNumber(idNum + 1) + id2.SetNumeric(idNum + 1) e.info.SetID(id2) diff --git a/pkg/innerring/subnet.go b/pkg/innerring/subnet.go index 5d040ab23..f60d736a0 100644 --- a/pkg/innerring/subnet.go +++ b/pkg/innerring/subnet.go @@ -314,7 +314,7 @@ func (s *Server) processCandidate(txHash neogoutil.Uint256, removedID subnetid.I ) err := c.NodeInfo.IterateSubnets(func(id subnetid.ID) error { - if removedID.Equals(&id) { + if removedID.Equals(id) { removeSubnet = true return netmap.ErrRemoveSubnet } diff --git a/pkg/morph/event/subnet/remove_node_test.go b/pkg/morph/event/subnet/remove_node_test.go index 17410a012..dcad25e9e 100644 --- a/pkg/morph/event/subnet/remove_node_test.go +++ b/pkg/morph/event/subnet/remove_node_test.go @@ -25,10 +25,9 @@ func TestParseRemoveNode(t *testing.T) { }) subnetID := subnetid.ID{} - subnetID.SetNumber(123) + subnetID.SetNumeric(123) - rawSubnetID, err := subnetID.Marshal() - require.NoError(t, err) + rawSubnetID := subnetID.Marshal() priv, err := keys.NewPrivateKey() require.NoError(t, err)