From 2f04ce2f7946d1bcafe0280488f42806f106df8c Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 15 May 2024 16:04:01 +0300 Subject: [PATCH] [#1138] adm: Parallelize `generate-alphabet` command This is the longest test in our suite, try to help CI a bit. Before: ``` $ go test -run=TestGenerateAlphabet -count=10 . ok git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/generate 45.400s ``` After: ``` $ go test -run=TestGenerateAlphabet -count=10 . ok git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/generate 33.267s ``` Signed-off-by: Evgenii Stratonikov --- .../modules/morph/generate/generate.go | 46 +++++++++++-------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/cmd/frostfs-adm/internal/modules/morph/generate/generate.go b/cmd/frostfs-adm/internal/modules/morph/generate/generate.go index 8ecc9f1b..c7de599e 100644 --- a/cmd/frostfs-adm/internal/modules/morph/generate/generate.go +++ b/cmd/frostfs-adm/internal/modules/morph/generate/generate.go @@ -65,34 +65,42 @@ func initializeWallets(v *viper.Viper, walletDir string, size int) ([]string, er pubs := make(keys.PublicKeys, size) passwords := make([]string, size) + var errG errgroup.Group + for i := range wallets { password, err := config.GetPassword(v, innerring.GlagoliticLetter(i).String()) if err != nil { return nil, fmt.Errorf("can't fetch password: %w", err) } - p := filepath.Join(walletDir, innerring.GlagoliticLetter(i).String()+".json") - f, err := os.OpenFile(p, os.O_CREATE, 0o644) - if err != nil { - return nil, fmt.Errorf("can't create wallet file: %w", err) - } - if err := f.Close(); err != nil { - return nil, fmt.Errorf("can't close wallet file: %w", err) - } - w, err := wallet.NewWallet(p) - if err != nil { - return nil, fmt.Errorf("can't create wallet: %w", err) - } - if err := w.CreateAccount(constants.SingleAccountName, password); err != nil { - return nil, fmt.Errorf("can't create account: %w", err) - } + i := i + errG.Go(func() error { + p := filepath.Join(walletDir, innerring.GlagoliticLetter(i).String()+".json") + f, err := os.OpenFile(p, os.O_CREATE, 0o644) + if err != nil { + return fmt.Errorf("can't create wallet file: %w", err) + } + if err := f.Close(); err != nil { + return fmt.Errorf("can't close wallet file: %w", err) + } + w, err := wallet.NewWallet(p) + if err != nil { + return fmt.Errorf("can't create wallet: %w", err) + } + if err := w.CreateAccount(constants.SingleAccountName, password); err != nil { + return fmt.Errorf("can't create account: %w", err) + } - passwords[i] = password - wallets[i] = w - pubs[i] = w.Accounts[0].PrivateKey().PublicKey() + passwords[i] = password + wallets[i] = w + pubs[i] = w.Accounts[0].PrivateKey().PublicKey() + return nil + }) } - var errG errgroup.Group + if err := errG.Wait(); err != nil { + return nil, err + } // Create committee account with N/2+1 multi-signature. majCount := smartcontract.GetMajorityHonestNodeCount(size)