[#1365] ir: Check homomorphic hash flexibly in audit

Do not perform that check if it was turned off for the container being
checked.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-04-29 20:59:14 +03:00 committed by Evgenii Stratonikov
parent 455096ab53
commit e9c534b0a0

View file

@ -7,6 +7,7 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
"github.com/nspcc-dev/neofs-node/pkg/util/rand"
containerSDK "github.com/nspcc-dev/neofs-sdk-go/container"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
storagegroupSDK "github.com/nspcc-dev/neofs-sdk-go/storagegroup"
"github.com/nspcc-dev/tzhash/tz"
@ -50,6 +51,8 @@ func (c *Context) checkStorageGroupPoR(sgID oid.ID, sg storagegroupSDK.StorageGr
getHeaderPrm.CID = c.task.ContainerID()
getHeaderPrm.NodeIsRelay = true
homomorphicHashingEnabled := !containerSDK.IsHomomorphicHashingDisabled(c.task.ContainerStructure())
for i := range members {
objectPlacement, err := c.buildPlacement(members[i])
if err != nil {
@ -90,18 +93,22 @@ func (c *Context) checkStorageGroupPoR(sgID oid.ID, sg storagegroupSDK.StorageGr
// update cache for PoR and PDP audit checks
c.updateHeadResponses(hdr)
cs, _ := hdr.PayloadHomomorphicHash()
if homomorphicHashingEnabled {
cs, _ := hdr.PayloadHomomorphicHash()
if len(tzHash) == 0 {
tzHash = cs.Value()
} else {
tzHash, err = tz.Concat([][]byte{
tzHash,
cs.Value(),
})
if err != nil {
c.log.Debug("can't concatenate tz hash",
zap.String("oid", members[i].String()),
zap.String("error", err.Error()))
if len(tzHash) == 0 {
tzHash = cs.Value()
} else {
tzHash, err = tz.Concat([][]byte{tzHash, cs.Value()})
if err != nil {
c.log.Debug("can't concatenate tz hash",
zap.Stringer("oid", members[i]),
zap.String("error", err.Error()))
break
break
}
}
}
@ -116,7 +123,7 @@ func (c *Context) checkStorageGroupPoR(sgID oid.ID, sg storagegroupSDK.StorageGr
sizeCheck := sg.ValidationDataSize() == totalSize
cs, _ := sg.ValidationDataHash()
tzCheck := bytes.Equal(tzHash, cs.Value())
tzCheck := !homomorphicHashingEnabled || bytes.Equal(tzHash, cs.Value())
if sizeCheck && tzCheck {
c.report.PassedPoR(sgID) // write report