From cae50ecb21e91e32143ee5da65069430ed8ddfd4 Mon Sep 17 00:00:00 2001 From: Alexander Chuprov Date: Thu, 2 Nov 2023 16:20:37 +0300 Subject: [PATCH] [#716] adm: Add dump policy Signed-off-by: Alexander Chuprov --- .../internal/modules/morph/policy.go | 33 +++++++++++++++++++ .../internal/modules/morph/root.go | 15 +++++++++ 2 files changed, 48 insertions(+) diff --git a/cmd/frostfs-adm/internal/modules/morph/policy.go b/cmd/frostfs-adm/internal/modules/morph/policy.go index 0703ebc2d..005a02711 100644 --- a/cmd/frostfs-adm/internal/modules/morph/policy.go +++ b/cmd/frostfs-adm/internal/modules/morph/policy.go @@ -1,11 +1,15 @@ package morph import ( + "bytes" "fmt" "strconv" "strings" + "text/tabwriter" + commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common" "github.com/nspcc-dev/neo-go/pkg/io" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker" "github.com/nspcc-dev/neo-go/pkg/rpcclient/policy" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/vm/emit" @@ -52,3 +56,32 @@ func setPolicyCmd(cmd *cobra.Command, args []string) error { return wCtx.awaitTx() } + +func dumpPolicyCmd(cmd *cobra.Command, _ []string) error { + c, err := getN3Client(viper.GetViper()) + commonCmd.ExitOnErr(cmd, "can't create N3 client:", err) + + inv := invoker.New(c, nil) + policyContract := policy.NewReader(inv) + + execFee, err := policyContract.GetExecFeeFactor() + commonCmd.ExitOnErr(cmd, "can't get execution fee factor:", err) + + feePerByte, err := policyContract.GetFeePerByte() + commonCmd.ExitOnErr(cmd, "can't get fee per byte:", err) + + storagePrice, err := policyContract.GetStoragePrice() + commonCmd.ExitOnErr(cmd, "can't get storage price:", err) + + buf := bytes.NewBuffer(nil) + tw := tabwriter.NewWriter(buf, 0, 2, 2, ' ', 0) + + _, _ = tw.Write([]byte(fmt.Sprintf("Execution Fee Factor:\t%d (int)\n", execFee))) + _, _ = tw.Write([]byte(fmt.Sprintf("Fee Per Byte:\t%d (int)\n", feePerByte))) + _, _ = tw.Write([]byte(fmt.Sprintf("Storage Price:\t%d (int)\n", storagePrice))) + + _ = tw.Flush() + cmd.Print(buf.String()) + + return nil +} diff --git a/cmd/frostfs-adm/internal/modules/morph/root.go b/cmd/frostfs-adm/internal/modules/morph/root.go index 133d5162f..707ae733d 100644 --- a/cmd/frostfs-adm/internal/modules/morph/root.go +++ b/cmd/frostfs-adm/internal/modules/morph/root.go @@ -146,6 +146,15 @@ var ( }, } + dumpPolicy = &cobra.Command{ + Use: "dump-policy", + Short: "Dump FrostFS policy", + PreRun: func(cmd *cobra.Command, _ []string) { + _ = viper.BindPFlag(endpointFlag, cmd.Flags().Lookup(endpointFlag)) + }, + RunE: dumpPolicyCmd, + } + dumpContractHashesCmd = &cobra.Command{ Use: "dump-hashes", Short: "Dump deployed contract hashes", @@ -239,6 +248,7 @@ func init() { initForceNewEpochCmd() initRemoveNodesCmd() initSetPolicyCmd() + initDumpPolicyCmd() initDumpContractHashesCmd() initDumpNetworkConfigCmd() initSetConfigCmd() @@ -341,6 +351,11 @@ func initSetPolicyCmd() { setPolicy.Flags().String(localDumpFlag, "", "Path to the blocks dump file") } +func initDumpPolicyCmd() { + RootCmd.AddCommand(dumpPolicy) + dumpPolicy.Flags().StringP(endpointFlag, "r", "", "N3 RPC node endpoint") +} + func initRemoveNodesCmd() { RootCmd.AddCommand(removeNodes) removeNodes.Flags().String(alphabetWalletsFlag, "", "Path to alphabet wallets dir")