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

Change Coin storage model #9361

Closed
2 of 4 tasks
robert-zaremba opened this issue May 19, 2021 · 3 comments · Fixed by #9832
Closed
2 of 4 tasks

Change Coin storage model #9361

robert-zaremba opened this issue May 19, 2021 · 3 comments · Fixed by #9832
Assignees
Labels
C:x/bank T: Performance Performance improvements

Comments

@robert-zaremba
Copy link
Collaborator

robert-zaremba commented May 19, 2021

Summary

The sdk.Coin has the following type definition:

type Coin struct {
	Denom  string 
	Amount Int
}

Bank module stores account balances in KV store using following schema:

key = "<module key>/<holder_address>/<denom>"
value = proto.Marshal(coin)

Problem Definition

The denom is repeated both in the key and value and wastes the valuable blockchain space.

Proposal

We can save a blockchain space if we only save the amount in value:

key = "<module key>/<holder_address>/<denom>"
value = coin.Amount.Bytes()

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@robert-zaremba robert-zaremba added C:x/bank S:needs architecture review To discuss on the next architecture review call to come to alignment labels May 19, 2021
@alexanderbez
Copy link
Contributor

I think the proposal is fine 👍

@aaronc
Copy link
Member

aaronc commented May 19, 2021

That makes sense, but why do we even need to proto.Marshal a string? Why don't we just do store.Set(key, []byte(coin.Amount))

@robert-zaremba
Copy link
Collaborator Author

robert-zaremba commented May 19, 2021

yes, we can save amount directly without using protobuf.

@amaury1093 amaury1093 removed the S:needs architecture review To discuss on the next architecture review call to come to alignment label Jun 30, 2021
@aaronc aaronc added the T: Performance Performance improvements label Jun 30, 2021
@mergify mergify bot closed this as completed in #9832 Aug 5, 2021
mergify bot pushed a commit that referenced this issue Aug 5, 2021
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->

## Description

Closes: #9361 

<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->

---

### 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...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [x] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:x/bank T: Performance Performance improvements
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants