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] #1255 make keybase opened with readonly option for query-purpose cli commands #2489

Merged
merged 1 commit into from
Oct 23, 2018

Conversation

ackratos
Copy link
Contributor

@ackratos ackratos commented Oct 13, 2018

This is a PR for #1255

make keybase opened with readonly option for query-purpose to support better parallelization between gaiacli

This change enabled parallelization between read and write of keys db via gaiacli, so most of operations can be parallelized except multiple add/update keys to keys db at the same time (but sending transactions and serve rest-server can be parallelized!) in trust mode

There are more work to do to supprt non-trust mode, which have to made change to tendermint code. The remainning work mostly reside on make open and close dbprovider in verifier fine grained.

func NewVerifier(chainID, rootDir string, client lclient.SignStatusClient, logger log.Logger) (*lite.DynamicVerifier, error) {

	logger = logger.With("module", "lite/proxy")
	logger.Info("lite/proxy/NewVerifier()...", "chainID", chainID, "rootDir", rootDir, "client", client)

	memProvider := lite.NewDBProvider("trusted.mem", dbm.NewMemDB()).SetLimit(10)
	lvlProvider := lite.NewDBProvider("trusted.lvl", dbm.NewDB("trust-base", dbm.LevelDBBackend, rootDir))

just like golevel db, the cleveldb interface in tendermint should also expose readonly option to up-level caller:

func NewCLevelDB(name string, dir string) (*CLevelDB, error) {
	dbPath := filepath.Join(dir, name+".db")

	opts := levigo.NewOptions()
	opts.SetCache(levigo.NewLRUCache(1 << 30))
	opts.SetCreateIfMissing(true)
	db, err := levigo.Open(dbPath, opts)
	if err != nil {
		return nil, err
	}
	ro := levigo.NewReadOptions()
	wo := levigo.NewWriteOptions()
	woSync := levigo.NewWriteOptions()
	woSync.SetSync(true)
	database := &CLevelDB{
		db:     db,
		ro:     ro,
		wo:     wo,
		woSync: woSync,
	}
	return database, nil
}

This was manually tested:

  1. start a single-node chain by gaiad start
  2. start a rest-server by gaiacli rest-server --chain-id test-chain-2UzoT6 --insecure true --trust-node
  3. query account balance while keep the rest-server running: gaiacli query account cosmos1uw7nvnfccr3fnumtjs82qvvn3z8uzw7fdznn3t --chain-id test-chain-2UzoT6
  • 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.

  • Wrote tests - investigating the failed test case

  • Updated relevant documentation (docs/) - no need update 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)

@ackratos ackratos changed the title #1255 make keybase opened with readonly option to support better para… [WIP] #1255 make keybase opened with readonly option to support better para… Oct 13, 2018
@ackratos ackratos changed the title [WIP] #1255 make keybase opened with readonly option to support better para… [WIP] #1255 make keybase opened with readonly option for query-purpose cli commands Oct 13, 2018
@ackratos ackratos changed the title [WIP] #1255 make keybase opened with readonly option for query-purpose cli commands [R4R] #1255 make keybase opened with readonly option for query-purpose cli commands Oct 13, 2018
@ackratos ackratos changed the title [R4R] #1255 make keybase opened with readonly option for query-purpose cli commands [WIP] #1255 make keybase opened with readonly option for query-purpose cli commands Oct 14, 2018
@ackratos ackratos changed the title [WIP] #1255 make keybase opened with readonly option for query-purpose cli commands [R4R] #1255 make keybase opened with readonly option for query-purpose cli commands Oct 16, 2018
@@ -83,9 +84,9 @@ func ReadPassphraseFromStdin(name string) (string, error) {
}

