/
tx.go
205 lines (164 loc) · 5.98 KB
/
tx.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package cli
import (
"encoding/json"
"fmt"
"os"
"strings"
ibctmtypes "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/interchain-security/v5/x/ccv/provider/types"
)
// GetTxCmd returns the transaction commands for this module
func GetTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
cmd.AddCommand(NewAssignConsumerKeyCmd())
cmd.AddCommand(NewSubmitConsumerMisbehaviourCmd())
cmd.AddCommand(NewSubmitConsumerDoubleVotingCmd())
return cmd
}
func NewAssignConsumerKeyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "assign-consensus-key [consumer-chain-id] [consumer-pubkey]",
Short: "assign a consensus public key to use for a consumer chain",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
signer := clientCtx.GetFromAddress().String()
txf, err := tx.NewFactoryCLI(clientCtx, cmd.Flags())
if err != nil {
return err
}
txf = txf.WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever)
providerValAddr := clientCtx.GetFromAddress()
msg, err := types.NewMsgAssignConsumerKey(args[0], sdk.ValAddress(providerValAddr), args[1], signer)
if err != nil {
return err
}
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
},
}
flags.AddTxFlagsToCmd(cmd)
_ = cmd.MarkFlagRequired(flags.FlagFrom)
return cmd
}
func NewSubmitConsumerMisbehaviourCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "submit-consumer-misbehaviour [misbehaviour]",
Short: "submit an IBC misbehaviour for a consumer chain",
Long: strings.TrimSpace(
fmt.Sprintf(`Submit an IBC misbehaviour detected on a consumer chain.
An IBC misbehaviour contains two conflicting IBC client headers, which are used to form a light client attack evidence.
The misbehaviour type definition can be found in the IBC client messages, see ibc-go/proto/ibc/core/client/v1/tx.proto.
Example:
%s tx provider submit-consumer-misbehaviour [path/to/misbehaviour.json] --from node0 --home ../node0 --chain-id $CID
`, version.AppName)),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
txf, err := tx.NewFactoryCLI(clientCtx, cmd.Flags())
if err != nil {
return err
}
txf = txf.WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever)
submitter := clientCtx.GetFromAddress()
misbJson, err := os.ReadFile(args[0])
if err != nil {
return err
}
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)
misbehaviour := ibctmtypes.Misbehaviour{}
if err := cdc.UnmarshalJSON(misbJson, &misbehaviour); err != nil {
return fmt.Errorf("misbehaviour unmarshalling failed: %s", err)
}
msg, err := types.NewMsgSubmitConsumerMisbehaviour(submitter, &misbehaviour)
if err != nil {
return err
}
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
},
}
flags.AddTxFlagsToCmd(cmd)
_ = cmd.MarkFlagRequired(flags.FlagFrom)
return cmd
}
func NewSubmitConsumerDoubleVotingCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "submit-consumer-double-voting [evidence] [infraction_header]",
Short: "submit a double voting evidence for a consumer chain",
Long: strings.TrimSpace(
fmt.Sprintf(`Submit a Tendermint duplicate vote evidence detected on a consumer chain with
the IBC light client header for the infraction height.
The DuplicateVoteEvidence type definition can be found in the Tendermint messages,
see cometbft/proto/tendermint/types/evidence.proto and the IBC header
definition can be found in the IBC messages, see ibc-go/proto/ibc/lightclients/tendermint/v1/tendermint.proto.
Example:
%s tx provider submit-consumer-double-voting [path/to/evidence.json] [path/to/infraction_header.json] --from node0 --home ../node0 --chain-id $CID
`, version.AppName)),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
txf, err := tx.NewFactoryCLI(clientCtx, cmd.Flags())
if err != nil {
return err
}
txf = txf.WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever)
submitter := clientCtx.GetFromAddress()
ev := tmproto.DuplicateVoteEvidence{}
evidenceJson, err := os.ReadFile(args[0])
if err != nil {
return err
}
if err := json.Unmarshal(evidenceJson, &ev); err != nil {
return fmt.Errorf("duplicate vote evidence unmarshalling failed: %s", err)
}
headerJson, err := os.ReadFile(args[1])
if err != nil {
return err
}
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)
header := ibctmtypes.Header{}
if err := cdc.UnmarshalJSON(headerJson, &header); err != nil {
return fmt.Errorf("infraction IBC header unmarshalling failed: %s", err)
}
msg, err := types.NewMsgSubmitConsumerDoubleVoting(submitter, &ev, &header)
if err != nil {
return err
}
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
},
}
flags.AddTxFlagsToCmd(cmd)
_ = cmd.MarkFlagRequired(flags.FlagFrom)
return cmd
}