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: x/gov ChargeDeposit delete deposits #15033

Merged
merged 1 commit into from
Feb 14, 2023
Merged

Conversation

facundomedica
Copy link
Member

@facundomedica facundomedica commented Feb 14, 2023

Description

TL;DR: the code tried to delete all deposits with a prefix, this doesn't work. We need to delete each deposit with its own key.

Previously it was trying to delete a non-existing key, so when comparing the balance of the gov module account vs the amount of deposits they didn't match because the deposit tokens were burnt/refunded but the deposit object was never deleted.

Also included some renamings of variables to make it easier to read


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)

@facundomedica facundomedica requested a review from a team as a code owner February 14, 2023 19:55
@github-prbot github-prbot requested review from a team, atheeshp and likhita-809 and removed request for a team February 14, 2023 19:55
@@ -203,6 +203,8 @@ func (keeper Keeper) ChargeDeposit(ctx sdk.Context, proposalID uint64, destAddre
return err
}
}

store.Delete(types.DepositKey(deposit.ProposalId, depositerAddress))
Copy link
Member

Choose a reason for hiding this comment

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

Say a function below fails (BurnCoins, GetModuleAddress, FunCommunityPool), what happens to the deposit then?

Isn't it safer to store the deposit keys to delete and delete them at the end of his function?

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 we might not need to do that, because if we return an error all the changes done during the message execution won't get persisted, right? But now that you mention it I'm not that sure

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.

ACK, but one concern.

@alexanderbez alexanderbez merged commit dfb3271 into main Feb 14, 2023
@alexanderbez alexanderbez deleted the facu/fix-gov-chargedeposit branch February 14, 2023 21:26
@facundomedica facundomedica added the backport/v0.47.x PR scheduled for inclusion in the v0.47's next stable release label Feb 14, 2023
mergify bot pushed a commit that referenced this pull request Feb 14, 2023
(cherry picked from commit dfb3271)

# Conflicts:
#	x/gov/keeper/deposit.go
@tac0turtle
Copy link
Member

would be interested to see how this issue landed on main, this is something we should figure out how to prevent in the future

@julienrbrt
Copy link
Member

julienrbrt commented Feb 15, 2023

would be interested to see how this issue landed on main, this is something we should figure out how to prevent in the future

To answer this, we can see that #13010 added the feature and its simulations.
However, looking at when these sims started to fail is shortly after the simulation refactor (#14728), maybe that surfaced it.

Moreover, long SimApp simulations do not run on PRs because they take 45min up to 1h to run. We do have short sims in CI.

@facundomedica
Copy link
Member Author

Maybe we can change this with the merge queue, and run sims there too

@tac0turtle
Copy link
Member

is there a possibility that a unit test case could of caught the issue?

@amaury1093
Copy link
Contributor

amaury1093 commented Feb 15, 2023

Probably yes. I reviewed that PR multiple times, my reviews were mostly around adding more tests, review 1, or any comment under review 2. However, towards the end, as a reviewer it's very hard to gauge what was tested, and what not.

I wonder if this kind of complex state machine logic could be a good showcase of BDD.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.47.x PR scheduled for inclusion in the v0.47's next stable release C:x/gov
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants