From 9c96c499284bd5997fbe9efceaf8058734ef096e Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 21 Mar 2024 09:57:34 +0300 Subject: [PATCH] [#205] netmap: Add well-known EC parameters to network config Signed-off-by: Evgenii Stratonikov --- netmap/network_info.go | 32 ++++++++++++++++++++++++++++++++ netmap/network_info_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/netmap/network_info.go b/netmap/network_info.go index 186d433..a149bf4 100644 --- a/netmap/network_info.go +++ b/netmap/network_info.go @@ -62,6 +62,8 @@ func (x *NetworkInfo) readFromV2(m netmap.NetworkInfo, checkFieldPresence bool) configEpochDuration, configIRCandidateFee, configMaxObjSize, + configMaxECDataCount, + configMaxECParityCount, configWithdrawalFee: _, err = decodeConfigValueUint64(prm.GetValue()) case configHomomorphicHashingDisabled, @@ -234,6 +236,8 @@ func (x *NetworkInfo) IterateRawNetworkParameters(f func(name string, value []by configEpochDuration, configIRCandidateFee, configMaxObjSize, + configMaxECDataCount, + configMaxECParityCount, configWithdrawalFee, configHomomorphicHashingDisabled, configMaintenanceModeAllowed: @@ -432,6 +436,34 @@ func (x NetworkInfo) MaxObjectSize() uint64 { return x.configUint64(configMaxObjSize) } +const configMaxECDataCount = "MaxECDataCount" + +// SetMaxECDataCount sets maximum number of data shards for erasure codes. +// +// Zero means no restrictions. +func (x *NetworkInfo) SetMaxECDataCount(dataCount uint64) { + x.setConfigUint64(configMaxECDataCount, dataCount) +} + +// MaxECDataCount returns maximum number of data shards for erasure codes. +func (x NetworkInfo) MaxECDataCount() uint64 { + return x.configUint64(configMaxECDataCount) +} + +const configMaxECParityCount = "MaxECParityCount" + +// SetMaxECParityCount sets maximum number of parity shards for erasure codes. +// +// Zero means no restrictions. +func (x *NetworkInfo) SetMaxECParityCount(parityCount uint64) { + x.setConfigUint64(configMaxECParityCount, parityCount) +} + +// MaxECParityCount returns maximum number of parity shards for erasure codes. +func (x NetworkInfo) MaxECParityCount() uint64 { + return x.configUint64(configMaxECParityCount) +} + const configWithdrawalFee = "WithdrawFee" // SetWithdrawalFee sets fee for withdrawals from the FrostFS accounts that diff --git a/netmap/network_info_test.go b/netmap/network_info_test.go index 54b1b30..161d152 100644 --- a/netmap/network_info_test.go +++ b/netmap/network_info_test.go @@ -173,6 +173,32 @@ func TestNetworkInfo_MaxObjectSize(t *testing.T) { ) } +func TestNetworkInfo_MaxECDataCount(t *testing.T) { + testConfigValue(t, + func(x NetworkInfo) any { return x.MaxECDataCount() }, + func(info *NetworkInfo, val any) { info.SetMaxECDataCount(val.(uint64)) }, + uint64(1), uint64(2), + "MaxECDataCount", func(val any) []byte { + data := make([]byte, 8) + binary.LittleEndian.PutUint64(data, val.(uint64)) + return data + }, + ) +} + +func TestNetworkInfo_MaxECParityCount(t *testing.T) { + testConfigValue(t, + func(x NetworkInfo) any { return x.MaxECParityCount() }, + func(info *NetworkInfo, val any) { info.SetMaxECParityCount(val.(uint64)) }, + uint64(1), uint64(2), + "MaxECParityCount", func(val any) []byte { + data := make([]byte, 8) + binary.LittleEndian.PutUint64(data, val.(uint64)) + return data + }, + ) +} + func TestNetworkInfo_WithdrawalFee(t *testing.T) { testConfigValue(t, func(x NetworkInfo) any { return x.WithdrawalFee() },