Skip to content

Handle panic in addition of error recovery of PSE#110

Merged
TxCorpi0x merged 3 commits into
masterfrom
mehdi/panic-recovery-pse-distribution
Mar 24, 2026
Merged

Handle panic in addition of error recovery of PSE#110
TxCorpi0x merged 3 commits into
masterfrom
mehdi/panic-recovery-pse-distribution

Conversation

@TxCorpi0x

@TxCorpi0x TxCorpi0x commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

Description

This pull request enhances error handling and test coverage for the distribution end block logic in the x/pse module. 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:

  • The EndBlock method in AppModule now 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 the DistributionDisabled flag.

Test Coverage Enhancements:

  • The TestDistribution_EndBlockFailure test 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:

  • The signature of EndBlock is updated to explicitly name the return variable for better error handling with deferred functions.

Reviewers checklist:

  • Try to write more meaningful comments with clear actions to be taken.
  • Nit-picking should be unblocking. Focus on core issues.

Authors checklist

  • Provide a concise and meaningful description
  • Review the code yourself first, before making the PR.
  • Annotate your PR in places that require explanation.
  • Think and try to split the PR to smaller PR if it is big.

This change is Reviewable

@TxCorpi0x TxCorpi0x requested a review from a team as a code owner March 18, 2026 14:51
@TxCorpi0x TxCorpi0x requested review from akhlopiachyi, masihyeganeh, metalarm10, miladz68 and ysv and removed request for a team March 18, 2026 14:51

@metalarm10 metalarm10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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 TxCorpi0x left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@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 of IsPositive() , stricter test approach might be using Equal(allocationAmount) here as well, like the panic subtest does.

Done

@metalarm10 metalarm10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@metalarm10 reviewed 2 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on akhlopiachyi, masihyeganeh, miladz68, and ysv).

@ysv ysv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ysv reviewed 2 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on akhlopiachyi, masihyeganeh, and miladz68).

@TxCorpi0x TxCorpi0x merged commit 08c542b into master Mar 24, 2026
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants