-
Notifications
You must be signed in to change notification settings - Fork 34
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
Conversation
…-ics-lsm branch (cosmos#19305)
8992442
to
e95dddd
Compare
@czarcas7ic should this be good to go ahead and merge? |
WalkthroughThis 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 Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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
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
inMultiGovHooks
correctly aggregates errors from multiple hooks usingJoinErrors
. This approach ensures that errors from all hooks are collected and returned, enhancing error handling in the governance module.- 24-29: The
AfterProposalDeposit
method inMultiGovHooks
follows the same pattern asAfterProposalSubmission
, 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 inMultiGovHooks
also aggregates errors from multiple hooks usingJoinErrors
. This consistent error handling strategy across different hook methods ensures that the governance module's robustness is maintained.- 40-45: The implementation of
AfterProposalFailedMinDeposit
inMultiGovHooks
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 thejoinError
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 customError
method implementation forjoinError
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 anerror
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 anerror
and explicitly returnnil
align with the changes made to theGovHooks
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 returningnil
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 theAddVote
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 theEndBlocker
function for theAfterProposalFailedMinDeposit
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 theEndBlocker
function follows the same cautious approach as theAfterProposalFailedMinDeposit
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 theAddDeposit
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 theSubmitProposal
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.
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...
!
to the type prefix if API or client breaking changeCHANGELOG.md
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...
!
in the type prefix if API or client breaking changeSummary by CodeRabbit