forked from TrueCloudLab/frostfs-node
[#936] ir: Do not require number of Alphabet contracts to be set
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
b492201a84
commit
6cab1635d4
2 changed files with 17 additions and 2 deletions
|
@ -64,8 +64,6 @@ func defaultConfiguration(cfg *viper.Viper) {
|
|||
cfg.SetDefault("contracts.proxy", "")
|
||||
cfg.SetDefault("contracts.processing", "")
|
||||
cfg.SetDefault("contracts.reputation", "")
|
||||
// alphabet contracts
|
||||
cfg.SetDefault("contracts.alphabet.amount", 7)
|
||||
|
||||
cfg.SetDefault("timers.epoch", "0")
|
||||
cfg.SetDefault("timers.emit", "0")
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package innerring
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
|
@ -87,18 +88,34 @@ func parseAlphabetContracts(cfg *viper.Viper, morph *client.Client) (alphabetCon
|
|||
return nil, fmt.Errorf("amount of alphabet contracts overflows glagolitsa %d > %d", num, lastLetterNum)
|
||||
}
|
||||
|
||||
thresholdIsSet := num != 0
|
||||
|
||||
if !thresholdIsSet {
|
||||
// try to read maximum alphabet contracts
|
||||
// if threshold has not been set manually
|
||||
num = lastLetterNum
|
||||
}
|
||||
|
||||
for letter := az; letter < num; letter++ {
|
||||
contractHash, err := parseContract(cfg, morph,
|
||||
"contracts.alphabet."+letter.String(),
|
||||
client.NNSAlphabetContractName(int(letter)),
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, client.ErrNNSRecordNotFound) {
|
||||
break
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("invalid alphabet %s contract: %w", letter, err)
|
||||
}
|
||||
|
||||
alpha.set(letter, contractHash)
|
||||
}
|
||||
|
||||
if thresholdIsSet && len(alpha) != int(num) {
|
||||
return nil, fmt.Errorf("could not read all contracts: required %d, read %d", num, len(alpha))
|
||||
}
|
||||
|
||||
return alpha, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue