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

feat: introduce --keyring-dir=... flag #7436

Closed
wants to merge 6 commits into from

Conversation

michaelfig
Copy link
Contributor

@michaelfig michaelfig commented Oct 1, 2020

Description

Since the merger of gaiacli and gaiad, the gentx --home-client=... flag was removed. Unfortunately, this makes it onerous to run a gentx where a file-based client keystore is not in the same directory as the server config.

This PR introduces a --keyring-dir=... flag for all cases that --keyring-backend can be specified. This flag allows for, say, creating a chain config on a remote machine then downloading it to a separate directory and using gentx to add a create-validator transaction to that directory without needing to copy it into the keystore or vice versa.


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • (discussion in the current PR's comments) Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@michaelfig
Copy link
Contributor Author

michaelfig commented Oct 1, 2020

@alexanderbez, this is what I ended up doing to fix my specific use case.

@codecov
Copy link

codecov bot commented Oct 1, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@3e6089d). Click here to learn what that means.
The diff coverage is 86.27%.

@@            Coverage Diff            @@
##             master    #7436   +/-   ##
=========================================
  Coverage          ?   56.27%           
=========================================
  Files             ?      457           
  Lines             ?    27239           
  Branches          ?        0           
=========================================
  Hits              ?    15328           
  Misses            ?    10239           
  Partials          ?     1672           

@michaelfig michaelfig changed the title feat: introduce gentx --home-server=... flag feat: introduce gentx --server-home=... flag Oct 1, 2020
Copy link
Contributor

@alessio alessio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@alessio alessio requested a review from fedekunze October 2, 2020 07:26
x/genutil/client/cli/gentx.go Outdated Show resolved Hide resolved
@michaelfig michaelfig force-pushed the mfig/home-server branch 2 times, most recently from 3c39030 to f5d8ef3 Compare October 2, 2020 20:26
@michaelfig michaelfig changed the title feat: introduce gentx --server-home=... flag feat: introduce gentx --client-home=... flag Oct 2, 2020
@michaelfig michaelfig changed the title feat: introduce gentx --client-home=... flag feat: introduce --client-home=... flag Oct 3, 2020
client/cmd.go Outdated Show resolved Hide resolved
@michaelfig michaelfig changed the title feat: introduce --client-home=... flag feat: introduce --keyring-dir=... flag Oct 6, 2020
CHANGELOG.md Outdated
@@ -2843,7 +2845,7 @@ FEATURES:
* Better key output, pubkey go-amino hex bytes now output by default
* gaiad init overhaul
* Create genesis transactions with `gaiad init gen-tx`
* New genesis account keys are automatically added to the client keybase (introduce `--client-home` flag)
* New genesis account keys are automatically added to the client keybase (introduce `--home-client` flag)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* New genesis account keys are automatically added to the client keybase (introduce `--home-client` flag)
* New genesis account keys are automatically added to the client keybase (introduce `--keyring-dir` flag)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually ancient news and should not be changed. But I accidentally changed it. It should remain --client-home.

client/cmd.go Outdated
@@ -104,9 +104,10 @@ func ReadPersistentCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Cont

if clientCtx.Keyring == nil || flagSet.Changed(flags.FlagKeyringBackend) {
keyringBackend, _ := flagSet.GetString(flags.FlagKeyringBackend)
keyringDir, _ := flags.GetKeyringDir(flagSet, clientCtx.HomeDir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to be a new flag. --home and --keyring-dir can be used together.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah there should be a way to initialise the keyring with a different home directory (when setting a home directory makes sense at all, i.e. keyring-backend = file | test | pass)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to be a new flag. --home and --keyring-dir can be used together.

I don't understand what your critique is. flags.GetKeyringDir uses --keyring-dir (which can be different from --home), and it defaults to the second argument, and missing that, the value of --home.

Did I not implement that correctly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, sorry, I misread this code. But I still find this confusing. See comment on GetKeyringDir.

@michaelfig michaelfig force-pushed the mfig/home-server branch 2 times, most recently from a47e40b to d55f95e Compare October 6, 2020 16:01
@@ -111,6 +114,20 @@ func AddTxFlagsToCmd(cmd *cobra.Command) {
cmd.SetOut(cmd.OutOrStdout())
}

// GetKeyringDir finds the directory for the keyring storage
func GetKeyringDir(pflags *pflag.FlagSet, homeDir string) (string, error) {
keyringDir, err := pflags.GetString(FlagKeyringDir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
keyringDir, err := pflags.GetString(FlagKeyringDir)
keyringDir, _ := pflags.GetString(FlagKeyringDir)

You can ignore the error

client/cmd.go Outdated
@@ -104,9 +104,10 @@ func ReadPersistentCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Cont

if clientCtx.Keyring == nil || flagSet.Changed(flags.FlagKeyringBackend) {
keyringBackend, _ := flagSet.GetString(flags.FlagKeyringBackend)
keyringDir, _ := flags.GetKeyringDir(flagSet, clientCtx.HomeDir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, sorry, I misread this code. But I still find this confusing. See comment on GetKeyringDir.

Comment on lines 120 to 130
if keyringDir == "" {
// Use the specified home directory.
keyringDir = homeDir
}
if keyringDir == "" {
// Default to the node's home directory.
keyringDir, err = pflags.GetString(FlagHome)
}
return keyringDir, err
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit confusing to grok IMHO. We know that when this is called, clientCtx.HomeDir is populated. So really, this method should be a simple if/else.

if keyringDir != "" {
  return keyringDir
}

return homeDir

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I think of it, I'm not even sure we need a function for this -- it's so concise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit confusing to grok IMHO. We know that when this is called, clientCtx.HomeDir is populated. So really, this method should be a simple if/else.

All the gaiad keys ... commands don't have a clientCtx.HomeDir and so need to handle the FlagHome explicitly. I will inline the details in all the appropriate places, though, in the interest of understandability.

client/cmd.go Outdated Show resolved Hide resolved
Comment on lines +29 to +32
keyringDir, _ := cmd.Flags().GetString(flags.FlagKeyringDir)
if keyringDir == "" {
keyringDir, _ = cmd.Flags().GetString(flags.FlagHome)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to do these calls in each command. Can we not use the Context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to do these calls in each command. Can we not use the Context?

The keys * commands don't appear to have a Context. What do you have in mind?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or at least they don't use the clientCtx at all and I was just following how --keyring-backend was implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants