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: ADR-040: Add RootStore implementation #10430

Merged
merged 47 commits into from
Dec 16, 2021

Conversation

roysc
Copy link
Contributor

@roysc roysc commented Oct 25, 2021

Description

Part of: #10192

Introduces a new RootStore type in the store/v2 package and an implementation, without yet replacing the MultiStore or refactoring its use within the SDK (which will happen in the follow up: #10174).
Specified by ADR-040.

Fixes #10651
Fixes #10263


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@roysc roysc force-pushed the roysc/adr-040-create-rootstore branch from 91eb724 to 6b983e5 Compare October 27, 2021 14:00
@roysc roysc marked this pull request as ready for review October 27, 2021 14:42
@robert-zaremba robert-zaremba mentioned this pull request Nov 3, 2021
38 tasks
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.

part-1 review

db/memdb/db.go Outdated Show resolved Hide resolved
db/meta/backend.go Outdated Show resolved Hide resolved
db/meta/backend.go Outdated Show resolved Hide resolved
db/meta/backend.go Outdated Show resolved Hide resolved
internal/db/legacy_adapter.go Outdated Show resolved Hide resolved
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.

Part 2 review

  • let's rename flat package to root

store/v2/dbadapter/store.go Show resolved Hide resolved
)

// RootStoreConfig is used to define a schema and pass options to the RootStore constructor.
type RootStoreConfig struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we don't need to store the config at all. The idea of RootStore was to remove the functionality of Multistore (dynamically adding / removing sub stores) and only provide a minimum functionality to keep the compatibility with existing modules (notably IBC).
In other words, RootStore:

  • is configured by app
  • doesn't need to load a dynamic configuration from its persistent state.

Let's review this approach.

Copy link
Collaborator

Choose a reason for hiding this comment

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

store/v2/flat/store.go Outdated Show resolved Hide resolved
store/v2/flat/store_view.go Outdated Show resolved Hide resolved
@roysc roysc force-pushed the roysc/adr-040-create-rootstore branch from 436fdaa to ad9ab87 Compare November 11, 2021 12:14
@lgtm-com
Copy link

lgtm-com bot commented Nov 11, 2021

This pull request introduces 1 alert when merging ad9ab87 into 8fc9f76 - view on LGTM.com

new alerts:

  • 1 for Expression has no effect

@roysc roysc force-pushed the roysc/adr-040-create-rootstore branch from ad9ab87 to b90fadf Compare November 17, 2021 17:09
@roysc
Copy link
Contributor Author

roysc commented Nov 17, 2021

Okay, this is now reworked to store an independent SMT for each store (and combine each tree into a "namespace" Merkle map to produce a root hash, like the Multistore). This will allow us to implement proofs in an IBC-compatible way. The actual proofs are not implemented, but that can be done on top of #10015. Since that PR has yet to be reviewed, I propose we focus on getting this merged and then rebase that branch and add RootStore proofs there.

cc @robert-zaremba @aaronc @marbar3778

@roysc roysc changed the title feat: ADR-040: Add RootStore implementation feat: ADR-040: Add RootStore implementation Nov 17, 2021
@codecov
Copy link

codecov bot commented Nov 18, 2021

Codecov Report

Merging #10430 (198c1a5) into master (3495691) will decrease coverage by 0.70%.
The diff coverage is 57.46%.

❗ Current head 198c1a5 differs from pull request most recent head 644cef8. Consider uploading reports for the commit 644cef8 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10430      +/-   ##
==========================================
- Coverage   65.42%   64.72%   -0.71%     
==========================================
  Files         634      624      -10     
  Lines       60702    60354     -348     
==========================================
- Hits        39716    39065     -651     
- Misses      18686    19056     +370     
+ Partials     2300     2233      -67     
Impacted Files Coverage Δ
client/tx/factory.go 24.64% <0.00%> (-0.73%) ⬇️
db/memdb/db.go 72.72% <ø> (ø)
db/rocksdb/batch.go 67.56% <ø> (ø)
db/rocksdb/db.go 72.25% <ø> (ø)
db/rocksdb/iterator.go 83.33% <ø> (ø)
store/types/store.go 64.70% <0.00%> (ø)
store/v2/multi/cache_store.go 0.00% <0.00%> (ø)
types/module/configurator.go 15.55% <0.00%> (-0.73%) ⬇️
x/auth/client/testutil/suite.go 97.33% <ø> (ø)
x/authz/client/testutil/tx.go 98.22% <ø> (ø)
... and 126 more

