[#1365] cli: Calculate homomorphic hash flexibly

Do not use homomorphic hash in storage group for containers that have
`homomorphic_hashing_disabled` set to `true`.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-04-29 20:02:52 +03:00 committed by fyrchik
parent 68e583f143
commit ae86d2907c
2 changed files with 31 additions and 18 deletions

View file

@ -14,6 +14,7 @@ import (
objectCli "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/modules/object"
sessionCli "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/modules/session"
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/storagegroup"
"github.com/nspcc-dev/neofs-sdk-go/container"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
"github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
@ -76,10 +77,18 @@ func putSG(cmd *cobra.Command, _ []string) {
}
var (
headPrm internalclient.HeadObjectPrm
putPrm internalclient.PutObjectPrm
headPrm internalclient.HeadObjectPrm
putPrm internalclient.PutObjectPrm
getCnrPrm internalclient.GetContainerPrm
)
cli := internalclient.GetSDKClientByFlag(cmd, pk, commonflags.RPC)
getCnrPrm.SetClient(cli)
getCnrPrm.SetContainer(cnr)
resGetCnr, err := internalclient.GetContainer(getCnrPrm)
common.ExitOnErr(cmd, "get container RPC call: %w", err)
sessionCli.Prepare(cmd, cnr, nil, pk, &putPrm)
objectCli.Prepare(cmd, &headPrm, &putPrm)
@ -90,11 +99,9 @@ func putSG(cmd *cobra.Command, _ []string) {
key: pk,
ownerID: &ownerID,
prm: headPrm,
}, cnr, members)
}, cnr, members, !container.IsHomomorphicHashingDisabled(resGetCnr.Container()))
common.ExitOnErr(cmd, "could not collect storage group members: %w", err)
cli := internalclient.GetSDKClientByFlag(cmd, pk, commonflags.RPC)
var netInfoPrm internalclient.NetworkInfoPrm
netInfoPrm.SetClient(cli)

View file

@ -14,7 +14,7 @@ import (
// with information about members collected via HeadReceiver.
//
// Resulting storage group consists of physically stored objects only.
func CollectMembers(r objutil.HeadReceiver, cnr cid.ID, members []oid.ID) (*storagegroup.StorageGroup, error) {
func CollectMembers(r objutil.HeadReceiver, cnr cid.ID, members []oid.ID, calcHomoHash bool) (*storagegroup.StorageGroup, error) {
var (
sumPhySize uint64
phyMembers []oid.ID
@ -37,25 +37,31 @@ func CollectMembers(r objutil.HeadReceiver, cnr cid.ID, members []oid.ID) (*stor
phyMembers = append(phyMembers, id)
sumPhySize += leaf.PayloadSize()
cs, _ := leaf.PayloadHomomorphicHash()
phyHashes = append(phyHashes, cs.Value())
if calcHomoHash {
phyHashes = append(phyHashes, cs.Value())
}
}); err != nil {
return nil, err
}
}
sumHash, err := tz.Concat(phyHashes)
if err != nil {
return nil, err
}
var cs checksum.Checksum
tzHash := [64]byte{}
copy(tzHash[:], sumHash)
cs.SetTillichZemor(tzHash)
sg.SetMembers(phyMembers)
sg.SetValidationDataSize(sumPhySize)
sg.SetValidationDataHash(cs)
if calcHomoHash {
sumHash, err := tz.Concat(phyHashes)
if err != nil {
return nil, err
}
var cs checksum.Checksum
tzHash := [64]byte{}
copy(tzHash[:], sumHash)
cs.SetTillichZemor(tzHash)
sg.SetValidationDataHash(cs)
}
return &sg, nil
}