2024-02-01 14:59:53 +00:00
|
|
|
package netmap
|
2021-07-09 09:53:10 +00:00
|
|
|
|
|
|
|
import (
|
2021-07-28 09:21:04 +00:00
|
|
|
"fmt"
|
2023-08-10 12:03:16 +00:00
|
|
|
"strings"
|
2021-07-28 09:21:04 +00:00
|
|
|
|
2024-02-02 11:30:32 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util"
|
2021-07-28 09:21:04 +00:00
|
|
|
"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"
|
2021-07-09 09:53:10 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
2024-02-01 14:59:53 +00:00
|
|
|
func ForceNewEpochCmd(cmd *cobra.Command, _ []string) error {
|
2024-02-02 11:30:32 +00:00
|
|
|
wCtx, err := util.NewInitializeContext(cmd, viper.GetViper())
|
2021-07-28 09:21:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("can't to initialize context: %w", err)
|
|
|
|
}
|
|
|
|
|
2023-10-24 10:06:30 +00:00
|
|
|
r := management.NewReader(wCtx.ReadOnlyInvoker)
|
|
|
|
cs, err := r.GetContractByID(1)
|
2021-07-28 09:21:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("can't get NNS contract info: %w", err)
|
|
|
|
}
|
|
|
|
|
2024-02-02 11:30:32 +00:00
|
|
|
nmHash, err := util.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util.DomainOf(util.NetmapContract))
|
2021-07-28 09:21:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("can't get netmap contract hash: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-06-27 14:47:13 +00:00
|
|
|
bw := io.NewBufBinWriter()
|
2024-02-02 11:30:32 +00:00
|
|
|
if err := util.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 {
|
|
|
|
err = wCtx.AwaitTx()
|
2022-06-27 14:47:13 +00:00
|
|
|
}
|
2024-02-07 16:44:28 +00:00
|
|
|
if err != nil && strings.Contains(err.Error(), "invalid epoch") {
|
|
|
|
cmd.Println("Epoch has already ticked.")
|
|
|
|
return nil
|
2023-08-10 12:03:16 +00:00
|
|
|
}
|
2024-02-07 16:44:28 +00:00
|
|
|
return err
|
2022-06-27 14:47:13 +00:00
|
|
|
}
|