@roysc roysc force-pushed the roysc/adr-040-create-rootstore branch from 5df15dc to 325e448 Compare November 23, 2021 04:52
Copy link
Contributor

@i-norden i-norden left a comment

Choose a reason for hiding this comment

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

Nothing insightful to add, just a few nitpicks. Didn't find any functional issues.

db/prefix/prefix.go Show resolved Hide resolved
store/v2/dbadapter/store.go Outdated Show resolved Hide resolved
store/v2/dbadapter/store_test.go Outdated Show resolved Hide resolved
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. Let's update the documentation by explaining when and how the substores are created
  2. There is lot of code duplication with v1. Would it be possible to import it rather than copying? Or maybe moving to it's own package, but it's a breaking change which we would like to avoid...

db/prefix/prefix.go Show resolved Hide resolved
db/prefix/prefix.go Outdated Show resolved Hide resolved
db/prefix/prefix.go Show resolved Hide resolved
docs/core/store.md Outdated Show resolved Hide resolved
const StoreTypeTransient = v1.StoreTypeTransient
const StoreTypeDB = v1.StoreTypeDB
const StoreTypeSMT = v1.StoreTypeSMT
const StoreTypePersistent = v1.StoreTypePersistent
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think StoreTypeSMT is not needed in v1 package and we can move it 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.

Unfortunately if we do that we can't include it in the (StoreType) String() function, because it's in a separate package.

store/v2/root/store.go Outdated Show resolved Hide resolved
store/v2/root/store.go Outdated Show resolved Hide resolved
store/v2/root/store.go Outdated Show resolved Hide resolved
store/v2/root/store.go Outdated Show resolved Hide resolved
store/v2/root/store.go Outdated Show resolved Hide resolved
@roysc roysc force-pushed the roysc/adr-040-create-rootstore branch 3 times, most recently from dbb2dfa to 04b51a5 Compare December 1, 2021 17:16
GetVersion
rename to databucket, indexbucket
- GetVersion
- migration (StoreUpgrades)
- flat.Store query uses getversion
@roysc roysc force-pushed the roysc/adr-040-create-rootstore branch from 857d09a to eab5875 Compare December 3, 2021 13:30
@github-actions github-actions bot removed the T: CI label Dec 3, 2021
@roysc roysc force-pushed the roysc/adr-040-create-rootstore branch from eab5875 to c04cd39 Compare December 3, 2021 13:33
@roysc roysc force-pushed the roysc/adr-040-create-rootstore branch from c04cd39 to ad227e0 Compare December 3, 2021 13:33
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.

@roysc roysc mentioned this pull request Dec 8, 2021
19 tasks
Copy link
Contributor

@i-norden i-norden left a comment

Choose a reason for hiding this comment

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

Excellent work! I left some rather nit-picky comments, I can't find anything substantial left to change.

docs/core/store.md Outdated Show resolved Hide resolved
docs/core/store.md Outdated Show resolved Hide resolved
if tlm.TracingEnabled() {
store = tracekv.NewStore(store, tlm.TraceWriter, tlm.TraceContext)
}
if wls, has := tlm.listeners[skey.Name()]; has && len(wls) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use ListeningEnabled method here?

if ls, has := tlm.listeners[key]; has {
tlm.listeners[key] = append(ls, listeners...)
} else {
tlm.listeners[key] = listeners
Copy link
Contributor

Choose a reason for hiding this comment

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

We can append to tlm.listeners[key] whether or not that key already exists in the map (as long as the entire map isn't nil, which it isn't)

@robert-zaremba robert-zaremba added A:automerge Automatically merge PR once all prerequisites pass. and removed A:automerge Automatically merge PR once all prerequisites pass. labels Dec 15, 2021
@robert-zaremba
Copy link
Collaborator

Tiny things to update:

  • rename root package to multi
  • re-review documentation for updates. (see Ian review, maybe there are other things to update as well).

@roysc roysc added the A:automerge Automatically merge PR once all prerequisites pass. label Dec 16, 2021
@roysc roysc force-pushed the roysc/adr-040-create-rootstore branch from 198c1a5 to 644cef8 Compare December 16, 2021 12:58
@mergify mergify bot merged commit 109bc94 into cosmos:master Dec 16, 2021
@roysc roysc deleted the roysc/adr-040-create-rootstore branch February 15, 2022 07:13
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:Store
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a flag to enable rocksdb tests Fork RocksDB into cosmos organization and use it in store/v2
5 participants