[#150] frostfsid: Fix 'update' clears group counter

Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
Alexander Chuprov 2025-03-11 11:25:41 +03:00
parent 201db45bd7
commit 0653f0dbc6
Signed by: achuprov
GPG key ID: 2D916FFD803B0EDD
3 changed files with 70 additions and 0 deletions

View file

@ -44,3 +44,8 @@ func AppendVersion(data any) []interface{} {
}
return append(data.([]any), Version)
}
// GetVersion returns version as int by major, minor, patch.
func GetVersion(major, minor, patch int) int {
return major*1_000_000 + minor*1_000 + patch
}

View file

@ -134,6 +134,22 @@ func _deploy(data any, isUpdate bool) {
storage.Put(ctx, address, true)
}
}
if args.version < common.GetVersion(0, 21, 2) {
maxGroupID := 0
it := storage.Find(ctx, groupKeysPrefix, storage.ValuesOnly)
for iterator.Next(it) {
groupRaw := iterator.Value(it)
group := std.Deserialize(groupRaw.([]byte)).(Group)
if group.ID > maxGroupID {
maxGroupID = group.ID
}
}
storage.Put(ctx, groupCounterKey, maxGroupID)
}
return
}
storage.Put(ctx, groupCounterKey, 0)

View file

@ -1,7 +1,9 @@
package tests
import (
"encoding/json"
"errors"
"fmt"
"path"
"testing"
@ -656,6 +658,53 @@ func TestAdditionalKeyFromPrimarySubject(t *testing.T) {
invoker.Invoke(t, stackitem.Null{}, createSubjectMethod, defaultNamespace, subjFPrimaryKey.PublicKey().Bytes())
}
func TestFrostFSIS_GroupsAfterUpdate(t *testing.T) {
countNamesepce := 2
f := newFrostFSIDInvoker(t)
invoker := f.OwnerInvoker()
groupid := int64(1)
for i := range countNamesepce {
namespace := fmt.Sprintf("nm_%d", i)
invoker.Invoke(t, stackitem.Null{}, createNamespaceMethod, namespace)
}
for i := range 5 {
namespace := fmt.Sprintf("nm_%d", i%2)
groupName := fmt.Sprintf("group_%d", groupid)
invoker.Invoke(t, stackitem.Make(groupid), createGroupMethod, namespace, groupName)
s, err := invoker.TestInvoke(t, getGroupIDByNameMethod, namespace, groupName)
checkGroupIDResult(t, s, err, groupid)
groupid++
}
args := make([]any, 2)
args[0] = f.owner.ScriptHash()
args[1] = 21 * 1_000
c := neotest.CompileFile(t, f.e.CommitteeHash, frostfsidPath, path.Join(frostfsidPath, "config.yml"))
nef, err := c.NEF.Bytes()
require.NoError(t, err)
manifest, err := json.Marshal(c.Manifest)
require.NoError(t, err)
f.CommitteeInvoker().Invoke(t, stackitem.Null{}, "update", nef, manifest, args)
for i := range 5 {
namespace := fmt.Sprintf("nm_%d", i%2)
groupName := fmt.Sprintf("group_%d", groupid)
invoker.Invoke(t, stackitem.Make(groupid), createGroupMethod, namespace, groupName)
s, err := invoker.TestInvoke(t, getGroupIDByNameMethod, namespace, groupName)
checkGroupIDResult(t, s, err, groupid)
groupid++
}
}
func checkPublicKeyResult(t *testing.T, s *vm.Stack, err error, key *keys.PrivateKey) {
if key == nil {
require.ErrorContains(t, err, "not found")