2022-06-27 14:47:13 +00:00
|
|
|
package morph
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
netmapcontract "git.frostfs.info/TrueCloudLab/frostfs-contract/netmap"
|
2024-02-01 06:43:51 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util"
|
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"
|
|
|
|
)
|
|
|
|
|
|
|
|
func removeNodesCmd(cmd *cobra.Command, args []string) error {
|
|
|
|
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-01 11:30:59 +00:00
|
|
|
wCtx, err := 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-01 07:06:05 +00:00
|
|
|
nmHash, err := util.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util.DomainOf(util.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
|
|
|
}
|
|
|
|
|
|
|
|
if err := emitNewEpochCall(bw, wCtx, nmHash); err != nil {
|
|
|
|
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
|
|
|
}
|