Handle panic in addition of error recovery of PSE#110
Conversation
metalarm10
left a comment
There was a problem hiding this comment.
@metalarm10 made 1 comment.
Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on akhlopiachyi, masihyeganeh, miladz68, TxCorpi0x, and ysv).
x/pse/keeper/distribution_test.go line 815 at r1 (raw file):
} moduleAddr := testApp.AccountKeeper.GetModuleAddress(mapping.ClearingAccount) requireT.True(bankKeeper.GetBalance(ctx, moduleAddr, bondDenom).Amount.IsPositive(),
nit: In this case every clearing account should have exactly initial allocationAmount, so instead of IsPositive() , stricter test approach might be using Equal(allocationAmount) here as well, like the panic subtest does.
TxCorpi0x
left a comment
There was a problem hiding this comment.
@TxCorpi0x made 1 comment and resolved 1 discussion.
Reviewable status: 0 of 2 files reviewed, all discussions resolved (waiting on akhlopiachyi, masihyeganeh, miladz68, and ysv).
x/pse/keeper/distribution_test.go line 815 at r1 (raw file):
Previously, metalarm10 wrote…
nit: In this case every clearing account should have exactly initial
allocationAmount, so instead ofIsPositive(), stricter test approach might be usingEqual(allocationAmount)here as well, like the panic subtest does.
Done
metalarm10
left a comment
There was a problem hiding this comment.
@metalarm10 reviewed 2 files and all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on akhlopiachyi, masihyeganeh, miladz68, and ysv).
ysv
left a comment
There was a problem hiding this comment.
@ysv reviewed 2 files and all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on akhlopiachyi, masihyeganeh, and miladz68).
Description
This pull request enhances error handling and test coverage for the distribution end block logic in the
x/psemodule. The most notable changes include improved handling of panics in the end blocker, more robust unit tests for error scenarios, and some minor refactoring for clarity.Error Handling Improvements:
EndBlockmethod inAppModulenow uses a deferred function to catch panics during distribution processing. If a panic occurs, it logs the error and disables all future distributions by setting theDistributionDisabledflag.Test Coverage Enhancements:
TestDistribution_EndBlockFailuretest now includes two subtests:"transfer_error": Verifies that if a clearing account (e.g., team) is unfunded, the distribution fails gracefully and disables further distributions, with all recipient balances remaining zero and clearing accounts retaining their funds. [1] [2] [3] [4]"panic_invalid_recipient": Simulates a panic caused by an invalid recipient address in the distribution parameters, ensuring the system disables distributions and leaves account balances unchanged.Minor Refactoring:
EndBlockis updated to explicitly name the return variable for better error handling with deferred functions.Reviewers checklist:
Authors checklist
This change is