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

(Backport) fix(x/gov): let hooks return an error #514

Merged
merged 4 commits into from
Mar 9, 2024

Conversation

mattverse
Copy link
Member

@mattverse mattverse commented Feb 6, 2024

Description

Backport of upstream PR#18173, upstream PR cosmos#19305

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)

Summary by CodeRabbit

  • Refactor
    • Improved error handling in governance processes, including deposit, proposal submission, and voting phases.
  • Tests
    • Updated mock governance hooks to align with new error handling protocols.
  • Chores
    • Enhanced governance hooks interface for more robust error management.

@czarcas7ic czarcas7ic changed the base branch from osmo-v22/v0.47.5 to osmo/v0.47.5 February 8, 2024 19:25
@mattverse
Copy link
Member Author

@czarcas7ic should this be good to go ahead and merge?

Copy link

coderabbitai bot commented Mar 8, 2024

Walkthrough

This update enhances error handling across various governance-related functions within the codebase. It introduces modifications to ensure that errors in hooks execution are properly handled and returned, improving the robustness and reliability of the governance process. The changes span across the EndBlocker, AddDeposit, SubmitProposal, and AddVote functions, alongside updates to the GovHooks interface and tests to align with the new error handling approach.

Changes

Files Change Summary
x/gov/abci.go, .../keeper/deposit.go, .../keeper/proposal.go, .../keeper/vote.go Enhanced error handling in EndBlocker, AddDeposit, SubmitProposal, and AddVote functions.
x/gov/keeper/hooks_test.go Updated MockGovHooksReceiver functions to explicitly return nil.
x/gov/types/expected_keepers.go, x/gov/types/hooks.go Updated GovHooks interface and implemented error handling with JoinErrors in MultiGovHooks.

🐰✨
In a land of code and bytes, where governance reigns,
A rabbit hopped, spreading updates, easing pains.
"No more silent errors," it cheerfully claims,
Through proposals and votes, it aims.
With a hop, skip, and a jump, errors it tames,
In the blockchain world, it leaves its marks, not just names.
🌟🐇

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@czarcas7ic czarcas7ic merged commit c2363b6 into osmo/v0.47.5 Mar 9, 2024
7 of 13 checks passed
@czarcas7ic czarcas7ic deleted the mattverse/bpt-4 branch March 9, 2024 04:42
Copy link

@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 8d82953 and 16afd97.
Files selected for processing (8)
  • CHANGELOG.md (1 hunks)
  • x/gov/abci.go (2 hunks)
  • x/gov/keeper/deposit.go (1 hunks)
  • x/gov/keeper/hooks_test.go (1 hunks)
  • x/gov/keeper/proposal.go (1 hunks)
  • x/gov/keeper/vote.go (1 hunks)
  • x/gov/types/expected_keepers.go (1 hunks)
  • x/gov/types/hooks.go (1 hunks)
Additional comments: 13
x/gov/types/hooks.go (5)
  • 16-21: The implementation of AfterProposalSubmission in MultiGovHooks correctly aggregates errors from multiple hooks using JoinErrors. This approach ensures that errors from all hooks are collected and returned, enhancing error handling in the governance module.
  • 24-29: The AfterProposalDeposit method in MultiGovHooks follows the same pattern as AfterProposalSubmission, aggregating errors from multiple hooks. This consistent approach to error handling across hook methods is commendable for maintainability and readability.
  • 32-37: The AfterProposalVote method in MultiGovHooks also aggregates errors from multiple hooks using JoinErrors. This consistent error handling strategy across different hook methods ensures that the governance module's robustness is maintained.
  • 40-45: The implementation of AfterProposalFailedMinDeposit in MultiGovHooks aggregates errors from multiple hooks, similar to other hook methods. This approach ensures that the governance module can handle errors from multiple hooks effectively.
  • 56-90: The JoinErrors function and the joinError type provide a comprehensive solution for aggregating multiple errors into a single error. This implementation is particularly useful for handling errors from multiple hooks in the governance module. The use of a slice to store errors and the custom Error method implementation for joinError ensure that all errors are preserved and can be easily accessed.
x/gov/types/expected_keepers.go (1)
  • 59-63: Updating the GovHooks interface methods to return an error is a significant improvement for error handling within the governance module. This change allows for better control and handling of errors that may occur during the execution of governance hooks, enhancing the module's robustness and reliability.
x/gov/keeper/hooks_test.go (1)
  • 28-50: The modifications to the MockGovHooksReceiver struct methods to return an error and explicitly return nil align with the changes made to the GovHooks interface. This ensures that the test receiver is consistent with the interface it mocks, facilitating accurate and meaningful testing of the governance module's hooks. Explicitly returning nil in each method clearly communicates the intended behavior in test scenarios.
x/gov/keeper/vote.go (1)
  • 35-38: The addition of error handling for the AfterProposalVote hook in the AddVote function is a crucial improvement. This ensures that errors encountered during the execution of the hook are not ignored and are properly propagated up the call stack, allowing for appropriate handling or logging. This change enhances the reliability and robustness of the vote addition process in the governance module.
x/gov/abci.go (2)
  • 33-39: The use of a caching context (cacheCtx) and the conditional write-back pattern (writeCache()) in the EndBlocker function for the AfterProposalFailedMinDeposit hook execution is a prudent approach. It ensures that state changes are only committed if no errors occur during the hook execution. Additionally, logging the error without halting the chain is a sensible decision, as it prevents a single failure from disrupting the entire chain's operation.
  • 151-157: Similarly, the handling of the AfterProposalVotingPeriodEnded hook in the EndBlocker function follows the same cautious approach as the AfterProposalFailedMinDeposit hook. Using a caching context and conditional write-back ensures that state changes are committed only if the hook executes successfully. Logging errors without halting the chain maintains the chain's stability while still acknowledging the occurrence of errors.
x/gov/keeper/deposit.go (1)
  • 151-154: Introducing error handling for the AfterProposalDeposit hook in the AddDeposit function is a significant enhancement. This ensures that errors encountered during the execution of the hook are properly handled, enhancing the reliability of the deposit addition process. It's crucial for maintaining the integrity of the governance module's operations.
x/gov/keeper/proposal.go (1)
  • 98-101: Adding error handling for the AfterProposalSubmission hook in the SubmitProposal function is a critical improvement. This change ensures that errors during the hook execution are not ignored, enhancing the proposal submission process's reliability. Proper error handling is essential for maintaining the governance module's robustness.
CHANGELOG.md (1)
  • 43-43: The change log entry clearly documents the update allowing governance hooks to return an error. This is a significant update for the gov module and is correctly placed under the "Unreleased" section.

It might be helpful to specify that this change affects all hooks within the gov module to ensure clarity for readers unfamiliar with the specifics of the module's implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants