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): deposits in simulations #18336

Merged
merged 2 commits into from
Nov 2, 2023
Merged

fix(x/gov): deposits in simulations #18336

merged 2 commits into from
Nov 2, 2023

Conversation

facundomedica
Copy link
Member

@facundomedica facundomedica commented Nov 2, 2023

Description

Closes: #XXXX


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
  • run make lint and make test
  • 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)

Summary by CodeRabbit

New Features:

  • Enhanced proposal retrieval with the addition of a new line to fetch proposals using k.Proposals.Get, improving the system's efficiency.
  • Updated the randomDeposit function to include the p.Expedited flag, providing more flexibility in function calls.

Please note that these changes are aimed at improving the overall performance and flexibility of the system, which should result in a smoother user experience.

Sorry, something went wrong.

Verified

This commit was signed with the committer’s verified signature.
facundomedica Facundo Medica
Copy link
Contributor

coderabbitai bot commented Nov 2, 2023

Walkthrough

The changes made to the codebase primarily revolve around enhancing the functionality of the randomDeposit function and improving error handling in the proposal retrieval process. The randomDeposit function now includes the p.Expedited flag, and a new line has been added to handle errors when getting the proposal using k.Proposals.Get.

Changes

File Path Summary
x/gov/simulation/operations.go A new line was added to retrieve the proposal using k.Proposals.Get and handle any potential errors. The randomDeposit function was also modified to include the p.Expedited flag.
x/gov/simulation/operations_test.go Changes were made in the test file. In the TestSimulateMsgSubmitProposal function, the value of msg.InitialDeposit[0] was changed. In the TestSimulateMsgSubmitLegacyProposal function, the value of msg.InitialDeposit[0] was changed. In the TestSimulateMsgDeposit function, the value of msg.Amount[0] was changed.

Poem

🍂 As the leaves fall this November, 🍁

Code changes we shall always remember. 📝

With randomDeposit now more refined, 🌟

And error handling well-defined. 🛠️

In the world of code, we dance and sway, 💃

Celebrating these changes today. 🎉

So here's to the coders, in their chairs, 💻

Making magic with brackets and squares. 🪄

As the day ends, we close our tabs, 🌙

Ready for tomorrow's code and labs. 🌞


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.json

@facundomedica facundomedica marked this pull request as ready for review November 2, 2023 13:53
@facundomedica facundomedica requested a review from a team as a code owner November 2, 2023 13:53
Copy link
Contributor

github-actions bot commented Nov 2, 2023

@facundomedica your pull request is missing a changelog!

@github-prbot github-prbot requested review from a team, alexanderbez and samricotta and removed request for a team November 2, 2023 13:54
@facundomedica facundomedica added the backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release label Nov 2, 2023
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 177e7f4 and 2382262.
Files selected for processing (1)
  • x/gov/simulation/operations.go (2 hunks)

Comment on lines 322 to 333
return simtypes.NoOpMsg(types.ModuleName, TypeMsgDeposit, "unable to generate proposalID"), nil, nil
}

deposit, skip, err := randomDeposit(r, ctx, ak, bk, k, simAccount.Address, false, false)
p, err := k.Proposals.Get(ctx, proposalID)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, TypeMsgDeposit, "unable to get proposal"), nil, err
}

deposit, skip, err := randomDeposit(r, ctx, ak, bk, k, simAccount.Address, false, p.Expedited)
switch {
case skip:
return simtypes.NoOpMsg(types.ModuleName, TypeMsgDeposit, "skip deposit"), nil, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

The error handling here is good, it checks for errors and handles them appropriately. However, the error messages could be more descriptive to provide more context about the error. For example, instead of "unable to generate proposalID", you could say "unable to generate proposalID in SimulateMsgDeposit function". This would make it easier to debug if an error occurs.

Comment on lines 597 to 602
return nil, false, err
}
amount = amount.Add(minAmount)
amount = amount.MulRaw(3) // 3x what's required // TODO: this is a hack, we need to be able to calculate the correct amount using params

if amount.GT(spendableBalance) || amount.LT(threshold) {
return nil, true, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

The error handling here is good, it checks for errors and handles them appropriately. However, the error messages could be more descriptive to provide more context about the error. For example, instead of "unable to generate deposit", you could say "unable to generate deposit in randomDeposit function". This would make it easier to debug if an error occurs.

Verified

This commit was signed with the committer’s verified signature.
facundomedica Facundo Medica
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2382262 and 3d8963c.
Files selected for processing (1)
  • x/gov/simulation/operations_test.go (3 hunks)
Additional comments: 3
x/gov/simulation/operations_test.go (3)
  • 155-155: The change in the initial deposit amount in the TestSimulateMsgSubmitProposal function from "143523282stake" to "47841094stake" is noted. Ensure that this new value is appropriate for the test scenario.

  • 188-188: The change in the initial deposit amount in the TestSimulateMsgSubmitLegacyProposal function from "75498768stake" to "25166256stake" is noted. Ensure that this new value is appropriate for the test scenario.

  • 279-279: The change in the deposit amount in the TestSimulateMsgDeposit function from "1682907stake" to "560969stake" is noted. Ensure that this new value is appropriate for the test scenario.

@julienrbrt julienrbrt removed the backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release label Nov 2, 2023
@julienrbrt
Copy link
Member

Removing the backport tag, we can cherry-pick in #18333

@julienrbrt julienrbrt added this pull request to the merge queue Nov 2, 2023
Merged via the queue into main with commit 9278b07 Nov 2, 2023
@julienrbrt julienrbrt deleted the facu/fix-sims-gov branch November 2, 2023 14:30
julienrbrt pushed a commit that referenced this pull request Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants