2024-02-02 07:25:04 +00:00
|
|
|
package initialize
|
2021-07-20 12:08:47 +00:00
|
|
|
|
|
|
|
import (
|
2024-02-02 12:36:14 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
2021-07-20 12:08:47 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
2022-11-23 14:44:03 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/rolemgmt"
|
2021-07-20 12:08:47 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
|
|
|
)
|
|
|
|
|
2024-02-02 12:36:14 +00:00
|
|
|
func setNotaryAndAlphabetNodes(c *helper.InitializeContext) error {
|
2024-02-01 11:30:59 +00:00
|
|
|
if ok, err := setRolesFinished(c); ok || err != nil {
|
2021-07-20 14:51:45 +00:00
|
|
|
if err == nil {
|
|
|
|
c.Command.Println("Stage 2: already performed.")
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-02-21 11:42:45 +00:00
|
|
|
var pubs []any
|
2021-07-30 11:26:44 +00:00
|
|
|
for _, acc := range c.Accounts {
|
2021-07-20 12:08:47 +00:00
|
|
|
pubs = append(pubs, acc.PrivateKey().PublicKey().Bytes())
|
|
|
|
}
|
|
|
|
|
|
|
|
w := io.NewBufBinWriter()
|
2022-11-23 14:44:03 +00:00
|
|
|
emit.AppCall(w.BinWriter, rolemgmt.Hash, "designateAsRole",
|
2021-07-20 12:08:47 +00:00
|
|
|
callflag.States|callflag.AllowNotify, int64(noderoles.P2PNotary), pubs)
|
2022-11-23 14:44:03 +00:00
|
|
|
emit.AppCall(w.BinWriter, rolemgmt.Hash, "designateAsRole",
|
2021-07-20 12:08:47 +00:00
|
|
|
callflag.States|callflag.AllowNotify, int64(noderoles.NeoFSAlphabet), pubs)
|
|
|
|
|
2024-02-01 11:30:59 +00:00
|
|
|
if err := c.SendCommitteeTx(w.Bytes(), false); err != nil {
|
2021-07-20 12:08:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-02-01 11:30:59 +00:00
|
|
|
return c.AwaitTx()
|
2021-07-20 12:08:47 +00:00
|
|
|
}
|
2021-07-20 14:51:45 +00:00
|
|
|
|
2024-02-02 12:36:14 +00:00
|
|
|
func setRolesFinished(c *helper.InitializeContext) (bool, error) {
|
2021-07-20 14:51:45 +00:00
|
|
|
height, err := c.Client.GetBlockCount()
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
2024-02-02 12:36:14 +00:00
|
|
|
pubs, err := helper.GetDesignatedByRole(c.ReadOnlyInvoker, rolemgmt.Hash, noderoles.NeoFSAlphabet, height)
|
2021-07-20 14:51:45 +00:00
|
|
|
return len(pubs) == len(c.Wallets), err
|
|
|
|
}
|