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

fix(bank): fix unhandled error for vesting #13690

Merged
merged 14 commits into from
Nov 3, 2022
Merged

Conversation

fedekunze
Copy link
Collaborator

@fedekunze fedekunze commented Oct 29, 2022

Description

Closes: #13691


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)

@fedekunze fedekunze marked this pull request as ready for review October 29, 2022 10:49
@fedekunze fedekunze requested a review from a team as a code owner October 29, 2022 10:49
@fedekunze fedekunze added backport/0.45.x backport/0.46.x PR scheduled for inclusion in the v0.46's next stable release T:Bug labels Oct 29, 2022
@codecov
Copy link

codecov bot commented Oct 29, 2022

Codecov Report

Merging #13690 (e0dae11) into main (155bcfa) will decrease coverage by 0.59%.
The diff coverage is 91.66%.

❗ Current head e0dae11 differs from pull request most recent head 3c075a9. Consider uploading reports for the commit 3c075a9 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #13690      +/-   ##
==========================================
- Coverage   56.03%   55.43%   -0.60%     
==========================================
  Files         646      646              
  Lines       55784    55790       +6     
==========================================
- Hits        31258    30928     -330     
- Misses      21984    22344     +360     
+ Partials     2542     2518      -24     
Impacted Files Coverage Δ
x/bank/keeper/send.go 80.79% <90.90%> (+0.38%) ⬆️
types/coin.go 94.51% <100.00%> (ø)
x/distribution/client/cli/query.go 0.00% <0.00%> (-73.95%) ⬇️
x/distribution/client/cli/tx.go 5.49% <0.00%> (-69.79%) ⬇️
crypto/keys/internal/ecdsa/privkey.go 83.01% <0.00%> (+1.88%) ⬆️

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

lgtm! maybe we should add a test, though.

CHANGELOG.md Outdated Show resolved Hide resolved
// NOTE: denom and amount validation should occur before transfer
locked := sdk.Coin{
Denom: coin.Denom,
Amount: lockedCoins.AmountOfNoDenomValidation(coin.Denom),
Copy link
Contributor

Choose a reason for hiding this comment

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

What benefit do we have to calling AmountOfNoDenomValidation here over AmountOf? Since validation should occur prior as you pointed out, AmountOf seems practical, no?

Copy link
Collaborator Author

@fedekunze fedekunze Oct 31, 2022

Choose a reason for hiding this comment

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

NewCoin and AmountOf validate the denom. Here we don't need to because we are already passing a Coins type as an argument. By using AmountOfNoDenomValidation and sdk.Coin{} we're saving two unnecessary denom validations just in this operation

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit against this. The idea is that these APIs exist for a reason, and unless explicitly not needed, e.g. denom validation is explicitly not required, then New* constructors should always be called. This also keeps consistency with the rest of the codebase and makes the PR diff smaller.

Copy link
Member

Choose a reason for hiding this comment

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

I tend to agree on this one, I really like consistency. Unless there's a noticeable performance difference I would go with AmountOf.

Copy link
Member

Choose a reason for hiding this comment

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

Shall we just push to this branch and fix it then?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yah!

Copy link
Member

Choose a reason for hiding this comment

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

Reverted!

x/bank/keeper/send.go Outdated Show resolved Hide resolved
fedekunze and others added 2 commits October 31, 2022 08:02
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Copy link
Member

@facundomedica facundomedica left a comment

Choose a reason for hiding this comment

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

LGTM, as Julien said would be nice to have a small test for this

Copy link
Contributor

@likhita-809 likhita-809 left a comment

Choose a reason for hiding this comment

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

lgtm

@fedekunze
Copy link
Collaborator Author

thanks for the reviews! Unfortunately, I don't have time to work on tests until the end of the week. I might ask someone from Evmos to add them on my behalf

@julienrbrt
Copy link
Member

Thanks, @MalteHerrmann for the test!

@julienrbrt julienrbrt added the A:automerge Automatically merge PR once all prerequisites pass. label Nov 3, 2022
@mergify mergify bot merged commit 3034a9d into main Nov 3, 2022
@mergify mergify bot deleted the fedekunze/handle-locked-amt branch November 3, 2022 18:22
mergify bot pushed a commit that referenced this pull request Nov 3, 2022
## Description

Closes: #13691

---

### 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] 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](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)

(cherry picked from commit 3034a9d)

# Conflicts:
#	CHANGELOG.md
#	x/bank/keeper/keeper_test.go
mergify bot pushed a commit that referenced this pull request Nov 3, 2022
## Description

Closes: #13691

---

### 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] 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](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)

(cherry picked from commit 3034a9d)

# Conflicts:
#	CHANGELOG.md
#	types/coin.go
#	x/bank/keeper/keeper_test.go
#	x/bank/keeper/send.go
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. backport/0.46.x PR scheduled for inclusion in the v0.46's next stable release C:x/bank T:Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unhandled error when vesting locked amount > balance
8 participants