Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Flag redefined when its not #19778

Closed
1 task done
gluax opened this issue Mar 18, 2024 · 2 comments
Closed
1 task done

[Bug]: Flag redefined when its not #19778

gluax opened this issue Mar 18, 2024 · 2 comments
Labels

Comments

@gluax
Copy link
Contributor

gluax commented Mar 18, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Though it was similar to #2884.

What happened?

We added a staking module to add functionality on top of the default staking functionality.

However, if we don't copy the autocli.go file from the SDK's staking module into our own at runtime, we get a panic about re-defining a flag, which we aren't doing.

panic: historical-info flag redefined: height

goroutine 1 [running]:
github.com/spf13/pflag.(*FlagSet).AddFlag(0xc0015de900, 0xc001a89220)
        github.com/spf13/pflag@v1.0.5/flag.go:848 +0x5ec
github.com/spf13/pflag.(*FlagSet).VarPF(0xc001d4d9d0?, {0x3a683b0, 0xc001f15c58}, {0x2fde4de, 0x6}, {0x0, 0x0}, {0x30fbf98, 0x55})
        github.com/spf13/pflag@v1.0.5/flag.go:831 +0x14f
github.com/spf13/pflag.(*FlagSet).VarP(...)
        github.com/spf13/pflag@v1.0.5/flag.go:837
github.com/spf13/pflag.(*FlagSet).Int64VarP(...)
        github.com/spf13/pflag@v1.0.5/int64.go:46
github.com/spf13/pflag.(*FlagSet).Int64(0x7f7cf474db28?, {0x2fde4de, 0x6}, 0x0, {0x30fbf98, 0x55})
        github.com/spf13/pflag@v1.0.5/int64.go:64 +0x8c
github.com/cosmos/cosmos-sdk/client/flags.AddQueryFlagsToCmd(0xc000bd7600?)
        github.com/cosmos/cosmos-sdk@v0.50.3/client/flags/flags.go:109 +0xe6
cosmossdk.io/client/v2/autocli.(*Builder).BuildQueryMethodCommand(0xc000bd7600, {0x3a9ab60, 0xc0007735a0}, 0xe?)
        cosmossdk.io/client/v2@v2.0.0-beta.1/autocli/query.go:151 +0x3f2
cosmossdk.io/client/v2/autocli.(*Builder).AddQueryServiceCommands(0xc000bd7600, 0x23?, 0xc0025f1c80)
        cosmossdk.io/client/v2@v2.0.0-beta.1/autocli/query.go:89 +0x64a
cosmossdk.io/client/v2/autocli.enhanceQuery(0x2addce0?, {0x2fdffea, 0x7}, 0x7?, 0xc001d4e048?)
        cosmossdk.io/client/v2@v2.0.0-beta.1/autocli/common.go:184 +0x134
cosmossdk.io/client/v2/autocli.(*Builder).enhanceCommandCommon(_, _, _, {{}, 0xc00280f320, 0xc00280f350, {0x3a53cc8, 0xc002988390}, {0x7f7cd0084d00, 0xc0029883a0}, ...}, ...)
        cosmossdk.io/client/v2@v2.0.0-beta.1/autocli/common.go:167 +0x3d9
cosmossdk.io/client/v2/autocli.AppOptions.EnhanceRootCommandWithBuilder({{}, 0xc00280f320, 0xc00280f350, {0x3a53cc8, 0xc002988390}, {0x7f7cd0084d00, 0xc0029883a0}, {0x7f7cd0084d28, 0xc0029883b0}, {0x7f7cd0084d50, ...}, ...}, ...)
        cosmossdk.io/client/v2@v2.0.0-beta.1/autocli/app.go:118 +0x30d
github.com/sedaprotocol/seda-chain/cmd/sedad/cmd.NewRootCmd()
        github.com/sedaprotocol/seda-chain/cmd/sedad/cmd/root.go:170 +0xf68
main.main()
        github.com/sedaprotocol/seda-chain/cmd/sedad/main.go:15 +0x17

I would not expect us to have to copy that autocli.go file into our staking module to avoid this panic for a flag we don't re-define.

I think this is an SDK bug, as I couldn't find a reason for why our code would be causing this.

Cosmos SDK Version

0.50.*

How to reproduce?

You can check out our repo here.
If you remove the file found here.
Then compile with make install or make build that will still work.
But when you try to run the binary sedad --help for instance, the above panic will be shown.

@julienrbrt
Copy link
Member

julienrbrt commented Mar 18, 2024

As soon as you use EnhanceRootCommand, you enable AutoCLI for all modules. This means AutoCLI will create commands and if autocli.go is not present the default behavior is to create flags for each query/transaction argument.

In the case of staking, the height flag clashes with the default sdk height flag, this is why we have it as well as positional parameter.
Imho this isn't a bug. If you wish to disable AutoCLI for that module, you can set it in your autocli.go.

@julienrbrt julienrbrt closed this as not planned Won't fix, can't repro, duplicate, stale Mar 18, 2024
@github-project-automation github-project-automation bot moved this from 📋 Backlog to 🥳 Done in Cosmos-SDK Mar 18, 2024
@gluax
Copy link
Contributor Author

gluax commented Mar 18, 2024

Thanks, we didn't know that!

@tac0turtle tac0turtle removed this from Cosmos-SDK Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants