From ae4740f99f3ba9a7c04a5a1d047e006618163240 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 29 Apr 2022 20:59:14 +0300 Subject: [PATCH] [#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 --- pkg/services/audit/auditor/por.go | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/pkg/services/audit/auditor/por.go b/pkg/services/audit/auditor/por.go index d07fd0aef..be7d3b87e 100644 --- a/pkg/services/audit/auditor/por.go +++ b/pkg/services/audit/auditor/por.go @@ -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