Skip to content

Commit 73bedad

Browse files
authored
fix(client/v2): add fallbacks when incorrect protos (#24449)
1 parent 6a1ec1b commit 73bedad

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

client/v2/autocli/app.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,18 @@ type AppOptions struct {
6262
// rootCmd := initRootCmd()
6363
// err = autoCliOpts.EnhanceRootCommand(rootCmd)
6464
func (appOptions AppOptions) EnhanceRootCommand(rootCmd *cobra.Command) error {
65-
mergedFiles, err := proto.MergedRegistry()
65+
var (
66+
mergedFiles flag.FileResolver
67+
err error
68+
)
69+
70+
mergedFiles, err = proto.MergedRegistry()
6671
if err != nil {
67-
return err
72+
// we can safely ignore this error, as this should have been called somewhere earlier
73+
// in the app's lifecycle.
74+
mergedFiles = appOptions.ClientCtx.InterfaceRegistry
6875
}
76+
6977
builder := &Builder{
7078
Builder: flag.Builder{
7179
TypeResolver: protoregistry.GlobalTypes,

client/v2/autocli/flag/builder.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,21 @@ const (
3232
DecScalarType = "cosmos.Dec"
3333
)
3434

35+
// FileResolver specifies how protobuf file descriptors will be resolved.
36+
type FileResolver interface {
37+
protodesc.Resolver
38+
RangeFiles(func(protoreflect.FileDescriptor) bool)
39+
}
40+
3541
// Builder manages options for building pflag flags for protobuf messages.
3642
type Builder struct {
37-
// TypeResolver specifies how protobuf types will be resolved. If it is
38-
// nil protoregistry.GlobalTypes will be used.
43+
// TypeResolver specifies how protobuf types will be resolved.
3944
TypeResolver interface {
4045
protoregistry.MessageTypeResolver
4146
protoregistry.ExtensionTypeResolver
4247
}
4348

44-
// FileResolver specifies how protobuf file descriptors will be resolved. If it is
45-
// nil protoregistry.GlobalFiles will be used.
49+
// FileResolver specifies how protobuf file descriptors will be resolved.
4650
FileResolver interface {
4751
protodesc.Resolver
4852
RangeFiles(func(protoreflect.FileDescriptor) bool)
@@ -300,7 +304,7 @@ func (b *Builder) addFlattenFieldBindingToArgs(ctx *context.Context, path string
300304
func (b *Builder) addFieldBindingToArgs(ctx *context.Context, messageBinder *MessageBinder, name protoreflect.Name, fields protoreflect.FieldDescriptors) (fieldBinding, error) {
301305
field := fields.ByName(name)
302306
if field == nil {
303-
return fieldBinding{}, fmt.Errorf("can't find field %s", name) // TODO: it will improve error if msg.FullName() was included.`
307+
return fieldBinding{}, fmt.Errorf("can't find field %s in %s", name, messageBinder.messageType.Descriptor().FullName())
304308
}
305309

306310
_, hasValue, err := b.addFieldFlag(

x/crisis/autocli.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package crisis
22

33
import (
4-
"fmt"
5-
64
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
75
crisisv1beta1 "cosmossdk.io/api/cosmos/crisis/v1beta1"
8-
"github.com/cosmos/cosmos-sdk/version"
96
)
107

118
// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface.
@@ -24,12 +21,8 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
2421
},
2522
},
2623
{
27-
RpcMethod: "UpdateParams",
28-
Use: "update-params-proposal [params]",
29-
Short: "Submit a proposal to update crisis module params. Note: the entire params must be provided.",
30-
Example: fmt.Sprintf(`%s tx crisis update-params-proposal '{ "constant_fee": {"denom": "stake", "amount": "1000"} }'`, version.AppName),
31-
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "params"}},
32-
GovProposal: true,
24+
RpcMethod: "UpdateParams",
25+
Skip: true, // Crisis is deprecated.
3326
},
3427
},
3528
},

x/gov/client/cli/util.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func AddGovPropFlagsToCmd(cmd *cobra.Command) {
131131
cmd.Flags().String(FlagMetadata, "", "The metadata to include with the governance proposal")
132132
cmd.Flags().String(FlagTitle, "", "The title to put on the governance proposal")
133133
cmd.Flags().String(FlagSummary, "", "The summary to include with the governance proposal")
134-
cmd.Flags().Bool(FlagExpedited, false, "Whether to expedite the governance proposal")
134+
// cmd.Flags().Bool(FlagExpedited, false, "Whether to expedite the governance proposal") // cannot be enabled because of IBC redefining this flag in `upgrade-channels` command.
135135
}
136136

137137
// ReadGovPropCmdFlags parses a MsgSubmitProposal from the provided context and flags.
@@ -167,10 +167,10 @@ func ReadGovPropCmdFlags(proposer string, flagSet *pflag.FlagSet) (*govv1.MsgSub
167167
return nil, fmt.Errorf("could not read summary: %w", err)
168168
}
169169

170-
rv.Expedited, err = flagSet.GetBool(FlagExpedited)
171-
if err != nil {
172-
return nil, fmt.Errorf("could not read expedited: %w", err)
173-
}
170+
// rv.Expedited, err = flagSet.GetBool(FlagExpedited)
171+
// if err != nil {
172+
// return nil, fmt.Errorf("could not read expedited: %w", err)
173+
// }
174174

175175
rv.Proposer = proposer
176176

0 commit comments

Comments
 (0)