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

CLI/keys: define default supported keyring algorithms #8825

Merged
merged 17 commits into from
Mar 18, 2021

Conversation

gsora
Copy link
Contributor

@gsora gsora commented Mar 9, 2021

Description

This PR adds a way for developers to specify a suite of algorithms to be used in keyring instances instantiated with keyring.New().

While New() already has ways of achieving something similar doing so in CLI commands, in a generic enough way, is very hard.

We address this by providing package-level settings in keyring to define a default SigningAlgoList, automatically used in every keyring initialization phase.

This PR streamlines also the keys add command execution flow by using the Keyring included in the CLI context instead of instantiating a new one.

closes: #8803


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)
  • 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

gsora added 5 commits March 9, 2021 12:57
This commit lets developer define what algorithms Keyring supports instead of relying on just keyring.New options.

This change is needed since it allows us to support those algorithms in CLI commands too without subverting their current execution flow.
@gsora gsora added help wanted C:CLI T: Dev UX UX for SDK developers (i.e. how to call our code) labels Mar 9, 2021
@gsora gsora self-assigned this Mar 9, 2021
@alessio alessio requested a review from fedekunze March 9, 2021 16:11
@codecov
Copy link

codecov bot commented Mar 10, 2021

Codecov Report

Merging #8825 (3090574) into master (1fddce7) will decrease coverage by 0.00%.
The diff coverage is 44.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8825      +/-   ##
==========================================
- Coverage   59.24%   59.23%   -0.01%     
==========================================
  Files         571      571              
  Lines       31807    31800       -7     
==========================================
- Hits        18844    18837       -7     
- Misses      10760    10761       +1     
+ Partials     2203     2202       -1     
Impacted Files Coverage Δ
client/context.go 57.00% <0.00%> (-1.09%) ⬇️
client/cmd.go 57.26% <100.00%> (ø)
client/keys/add.go 62.27% <100.00%> (-0.80%) ⬇️

Since Simulate is now used in both tx and query commands, move its reading routine into ReadPersistentCommandFlags.

Removed DryRun from Context, since it's not needed anymore.
@alessio alessio added A:automerge Automatically merge PR once all prerequisites pass. and removed help wanted labels Mar 13, 2021
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.

ACKed

@orijbot
Copy link

orijbot commented Mar 14, 2021

@orijbot
Copy link

orijbot commented Mar 14, 2021

Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Please don't use globals for controlling a constructor behavior.

BTW: I was also looking at this code last week, and felt a need to make a simapp keys list-algos command: #8886

@orijbot
Copy link

orijbot commented Mar 16, 2021

@gsora gsora requested review from alessio and jgimeno March 16, 2021 16:11
@alessio alessio requested a review from robert-zaremba March 16, 2021 17:22
@orijbot
Copy link

orijbot commented Mar 16, 2021

@orijbot
Copy link

orijbot commented Mar 16, 2021

Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

  1. Tests needs to be udpated (it's still using the old, failing logic)
  2. Context obfuscates the flow, and makes it hard to see how the parameters are passed. I propose a way to not use context - if you like we can have a chat.
  3. Documentation (/docs) and Changelog has to be updated as well.

if ctx.GenerateOnly {
return keyring.New(sdk.KeyringServiceName(), keyring.BackendMemory, ctx.KeyringDir, ctx.Input)
if ctx.GenerateOnly || ctx.Simulate {
return keyring.New(sdk.KeyringServiceName(), keyring.BackendMemory, ctx.KeyringDir, ctx.Input, ctx.KeyringOptions...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of using a context, can we use it in a straight way? Using a context obfuscates a flow. We should use function parameters wherever possible.
The ReadPersistentCommandFlags has access to flagSet - a set of defined flags. newKeyringFromFlags is called in that function. So we can use flagSet to carry the information (from config or cli flag) about supported algos. We could also add one more structural parameter to the ReadPersistentCommandFlags.

Copy link
Contributor

Choose a reason for hiding this comment

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

Robert, I agree with you on "using a context obfuscates a flow". Fully. I am a big fan of function parameters. I hate any stateful context and I hate even more using contexts to conveniently pack variables in order to reduce the number of function's arguments because that means that you are keen to sacrifice transparency and ease of debugging for the lazy developer's sake.

And yet, this is what we have now. I like your proposed changes, but I believe they are out of scope here. We should open another issue and try to overhaul the Context in a more holistic way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, but I would like to avoid adding more XOptions directly into config, and I'm worried that someone else from other team will be motivated to do it (by following an example of what's already implemented)

@orijbot
Copy link

orijbot commented Mar 17, 2021

@alessio alessio requested a review from robert-zaremba March 17, 2021 12:39
@orijbot
Copy link

orijbot commented Mar 17, 2021

@orijbot
Copy link

orijbot commented Mar 17, 2021

Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

I would prefer to put configs into a Context sub structure (not as a direct context attribute). But for short term this is good enough.
I created an issue to tackle the config problem: #8915

@orijbot
Copy link

orijbot commented Mar 18, 2021

@mergify mergify bot merged commit deaee53 into master Mar 18, 2021
@mergify mergify bot deleted the gsora/keys-commands-algorithms branch March 18, 2021 08:27
@orijbot
Copy link

orijbot commented Mar 18, 2021

@orijbot
Copy link

orijbot commented Mar 18, 2021

@orijbot
Copy link

orijbot commented Mar 18, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. C:CLI T: Dev UX UX for SDK developers (i.e. how to call our code)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Injection of Signing algorithm in Keys Add CLI command.
7 participants