[#240] netmap: Support HomomorphicHashingDisabled network config

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-06-30 18:44:40 +03:00 committed by LeL
parent df6538c68c
commit 0cd790cfe0
3 changed files with 112 additions and 1 deletions

View file

@ -7,6 +7,7 @@ import (
"fmt"
"math"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
)
@ -74,6 +75,8 @@ func (x *NetworkInfo) readFromV2(m netmap.NetworkInfo, checkFieldPresence bool)
configMaxObjSize,
configWithdrawalFee:
_, err = decodeConfigValueUint64(prm.GetValue())
case configHomomorphicHashingDisabled:
_, err = decodeConfigValueBool(prm.GetValue())
}
if err != nil {
@ -243,7 +246,8 @@ func (x *NetworkInfo) IterateRawNetworkParameters(f func(name string, value []by
configEpochDuration,
configIRCandidateFee,
configMaxObjSize,
configWithdrawalFee:
configWithdrawalFee,
configHomomorphicHashingDisabled:
}
return false
@ -257,6 +261,11 @@ func (x *NetworkInfo) setConfigUint64(name string, num uint64) {
x.setConfig(name, val)
}
func (x *NetworkInfo) setConfigBool(name string, val bool) {
v := stackitem.NewBool(val)
x.setConfig(name, v.Bytes())
}
// decodeConfigValueUint64 parses val as little-endian uint64.
// val must be less than 8 bytes in size.
func decodeConfigValueUint64(val []byte) (uint64, error) {
@ -272,6 +281,18 @@ func decodeConfigValueUint64(val []byte) (uint64, error) {
return res, nil
}
// decodeConfigValueBool parses val as boolean contract storage value.
func decodeConfigValueBool(val []byte) (bool, error) {
arr := stackitem.NewByteArray(val)
res, err := arr.TryBool()
if err != nil {
return false, fmt.Errorf("invalid bool parameter contract format %s", err)
}
return res, nil
}
func (x NetworkInfo) configUint64(name string) uint64 {
val := x.configValue(name)
if val == nil {
@ -288,6 +309,22 @@ func (x NetworkInfo) configUint64(name string) uint64 {
return res
}
func (x NetworkInfo) configBool(name string) bool {
val := x.configValue(name)
if val == nil {
return false
}
res, err := decodeConfigValueBool(val)
if err != nil {
// potential panic is OK since value MUST be correct since it is
// verified in ReadFromV2 or set by provided method.
panic(err)
}
return res
}
const configAuditFee = "AuditFee"
// SetAuditFee sets the configuration value of the audit fee for the Inner Ring.
@ -467,3 +504,21 @@ func (x *NetworkInfo) SetWithdrawalFee(sz uint64) {
func (x NetworkInfo) WithdrawalFee() uint64 {
return x.configUint64(configWithdrawalFee)
}
const configHomomorphicHashingDisabled = "HomomorphicHashingDisabled"
// DisableHomomorphicHashing sets flag requiring to disable homomorphic
// hashing of the containers in the network.
//
// See also HomomorphicHashingDisabled.
func (x *NetworkInfo) DisableHomomorphicHashing() {
x.setConfigBool(configHomomorphicHashingDisabled, true)
}
// HomomorphicHashingDisabled returns the state of the homomorphic
// hashing network setting.
//
// Zero NetworkInfo has enabled homomorphic hashing.
func (x NetworkInfo) HomomorphicHashingDisabled() bool {
return x.configBool(configHomomorphicHashingDisabled)
}