forked from TrueCloudLab/frostfs-node
[#932] adm: Move force-new-epoch
to package netmap
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
ce42547980
commit
9b65f1595a
4 changed files with 33 additions and 31 deletions
44
cmd/frostfs-adm/internal/modules/morph/netmap/epoch.go
Normal file
44
cmd/frostfs-adm/internal/modules/morph/netmap/epoch.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package netmap
|
||||
|
||||
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
|
||||
}
|
|
@ -6,20 +6,38 @@ import (
|
|||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var CandidatesCmd = &cobra.Command{
|
||||
Use: "netmap-candidates",
|
||||
Short: "List netmap candidates nodes",
|
||||
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||
_ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag))
|
||||
_ = viper.BindPFlag(util.AlphabetWalletsFlag, cmd.Flags().Lookup(util.AlphabetWalletsFlag))
|
||||
},
|
||||
Run: listNetmapCandidatesNodes,
|
||||
}
|
||||
var (
|
||||
CandidatesCmd = &cobra.Command{
|
||||
Use: "netmap-candidates",
|
||||
Short: "List netmap candidates nodes",
|
||||
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||
_ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag))
|
||||
_ = viper.BindPFlag(util.AlphabetWalletsFlag, cmd.Flags().Lookup(util.AlphabetWalletsFlag))
|
||||
},
|
||||
Run: listNetmapCandidatesNodes,
|
||||
}
|
||||
ForceNewEpoch = &cobra.Command{
|
||||
Use: "force-new-epoch",
|
||||
Short: "Create new FrostFS epoch event in the side chain",
|
||||
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||
_ = viper.BindPFlag(util.AlphabetWalletsFlag, cmd.Flags().Lookup(util.AlphabetWalletsFlag))
|
||||
_ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag))
|
||||
},
|
||||
RunE: ForceNewEpochCmd,
|
||||
}
|
||||
)
|
||||
|
||||
func initNetmapCandidatesCmd() {
|
||||
CandidatesCmd.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc)
|
||||
}
|
||||
|
||||
func initForceNewEpochCmd() {
|
||||
ForceNewEpoch.Flags().String(util.AlphabetWalletsFlag, "", util.AlphabetWalletsFlagDesc)
|
||||
ForceNewEpoch.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc)
|
||||
ForceNewEpoch.Flags().String(util.LocalDumpFlag, "", "Path to the blocks dump file")
|
||||
}
|
||||
|
||||
func init() {
|
||||
initNetmapCandidatesCmd()
|
||||
initForceNewEpochCmd()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue