2024-02-01 14:53:00 +00:00
|
|
|
package node
|
2022-06-27 14:47:13 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
netmapcontract "git.frostfs.info/TrueCloudLab/frostfs-contract/netmap"
|
2024-02-02 12:26:57 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
2024-02-02 12:36:14 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
2022-06-27 14:47:13 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
2023-10-24 10:06:30 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
2022-06-27 14:47:13 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
2024-02-01 14:53:00 +00:00
|
|
|
func RemoveNodesCmd(cmd *cobra.Command, args []string) error {
|
2022-06-27 14:47:13 +00:00
|
|
|
if len(args) == 0 {
|
|
|
|
return errors.New("at least one node key must be provided")
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeKeys := make(keys.PublicKeys, len(args))
|
|
|
|
for i := range args {
|
|
|
|
var err error
|
|
|
|
nodeKeys[i], err = keys.NewPublicKeyFromString(args[i])
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("can't parse node public key: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-02 12:36:14 +00:00
|
|
|
wCtx, err := helper.NewInitializeContext(cmd, viper.GetViper())
|
2022-06-27 14:47:13 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("can't initialize context: %w", err)
|
|
|
|
}
|
2024-02-01 11:30:59 +00:00
|
|
|
defer wCtx.Close()
|
2022-06-27 14:47:13 +00:00
|
|
|
|
2023-10-24 10:06:30 +00:00
|
|
|
r := management.NewReader(wCtx.ReadOnlyInvoker)
|
|
|
|
cs, err := r.GetContractByID(1)
|
2022-06-27 14:47:13 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("can't get NNS contract info: %w", err)
|
|
|
|
}
|
|
|
|
|
2024-02-02 12:36:14 +00:00
|
|
|
nmHash, err := helper.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, helper.DomainOf(constants.NetmapContract))
|
2022-06-27 14:47:13 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("can't get netmap contract hash: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
bw := io.NewBufBinWriter()
|
|
|
|
for i := range nodeKeys {
|
|
|
|
emit.AppCall(bw.BinWriter, nmHash, "updateStateIR", callflag.All,
|
2022-09-28 11:34:28 +00:00
|
|
|
int64(netmapcontract.NodeStateOffline), nodeKeys[i].Bytes())
|
2022-06-27 14:47:13 +00:00
|
|
|
}
|
|
|
|
|
2024-02-02 12:36:14 +00:00
|
|
|
if err := helper.EmitNewEpochCall(bw, wCtx, nmHash); err != nil {
|
2022-06-27 14:47:13 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-02-01 11:30:59 +00:00
|
|
|
if err := wCtx.SendConsensusTx(bw.Bytes()); err != nil {
|
2022-06-27 14:47:13 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-02-01 11:30:59 +00:00
|
|
|
return wCtx.AwaitTx()
|
2022-06-27 14:47:13 +00:00
|
|
|
}
|