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

R4R: don't lock keybase on lcd startup #3514

Merged
merged 12 commits into from
Feb 6, 2019

Conversation

alessio
Copy link
Contributor

@alessio alessio commented Feb 6, 2019

  • Replace all GetKeyBase* functions family in favor of
    NewKeyBaseFromDir and NewKeyBaseFromHomeFlag.
  • Provide a lazy loading implementation of Keybase that locks the underlying
    storage only for the time needed to perform the required operation.
  • Added Keybase reference to TxBuilder struct.
  • Remove Get prefix from all TxBuilder's getters
  • Linked to github-issue with discussion and accepted design OR link to spec that describes this work.
  • Wrote tests
  • Updated relevant documentation (docs/)
  • Added entries in PENDING.md with issue #
  • rereviewed Files changed in the github PR explorer

For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@codecov
Copy link

codecov bot commented Feb 6, 2019

Codecov Report

Merging #3514 into develop will increase coverage by 4.14%.
The diff coverage is 20%.

@@             Coverage Diff             @@
##           develop    #3514      +/-   ##
===========================================
+ Coverage    55.51%   59.66%   +4.14%     
===========================================
  Files          141      131      -10     
  Lines        10445     9681     -764     
===========================================
- Hits          5799     5776      -23     
+ Misses        4306     3565     -741     
  Partials       340      340

@alessio alessio changed the title WIP: don't lock keybase on lcd startup R4R: don't lock keybase on lcd startup Feb 6, 2019
@@ -162,6 +164,12 @@ func GetAccountDecoder(cdc *codec.Codec) auth.AccountDecoder {
}
}

// WithKeybase returns a copy of the context with an updated keybase.
func (ctx CLIContext) WithKeybase(kb cryptokeys.Keybase) CLIContext {
Copy link
Member

Choose a reason for hiding this comment

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

++

dir string
}

func NewLazyKeybase(name, dir string) Keybase {
Copy link
Member

Choose a reason for hiding this comment

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

++

if err != nil {
return
// MakeSignature builds a StdSignature given keybase, key name, passphrase, and a StdSignMsg.
func MakeSignature(keybase crkeys.Keybase, name, passphrase string,
Copy link
Member

Choose a reason for hiding this comment

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

++ I like this!! 😎

Copy link
Member

@jackzampolin jackzampolin left a comment

Choose a reason for hiding this comment

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

Big fan of this!

Alessio Treglia added 9 commits February 6, 2019 00:26
- GetKeyBase() -> NewKeyBaseFromHomeFlag()
- GetKeyBaseFromDir(rootDir string) > NewKeyBaseFromDir(rootDir string)
		//signedTx, err := func() (auth.StdTx, error) {
		//	oldClientHome := viper.Get(cli.HomeFlag)
		//	defer func() { viper.Set(cli.HomeFlag, oldClientHome) }()
		//	viper.Set(cli.HomeFlag, clientDir)
		//	return txBldr.SignStdTx(nodeDirName, app.DefaultKeyPass, tx, false)
		//}()
It's far more idiomatic to not have such prefix.
@alessio alessio force-pushed the alessio/dont-lock-keybase-on-lcd-startup branch from eedeffe to 5da49fb Compare February 6, 2019 08:41
@jleni
Copy link
Member

jleni commented Feb 6, 2019

btw, I have already rebased my changes on top of this PR! 👍

// TODO: this should be set in NewRestServer
// and pass down the CLIContext to achieve
// parallelism.
viper.Set(cli.HomeFlag, dir)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this could return a cleanup function to defer.
Something similar is being done here:

func SetupViper(t *testing.T) func() {
rootDir, err := ioutil.TempDir("", "mock-sdk-cmd")
require.Nil(t, err)
viper.Set(cli.HomeFlag, rootDir)
viper.Set(client.FlagName, "moniker")
return func() {
err := os.RemoveAll(rootDir)
if err != nil {
// TODO: Handle with #870
panic(err)
}

I am adding a temporary directory helper in a future PR.

Copy link
Member

Choose a reason for hiding this comment

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

I don't see this as an urgent change to block the PR

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

LGTM -- left a few minor remarks

@@ -19,15 +17,12 @@ import (
// KeyDBName is the directory under root where we store the keys
const KeyDBName = "keys"

// keybase is used to make GetKeyBase a singleton
var keybase keys.Keybase
Copy link
Contributor

Choose a reason for hiding this comment

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

++

return lazyKeybase{name: name, dir: dir}
}

func (lkb lazyKeybase) List() ([]Info, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this will be a huge PIA, but can we add godocs for all of these please?

@jackzampolin jackzampolin merged commit 9a57ce0 into develop Feb 6, 2019
@jackzampolin jackzampolin deleted the alessio/dont-lock-keybase-on-lcd-startup branch February 6, 2019 19:23
@sabau sabau mentioned this pull request Feb 7, 2019
2 tasks
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