From fe4082799a106a720240f685d3f5c5d84b64fabb Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 5 May 2023 16:44:02 +0300 Subject: [PATCH] [#321] adm: Create multisig accounts in parallel Signed-off-by: Evgenii Stratonikov --- .../internal/modules/morph/generate.go | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/cmd/frostfs-adm/internal/modules/morph/generate.go b/cmd/frostfs-adm/internal/modules/morph/generate.go index e714482dd..8975a6d76 100644 --- a/cmd/frostfs-adm/internal/modules/morph/generate.go +++ b/cmd/frostfs-adm/internal/modules/morph/generate.go @@ -21,6 +21,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/spf13/cobra" "github.com/spf13/viper" + "golang.org/x/sync/errgroup" ) const ( @@ -92,28 +93,30 @@ func initializeWallets(v *viper.Viper, walletDir string, size int) ([]string, er pubs[i] = w.Accounts[0].PrivateKey().PublicKey() } + var errG errgroup.Group + // Create committee account with N/2+1 multi-signature. majCount := smartcontract.GetMajorityHonestNodeCount(size) - for i, w := range wallets { - if err := addMultisigAccount(w, majCount, committeeAccountName, passwords[i], pubs); err != nil { - return nil, fmt.Errorf("can't create committee account: %w", err) - } - } - // Create consensus account with 2*N/3+1 multi-signature. bftCount := smartcontract.GetDefaultHonestNodeCount(size) - for i, w := range wallets { - if err := addMultisigAccount(w, bftCount, consensusAccountName, passwords[i], pubs); err != nil { - return nil, fmt.Errorf("can't create consensus account: %w", err) - } + for i := range wallets { + i := i + errG.Go(func() error { + if err := addMultisigAccount(wallets[i], majCount, committeeAccountName, passwords[i], pubs); err != nil { + return fmt.Errorf("can't create committee account: %w", err) + } + if err := addMultisigAccount(wallets[i], bftCount, consensusAccountName, passwords[i], pubs); err != nil { + return fmt.Errorf("can't create consentus account: %w", err) + } + if err := wallets[i].SavePretty(); err != nil { + return fmt.Errorf("can't save wallet: %w", err) + } + return nil + }) } - - for _, w := range wallets { - if err := w.SavePretty(); err != nil { - return nil, fmt.Errorf("can't save wallet: %w", err) - } + if err := errG.Wait(); err != nil { + return nil, err } - return passwords, nil }