forked from TrueCloudLab/frostfs-node
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package morph
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
util2 "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util"
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
func forceNewEpochCmd(cmd *cobra.Command, _ []string) error {
|
|
wCtx, err := util2.NewInitializeContext(cmd, viper.GetViper())
|
|
if err != nil {
|
|
return fmt.Errorf("can't to initialize context: %w", err)
|
|
}
|
|
|
|
r := management.NewReader(wCtx.ReadOnlyInvoker)
|
|
cs, err := r.GetContractByID(1)
|
|
if err != nil {
|
|
return fmt.Errorf("can't get NNS contract info: %w", err)
|
|
}
|
|
|
|
nmHash, err := util2.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util2.DomainOf(util2.NetmapContract))
|
|
if err != nil {
|
|
return fmt.Errorf("can't get netmap contract hash: %w", err)
|
|
}
|
|
|
|
bw := io.NewBufBinWriter()
|
|
if err := util2.EmitNewEpochCall(bw, wCtx, nmHash); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err = wCtx.SendConsensusTx(bw.Bytes()); err == nil {
|
|
err = wCtx.AwaitTx()
|
|
}
|
|
if err != nil && strings.Contains(err.Error(), "invalid epoch") {
|
|
cmd.Println("Epoch has already ticked.")
|
|
return nil
|
|
}
|
|
return err
|
|
}
|