adm: Refactor helper in part of reading alphabet wallets #1203

Merged
fyrchik merged 2 commits from acid-ant/frostfs-node:bugfix/morph-print-alphabet into master 2024-07-01 06:56:05 +00:00
3 changed files with 37 additions and 28 deletions

View file

@ -56,7 +56,8 @@ credentials: # passwords for consensus node / alphabet wallets
#### Network deployment #### Network deployment
- `generate-alphabet` generates a set of wallets for consensus and - `generate-alphabet` generates a set of wallets for consensus and
Alphabet nodes. Alphabet nodes. The list of the name for alphabet wallets(no gaps between names allowed, order is important):
- az, buky, vedi, glagoli, dobro, yest, zhivete, dzelo, zemlja, izhe, izhei, gerv, kako, ljudi, mislete, nash, on, pokoj, rtsi, slovo, tverdo, uk
- `init` initializes the sidechain by deploying smart contracts and - `init` initializes the sidechain by deploying smart contracts and
setting provided FrostFS network configuration. setting provided FrostFS network configuration.

View file

@ -64,6 +64,11 @@ alphabet-wallets: /home/user/deploy/alphabet-wallets
wallet[0]: hunter2 wallet[0]: hunter2
``` ```
This command generates wallets with the following names:
- az, buky, vedi, glagoli, dobro, yest, zhivete, dzelo, zemlja, izhe, izhei, gerv, kako, ljudi, mislete, nash, on, pokoj, rtsi, slovo, tverdo, uk
No gaps between names allowed, order is important.
Do not lose wallet files and network config. Store it in an encrypted backed up Do not lose wallet files and network config. Store it in an encrypted backed up
storage. storage.

View file

@ -40,45 +40,48 @@ func openAlphabetWallets(v *viper.Viper, walletDir string) ([]*wallet.Wallet, er
return nil, fmt.Errorf("can't read alphabet wallets dir: %w", err) return nil, fmt.Errorf("can't read alphabet wallets dir: %w", err)
} }
var size int var wallets []*wallet.Wallet
loop: var letter string
for i := 0; i < len(walletFiles); i++ { for i := 0; i < constants.MaxAlphabetNodes; i++ {

I don't understand the purpose of IterateGlagoliticLetters, what is wrong with a simple for loop?

I don't understand the purpose of `IterateGlagoliticLetters`, what is wrong with a simple for loop?

Are we ok to make lastLetterNum public?

Are we ok to make [lastLetterNum](https://git.frostfs.info/TrueCloudLab/frostfs-node/src/commit/a0e5fc733e412beb674f38d4b5994e443e63c937/pkg/innerring/alphabet.go#L52) public?

Do we need to? We already have a 23-node restriction anyway #352

Do we need to? We already have a 23-node restriction anyway #352

For the case of required wallets for operation - no, we can use MaxAlphabetNodes.
For the case of printing all alphabet letters - yes.

For the case of required wallets for operation - no, we can use [MaxAlphabetNodes](https://git.frostfs.info/TrueCloudLab/frostfs-node/src/commit/af57d5a6a12f1be58c836e079ff3fc73acca39b3/cmd/frostfs-adm/internal/modules/morph/constants/const.go#L9). For the case of printing all alphabet letters - yes.

@fyrchik updated, please review.

@fyrchik updated, please review.

Regarding printing -- the command has static output, how about mentioning all names in the documentation?

Regarding printing -- the command has static output, how about mentioning all names in the documentation?

Updated doc a bit.

Updated doc a bit.
name := innerring.GlagoliticLetter(i).String() + ".json" letter = innerring.GlagoliticLetter(i).String()
for j := range walletFiles { p := filepath.Join(walletDir, letter+".json")
if walletFiles[j].Name() == name { var w *wallet.Wallet
size++ w, err = wallet.NewWalletFromFile(p)
continue loop if err != nil {
} if errors.Is(err, os.ErrNotExist) {
err = nil
} else {
err = fmt.Errorf("can't open wallet: %w", err)
} }
break break
} }
if size == 0 {
return nil, errors.New("alphabet wallets dir is empty (run `generate-alphabet` command first)")
}
wallets := make([]*wallet.Wallet, size) var password string
for i := 0; i < size; i++ { password, err = config.GetPassword(v, letter)
letter := innerring.GlagoliticLetter(i).String()
p := filepath.Join(walletDir, letter+".json")
w, err := wallet.NewWalletFromFile(p)
if err != nil { if err != nil {
return nil, fmt.Errorf("can't open wallet: %w", err) err = fmt.Errorf("can't fetch password: %w", err)
} break
password, err := config.GetPassword(v, letter)
if err != nil {
return nil, fmt.Errorf("can't fetch password: %w", err)
} }
for i := range w.Accounts { for i := range w.Accounts {
if err := w.Accounts[i].Decrypt(password, keys.NEP2ScryptParams()); err != nil { if err = w.Accounts[i].Decrypt(password, keys.NEP2ScryptParams()); err != nil {
return nil, fmt.Errorf("can't unlock wallet: %w", err) err = fmt.Errorf("can't unlock wallet: %w", err)
break
} }
} }
wallets[i] = w wallets = append(wallets, w)
}
if err != nil {
return nil, fmt.Errorf("can't read wallet for letter '%s': %w", letter, err)
}
if len(wallets) == 0 {
err = errors.New("there are no alphabet wallets in dir (run `generate-alphabet` command first)")
if len(walletFiles) > 0 {
err = fmt.Errorf("use glagolitic names for wallets(run `print-alphabet`): %w", err)
}
return nil, err
} }
return wallets, nil return wallets, nil
} }