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(orm): add module db #10991

Merged
merged 14 commits into from
Jan 22, 2022
Merged

feat(orm): add module db #10991

merged 14 commits into from
Jan 22, 2022

Conversation

aaronc
Copy link
Member

@aaronc aaronc commented Jan 20, 2022

Description

This PR adds a ModuleDB interface which can be used directly by Cosmos SDK modules. A simplified bank example with Mint/Send/Burn functionality against Balance and Supply tables is included in the tests.

This PR also:

  • adds simplified Get and Has methods to Table which use the primary key values in the message instead of ...interface{}
  • adds a stable deterministic proto JSON marshaler and updates the Entry.String methods to use it because the golden tests are not deterministic without this. This code is currently internal but can be extracted to a public codec or cosmos-proto package eventually.

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)

@github-actions github-actions bot added the C:orm label Jan 20, 2022
@codecov
Copy link

codecov bot commented Jan 20, 2022

Codecov Report

Merging #10991 (f71bca1) into master (eb5b11b) will increase coverage by 0.20%.
The diff coverage is 68.34%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10991      +/-   ##
==========================================
+ Coverage   65.86%   66.06%   +0.20%     
==========================================
  Files         647      690      +43     
  Lines       65764    69558    +3794     
==========================================
+ Hits        43314    45952    +2638     
- Misses      19970    20810     +840     
- Partials     2480     2796     +316     
Impacted Files Coverage Δ
orm/model/ormdb/module.go 51.47% <51.47%> (ø)
orm/encoding/ormkv/entry.go 77.77% <57.14%> (ø)
orm/model/ormdb/file.go 57.14% <57.14%> (ø)
orm/model/ormtable/table_impl.go 55.37% <57.14%> (ø)
orm/internal/stablejson/encode.go 67.60% <67.60%> (ø)
x/feegrant/keeper/grpc_query.go 76.40% <68.96%> (-3.60%) ⬇️
orm/model/ormtable/primary_key.go 51.21% <75.00%> (ø)
x/feegrant/client/testutil/suite.go 99.64% <100.00%> (+0.02%) ⬆️
x/feegrant/key.go 100.00% <100.00%> (+100.00%) ⬆️
orm/model/ormtable/field_names.go 100.00% <0.00%> (ø)
... and 41 more

@aaronc aaronc changed the title feat(orm): module db feat(orm): add module db Jan 21, 2022
@aaronc aaronc linked an issue Jan 21, 2022 that may be closed by this pull request
@aaronc aaronc marked this pull request as ready for review January 21, 2022 00:43
@aaronc aaronc requested a review from alexanderbez as a code owner January 21, 2022 00:43

// Marshal marshals the provided message to JSON with a stable ordering based
// on ascending field numbers.
func Marshal(message proto.Message) ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

haven't done a deep check, but maybe there are some protobuf well-known types that need to be json marshalled in a custom way, examples are: timestamp, struct, etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, you're right... hopefully it's not too bad. will take a look soon

Copy link
Member Author

Choose a reason for hiding this comment

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

I think for now, maybe this is okay just because the main use case is to do stable marshaling for tests. I'm mainly trying to prevent spurious CI failures rather than a full fledged encoder

Comment on lines +22 to +30
// Has returns true if there is an entity in the table with the same
// primary key as message. Other fields besides the primary key fields will not
// be used for retrieval.
Has(ctx context.Context, message proto.Message) (found bool, err error)

// Get retrieves the message if one exists for the primary key fields
// set on the message. Other fields besides the primary key fields will not
// be used for retrieval.
Get(ctx context.Context, message proto.Message) (found bool, err error)
Copy link
Member Author

Choose a reason for hiding this comment

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

@fdymylja added these to the Table interface as this makes Has/Get usage based on the primary key simpler.

Copy link
Contributor

@ryanchristo ryanchristo left a comment

Choose a reason for hiding this comment

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

Aside from the minor changes to the format of an entry that need to be reflected in entry_test.go, looks good to me. Pre-approving.

orm/encoding/ormkv/entry.go Show resolved Hide resolved
orm/encoding/ormkv/entry.go Show resolved Hide resolved
Copy link
Contributor

@technicallyty technicallyty left a comment

Choose a reason for hiding this comment

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

👍🏻

@aaronc aaronc added the A:automerge Automatically merge PR once all prerequisites pass. label Jan 22, 2022
@mergify mergify bot merged commit 6ea2049 into master Jan 22, 2022
@mergify mergify bot deleted the aaronc/orm-db branch January 22, 2022 03: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:orm
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

ORM module integration
7 participants