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 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"
|
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 12:36:14 +00:00
|
|
|
wCtx, err := helper.NewInitializeContext(cmd, viper.GetViper())
|
2021-07-28 09:21:04 +00:00
|
|
|
if err != nil {
|
2024-07-01 15:58:37 +00:00
|
|
|
return fmt.Errorf("can't initialize context: %w", err)
|
2021-07-28 09:21:04 +00:00
|
|
|
}
|
|
|
|
|
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 12:36:14 +00:00
|
|
|
nmHash, err := helper.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, helper.DomainOf(constants.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 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 {
|
|
|
|
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
|
|
|
}
|