// initialize a keybase based on the configuration
func GetKeyBaseFromDir(rootDir string) (keys.Keybase, error) {
func GetKeyBaseFromDir(rootDir string, readonly bool) (keys.Keybase, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

my humble proposal:

set readonly to true by default to increase security. and make a separate method GetKeyBaseFromDirWithWritePerm(rootDir string) and call it where needed.

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 proposal. Do you mind modifying this @ackratos ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do that thanks @melekes , glad to see you here:)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@codecov
Copy link

codecov bot commented Oct 18, 2018

Codecov Report

Merging #2489 into develop will not change coverage.
The diff coverage is 50%.

@@           Coverage Diff            @@
##           develop    #2489   +/-   ##
========================================
  Coverage    60.28%   60.28%           
========================================
  Files          150      150           
  Lines         8589     8589           
========================================
  Hits          5178     5178           
  Misses        3067     3067           
  Partials       344      344

@ackratos
Copy link
Contributor Author

I found my failed test Test_Bonding is flaky:

This PR #2474 failed it too:
https://circleci.com/gh/cosmos/cosmos-sdk/37073?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link

Is this a known one or is there anyone working on fixing it?

@jackzampolin
Copy link
Member

@ackratos I think we fixed this in the latest develop. Please try rebasing.

@ackratos
Copy link
Contributor Author

@ackratos I think we fixed this in the latest develop. Please try rebasing.

COOL, rebased.

@jackzampolin
Copy link
Member

@ackratos Just a couple of linting errors now:

gometalinter --config=tools/gometalinter.json ./...
client/keys/utils.go:86:1:warning: exported function GetKeyBaseWithWritePerm should have comment or be unexported (golint)
client/keys/utils.go:91:1:warning: exported function GetKeyBaseFromDirWithWritePerm should have comment or be unexported (golint)
Makefile:193: recipe for target 'test_lint' failed
make: *** [test_lint] Error 1
Exited with code 2

@ackratos ackratos force-pushed the 1255-keybase-readonly branch 2 times, most recently from aa9d96b to 57de66a Compare October 20, 2018 00:23
@ackratos
Copy link
Contributor Author

ackratos commented Oct 20, 2018

@ackratos Just a couple of linting errors now:

gometalinter --config=tools/gometalinter.json ./...
client/keys/utils.go:86:1:warning: exported function GetKeyBaseWithWritePerm should have comment or be unexported (golint)
client/keys/utils.go:91:1:warning: exported function GetKeyBaseFromDirWithWritePerm should have comment or be unexported (golint)
Makefile:193: recipe for target 'test_lint' failed
make: *** [test_lint] Error 1
Exited with code 2

fixed, sorry didn't check that:(

@jackzampolin
Copy link
Member

Looks like dep is missing a dependancy. Can you run dep ensure from the project root commit any changes and push that to this branch?

@alessio
Copy link
Contributor

alessio commented Oct 22, 2018

Hey, I'm the author of #2544. I'd be happy to drop my PR in favor of this 👍

@alessio alessio self-requested a review October 22, 2018 17:38
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.

I'd add a CloseDB() function to the KeyBase interface to allow the caller to explicitly release the lock on the db. This is a not blocking request from me though, I'm happy to merge this.

@jackzampolin
Copy link
Member

@alessio Lets merge this and add the CloseDB() in a separate PR. Cool?

@alessio
Copy link
Contributor

alessio commented Oct 22, 2018

Oh and I'd like to see some tests too! :)

@alessio
Copy link
Contributor

alessio commented Oct 22, 2018

@ackratos I've made some changes to your PR: #2555

@ackratos
Copy link
Contributor Author

ackratos commented Oct 23, 2018

@ackratos I've made some changes to your PR: #2555

Thanks, approved that. I think I can close my PR or you want get mine merged first? Is there anything I can do to get this one merged?

@alessio
Copy link
Contributor

alessio commented Oct 23, 2018 via email

@ackratos
Copy link
Contributor Author

Yes, go ahead please.

I don't have permission to click the merge button, would you like do that?

@alexanderbez
Copy link
Contributor

Thanks @ackratos for the contribution. How does this relate to #2555? Are these duplicates? Can one be closed?

@cwgoes cwgoes merged commit 6c623b2 into cosmos:develop Oct 23, 2018
@ackratos
Copy link
Contributor Author

thanks for reviewing & merging this. Do you know when this change will be released? thx

@cwgoes
Copy link
Contributor

cwgoes commented Oct 24, 2018

thanks for reviewing & merging this. Do you know when this change will be released? thx

Very soon! Track progress here: #2588

@jackzampolin
Copy link
Member

Thanks again for your contribution @ackratos!

@ackratos ackratos deleted the 1255-keybase-readonly branch April 29, 2019 08:31
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.

6 participants