From fa9c910648149a655e4fb2c8e22e734360b9465e Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 29 Apr 2022 20:47:14 +0300 Subject: [PATCH] [#1365] morph: Add `HomomorphicHashDisabled` config getter Signed-off-by: Pavel Karpy --- pkg/morph/client/netmap/config.go | 47 ++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/pkg/morph/client/netmap/config.go b/pkg/morph/client/netmap/config.go index aa4e2565..47a539b7 100644 --- a/pkg/morph/client/netmap/config.go +++ b/pkg/morph/client/netmap/config.go @@ -10,16 +10,17 @@ import ( ) const ( - maxObjectSizeConfig = "MaxObjectSize" - basicIncomeRateConfig = "BasicIncomeRate" - auditFeeConfig = "AuditFee" - epochDurationConfig = "EpochDuration" - containerFeeConfig = "ContainerFee" - containerAliasFeeConfig = "ContainerAliasFee" - etIterationsConfig = "EigenTrustIterations" - etAlphaConfig = "EigenTrustAlpha" - irCandidateFeeConfig = "InnerRingCandidateFee" - withdrawFeeConfig = "WithdrawFee" + maxObjectSizeConfig = "MaxObjectSize" + basicIncomeRateConfig = "BasicIncomeRate" + auditFeeConfig = "AuditFee" + epochDurationConfig = "EpochDuration" + containerFeeConfig = "ContainerFee" + containerAliasFeeConfig = "ContainerAliasFee" + etIterationsConfig = "EigenTrustIterations" + etAlphaConfig = "EigenTrustAlpha" + irCandidateFeeConfig = "InnerRingCandidateFee" + withdrawFeeConfig = "WithdrawFee" + homomorphicHashingDisabledKey = "HomomorphicHashingDisabled" ) // MaxObjectSize receives max object size configuration @@ -109,6 +110,17 @@ func (c *Client) EigenTrustAlpha() (float64, error) { return strconv.ParseFloat(strAlpha, 64) } +// HomomorphicHashDisabled returns global configuration value of homomorphic hashing +// settings. +func (c *Client) HomomorphicHashDisabled() (bool, error) { + hashingDisabled, err := c.readBoolConfig(homomorphicHashingDisabledKey) + if err != nil { + return false, fmt.Errorf("(%T) could not get homomorphic hash state: %w", c, err) + } + + return hashingDisabled, nil +} + // InnerRingCandidateFee returns global configuration value of fee paid by // node to be in inner ring candidates list. func (c *Client) InnerRingCandidateFee() (uint64, error) { @@ -151,6 +163,16 @@ func (c *Client) readStringConfig(key string) (string, error) { return v.(string), nil } +func (c *Client) readBoolConfig(key string) (bool, error) { + v, err := c.config([]byte(key), BoolAssert) + if err != nil { + return false, err + } + + // BoolAssert is guaranteed to return bool if the error is nil. + return v.(bool), nil +} + // SetConfigPrm groups parameters of SetConfig operation. type SetConfigPrm struct { id []byte @@ -328,6 +350,11 @@ func StringAssert(item stackitem.Item) (interface{}, error) { return client.StringFromStackItem(item) } +// BoolAssert converts stack item to bool. +func BoolAssert(item stackitem.Item) (interface{}, error) { + return client.BoolFromStackItem(item) +} + // iterateRecords iterates over all config records and passes them to f. // // Returns f's errors directly.