/
debug.go
125 lines (109 loc) · 3.22 KB
/
debug.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package cli
import (
"fmt"
"strings"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/okex/exchain/x/debug/types"
"github.com/spf13/cobra"
)
// GetDebugCmd returns the cli query commands for this module
func GetDebugCmd(cdc *codec.Codec) *cobra.Command {
queryRoute := types.ModuleName
queryCmd := &cobra.Command{
Use: "debug",
Short: "Debugging subcommands",
}
queryCmd.AddCommand(client.GetCommands(
CmdSetLogLevel(queryRoute, cdc),
CmdDumpStore(queryRoute, cdc),
CmdSanityCheck(queryRoute, cdc),
CmdInvariantCheck(queryRoute, cdc),
)...)
return queryCmd
}
// CmdDumpStore implements the query params command.
func CmdDumpStore(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "dump [module]",
Args: cobra.ExactArgs(1),
Short: "Dump the data of kv-stores by a module name",
RunE: func(cmd *cobra.Command, args []string) error {
module := "all"
if len(args) == 1 {
module = args[0]
}
cliCtx := context.NewCLIContext().WithCodec(cdc)
bz, err := cdc.MarshalJSON(types.DumpInfoParams{Module: module})
if err != nil {
return err
}
res, _, err := cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/%s", queryRoute, types.DumpStore), bz)
if err != nil {
return err
}
fmt.Println(string(res))
return nil
},
}
}
// CmdSetLogLevel sets log level dynamically
func CmdSetLogLevel(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "set-loglevel",
Args: cobra.ExactArgs(1),
Short: "Set the exchaind log level",
Long: strings.TrimSpace(`
$ exchaincli debug set-loglevel "main:info,state:info"
$ exchaincli debug set-loglevel "upgrade:error"
`),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
if len(args) > 1 {
return fmt.Errorf("wrong number of arguments for set-loglevel")
}
if _, _, err := cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/%s/%s", queryRoute, types.SetLogLevel, args[0]), nil); err != nil {
return err
}
fmt.Println("Succeed to set the exchaind log level.")
return nil
},
}
}
// CmdSanityCheck does sanity check
func CmdSanityCheck(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "sanity-check-shares",
Short: "check the total share of validator",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
res, _, err := cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/%s", queryRoute, types.SanityCheckShares), nil)
if err != nil {
return err
}
fmt.Println(string(res))
return nil
},
}
}
// CmdInvariantCheck does invariants check
func CmdInvariantCheck(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "invariant-check",
Short: "check the invariant of all module",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
res, _, err := cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/%s", queryRoute, types.InvariantCheck), nil)
if err != nil {
return err
}
fmt.Println(string(res))
return nil
},
}
}