From 8a61d33c65096a23030ccdf41ccf65260fac2cab Mon Sep 17 00:00:00 2001
From: Pavel Karpy <carpawell@nspcc.ru>
Date: Fri, 29 Apr 2022 20:48:11 +0300
Subject: [PATCH] [#1365] ir: Check homomorphic hash setting on `ContainerPut`

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
---
 .../processors/container/process_container.go | 19 +++++++++++++++++++
 .../processors/container/processor.go         |  8 ++++++++
 2 files changed, 27 insertions(+)

diff --git a/pkg/innerring/processors/container/process_container.go b/pkg/innerring/processors/container/process_container.go
index ba0930608..0cb97ca20 100644
--- a/pkg/innerring/processors/container/process_container.go
+++ b/pkg/innerring/processors/container/process_container.go
@@ -82,6 +82,12 @@ func (cp *Processor) checkPutContainer(ctx *putContainerContext) error {
 		return fmt.Errorf("incorrect subnetwork: %w", err)
 	}
 
+	// check homomorphic hashing setting
+	err = checkHomomorphicHashing(cp.netState, cnr)
+	if err != nil {
+		return fmt.Errorf("incorrect homomorphic hashing setting: %w", err)
+	}
+
 	// check native name and zone
 	err = checkNNS(ctx, cnr)
 	if err != nil {
@@ -237,3 +243,16 @@ func checkSubnet(subCli *morphsubnet.Client, cnr containerSDK.Container) error {
 
 	return nil
 }
+
+func checkHomomorphicHashing(ns NetworkState, cnr containerSDK.Container) error {
+	netSetting, err := ns.HomomorphicHashDisabled()
+	if err != nil {
+		return fmt.Errorf("could not get setting in contract: %w", err)
+	}
+
+	if cnrSetting := containerSDK.IsHomomorphicHashingDisabled(cnr); netSetting != cnrSetting {
+		return fmt.Errorf("network setting: %t, container setting: %t", netSetting, cnrSetting)
+	}
+
+	return nil
+}
diff --git a/pkg/innerring/processors/container/processor.go b/pkg/innerring/processors/container/processor.go
index cd03e202d..039eb5fb4 100644
--- a/pkg/innerring/processors/container/processor.go
+++ b/pkg/innerring/processors/container/processor.go
@@ -53,6 +53,14 @@ type NetworkState interface {
 	// Must return any error encountered
 	// which did not allow reading the value.
 	Epoch() (uint64, error)
+
+	// HomomorphicHashDisabled must return boolean that
+	// represents homomorphic network state:
+	// 	* true if hashing is disabled;
+	// 	* false if hashing is enabled.
+	//
+	// which did not allow reading the value.
+	HomomorphicHashDisabled() (bool, error)
 }
 
 const (