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

Mount every single store with its own DB #726

Merged
merged 5 commits into from
Mar 30, 2018
Merged

Conversation

adrianbrink
Copy link
Contributor

@adrianbrink adrianbrink commented Mar 28, 2018

@adrianbrink adrianbrink requested a review from ebuchman as a code owner March 28, 2018 12:34
Our tests are at best probabilistic deterministic.
@codecov
Copy link

codecov bot commented Mar 28, 2018

Codecov Report

Merging #726 into develop will increase coverage by 0.1%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           develop     #726     +/-   ##
==========================================
+ Coverage    64.04%   64.15%   +0.1%     
==========================================
  Files           43       43             
  Lines         2022     2028      +6     
==========================================
+ Hits          1295     1301      +6     
  Misses         615      615             
  Partials       112      112

@adrianbrink
Copy link
Contributor Author

Testet locally. It allows you to restart the app without wiping the database.

Copy link
Member

@ebuchman ebuchman left a comment

Choose a reason for hiding this comment

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

Awesome thank you.

We have unit testing that captures this but is just commented out.

eg. https://github.com/cosmos/cosmos-sdk/blob/master/baseapp/baseapp_test.go#L154

and

https://github.com/cosmos/cosmos-sdk/blob/master/examples/basecoin/app/app_test.go#L145

Maybe we can write a proper specific unit test for it too ?

}
}

// Mount a store to the provided key in the BaseApp multistore
func (app *BaseApp) MountStore(key sdk.StoreKey, typ sdk.StoreType) {
app.cms.MountStoreWithDB(key, typ, app.db)
func (app *BaseApp) MountStore(key sdk.StoreKey, typ sdk.StoreType, db dbm.DB) {
Copy link
Member

Choose a reason for hiding this comment

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

let's leave the old MountStore, mark it as broken like above, and add a new MountStoreWithDB method to BaseApp

capKeyIBCStore *sdk.KVStoreKey
capKeyStakingStore *sdk.KVStoreKey

// Manage getting and setting accounts
accountMapper sdk.AccountMapper
}

func NewBasecoinApp(logger log.Logger, db dbm.DB) *BasecoinApp {
func NewBasecoinApp(logger log.Logger, dbMain, dbAcc, dbIBC, dbStaking dbm.DB) *BasecoinApp {
Copy link
Member

Choose a reason for hiding this comment

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

lets start a convention here where we pass in a map[string]dbm.DB and then we can use that to fill in the capKeys, rather than this hardcoded list.

Then we can add more dbs (governance, etc.) without breaking the API

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once #532 is merged we will only need one database and it feels strange that we want to pass in multiple databases. I think it provides a strange API if we allow a map of databases to be passed in, because then we also need to have some convention around how those map to capKeys.

Copy link
Member

Choose a reason for hiding this comment

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

The convention is extremely simple: use the same string.

I have the following facts:

  • the DB will be fixed an unknown amount of time in the future (call it months)
  • we will add new stores soon (call it weeks)
  • we have users of this API (including ourselves, in tests)
  • the current approach will lead to more breakages of this API

I would think the above signals strongly that we should take an approach that can last for a bit and will require the least amount of maintenance work. Why set us up to do more unnecessary work in the future ?

cdc: MakeCodec(),
capKeyMainStore: sdk.NewKVStoreKey("main"),
capKeyAccountStore: sdk.NewKVStoreKey("acc"),
Copy link
Member

Choose a reason for hiding this comment

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

what is the account key used for ? currently we just put it in the main I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we used the main store also as the account store. However it seems cleaner if the accounts get their own capKey instead of just using the main one. In the future we might want to give someone access to the accounts without giving them access to governance.

@ebuchman
Copy link
Member

Still need to address the comments and get unit tests in place but would be great to merge and release this today if possible

Adrian Brink added 2 commits March 29, 2018 20:44
I hope this is correct. I'm feely pretty dizzy right now from the fish
food.
NewBasecoinApp takes a map[string]dbm.DB . This stabilises the API,
since it allows us to add more stores without a breaking change. The
convention is that the keys of the dbs correspond to the names of the
capKeys.
ebuchman
ebuchman previously approved these changes Mar 30, 2018
Copy link
Member

@ebuchman ebuchman left a comment

Choose a reason for hiding this comment

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

Wundabar!

@ebuchman
Copy link
Member

I'm going to uncomment the other test I mentioned as well and push to this branch, then merge

@ebuchman ebuchman merged commit d25593a into develop Mar 30, 2018
@ebuchman ebuchman deleted the adrian/mountmultipledbs branch March 30, 2018 10:41
@adrianbrink
Copy link
Contributor Author

Oh I missed that one. Sorry, was travelling all of yesterday for the Easter celebrations.

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.

2 participants