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-01 06:43:51 +00:00
|
|
|
util2 "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-01 12:21:51 +00:00
|
|
|
wCtx, err := util2.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-01 07:06:05 +00:00
|
|
|
nmHash, err := util2.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util2.DomainOf(util2.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-01 14:53:00 +00:00
|
|
|
if err := util2.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
|
|
|
}
|