[#1065] adm: Add support EC parameters
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
parent
0290f86579
commit
17f7adb640
9 changed files with 43 additions and 6 deletions
|
@ -60,7 +60,8 @@ func dumpNetworkConfig(cmd *cobra.Command, _ []string) error {
|
|||
switch k {
|
||||
case netmap.ContainerFeeConfig, netmap.ContainerAliasFeeConfig,
|
||||
netmap.EpochDurationConfig, netmap.IrCandidateFeeConfig,
|
||||
netmap.MaxObjectSizeConfig, netmap.WithdrawFeeConfig:
|
||||
netmap.MaxObjectSizeConfig, netmap.WithdrawFeeConfig,
|
||||
netmap.MaxECDataCountConfig, netmap.MaxECParityCountConfig:
|
||||
nbuf := make([]byte, 8)
|
||||
copy(nbuf[:], v)
|
||||
n := binary.LittleEndian.Uint64(nbuf)
|
||||
|
@ -103,10 +104,8 @@ func SetConfigCmd(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
|
||||
forceFlag, _ := cmd.Flags().GetBool(forceConfigSet)
|
||||
|
||||
bw := io.NewBufBinWriter()
|
||||
prm := make(map[string]any)
|
||||
|
||||
for _, arg := range args {
|
||||
k, v, err := parseConfigPair(arg, forceFlag)
|
||||
if err != nil {
|
||||
|
@ -116,7 +115,7 @@ func SetConfigCmd(cmd *cobra.Command, args []string) error {
|
|||
prm[k] = v
|
||||
}
|
||||
|
||||
if err := validateConfig(prm); err != nil {
|
||||
if err := validateConfig(prm, forceFlag); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -138,12 +137,29 @@ func SetConfigCmd(cmd *cobra.Command, args []string) error {
|
|||
return wCtx.AwaitTx()
|
||||
}
|
||||
|
||||
func validateConfig(args map[string]any) error {
|
||||
func validateConfig(args map[string]any, forceFlag bool) error {
|
||||
var sumEC int64
|
||||
_, okData := args[netmap.MaxECDataCountConfig]
|
||||
_, okParity := args[netmap.MaxECParityCountConfig]
|
||||
if okData != okParity {
|
||||
return fmt.Errorf("both %s and %s must be present in the configuration",
|
||||
netmap.MaxECDataCountConfig, netmap.MaxECParityCountConfig)
|
||||
}
|
||||
|
||||
for k, v := range args {
|
||||
value, ok := v.(int64)
|
||||
if !ok || value < 0 {
|
||||
return fmt.Errorf("%s must be >= 0, got %v", k, v)
|
||||
}
|
||||
|
||||
if k == netmap.MaxECDataCountConfig || k == netmap.MaxECParityCountConfig {
|
||||
sumEC += value
|
||||
}
|
||||
}
|
||||
|
||||
if sumEC > 256 && !forceFlag {
|
||||
return fmt.Errorf("the sum of %s and %s must be <= 256, got %d",
|
||||
netmap.MaxECDataCountConfig, netmap.MaxECParityCountConfig, sumEC)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -160,7 +176,8 @@ func parseConfigPair(kvStr string, force bool) (key string, val any, err error)
|
|||
switch key {
|
||||
case netmap.ContainerFeeConfig, netmap.ContainerAliasFeeConfig,
|
||||
netmap.EpochDurationConfig, netmap.IrCandidateFeeConfig,
|
||||
netmap.MaxObjectSizeConfig, netmap.WithdrawFeeConfig:
|
||||
netmap.MaxObjectSizeConfig, netmap.WithdrawFeeConfig,
|
||||
netmap.MaxECDataCountConfig, netmap.MaxECParityCountConfig:
|
||||
val, err = strconv.ParseInt(valRaw, 10, 64)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("could not parse %s's value '%s' as int: %w", key, valRaw, err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue