Vitaliy Potyarkin
f71418b73c
These error messages bubble up to human users - adding more context helps to find the cause of the issue faster. Signed-off-by: Vitaliy Potyarkin <v.potyarkin@yadro.com>
52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
package initialize
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
|
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/rolemgmt"
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
|
)
|
|
|
|
func setNotaryAndAlphabetNodes(c *helper.InitializeContext) error {
|
|
if ok, err := setRolesFinished(c); ok || err != nil {
|
|
if err == nil {
|
|
c.Command.Println("Stage 2: already performed.")
|
|
}
|
|
return err
|
|
}
|
|
|
|
var pubs []any
|
|
for _, acc := range c.Accounts {
|
|
pubs = append(pubs, acc.PrivateKey().PublicKey().Bytes())
|
|
}
|
|
|
|
w := io.NewBufBinWriter()
|
|
emit.AppCall(w.BinWriter, rolemgmt.Hash, "designateAsRole",
|
|
callflag.States|callflag.AllowNotify, int64(noderoles.P2PNotary), pubs)
|
|
emit.AppCall(w.BinWriter, rolemgmt.Hash, "designateAsRole",
|
|
callflag.States|callflag.AllowNotify, int64(noderoles.NeoFSAlphabet), pubs)
|
|
|
|
if err := c.SendCommitteeTx(w.Bytes(), false); err != nil {
|
|
return fmt.Errorf("send committee transaction: %w", err)
|
|
}
|
|
|
|
err := c.AwaitTx()
|
|
if err != nil {
|
|
err = fmt.Errorf("await committee transaction: %w", err)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func setRolesFinished(c *helper.InitializeContext) (bool, error) {
|
|
height, err := c.Client.GetBlockCount()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
pubs, err := helper.GetDesignatedByRole(c.ReadOnlyInvoker, rolemgmt.Hash, noderoles.NeoFSAlphabet, height)
|
|
return len(pubs) == len(c.Wallets), err
|
|
}
|