Skip to content

fix(mstaking): bound redelegation slash by remaining amount#524

Merged
traviolus merged 2 commits into
mainfrom
fix/redelegation-slash
Jun 8, 2026
Merged

fix(mstaking): bound redelegation slash by remaining amount#524
traviolus merged 2 commits into
mainfrom
fix/redelegation-slash

Conversation

@traviolus

Copy link
Copy Markdown
Contributor

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, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • 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 all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

@traviolus
traviolus requested a review from a team as a code owner June 4, 2026 09:03
@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4b15c8c7-68dc-4fb7-8053-3bf7a865487b

📥 Commits

Reviewing files that changed from the base of the PR and between 587e57b and cae7ee8.

📒 Files selected for processing (2)
  • x/mstaking/keeper/slash.go
  • x/mstaking/keeper/slash_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • x/mstaking/keeper/slash.go

📝 Walkthrough

Walkthrough

Modified SlashRedelegation to bound destination unbond shares by the remaining slash obligation, preventing double-counting when redelegate is followed by undelegate and then slash. Added test validating this edge case where unbonding delegation is absorbed during slashing of the source validator.

Changes

SlashRedelegation Double-Counting Fix

Layer / File(s) Summary
Bounded sharesToUnbond calculation in SlashRedelegation
x/mstaking/keeper/slash.go
SlashRedelegation now re-fetches the destination validator early and derives remainingShares from the current remaining slashAmount using truncated conversion. sharesToUnbond is bounded by intersecting the scaled destination shares with remainingShares. After k.Unbond, the validator is re-read again to account for status changes before burn aggregation.
Test for redelegate-undelegate-slash flow
x/mstaking/keeper/slash_test.go
Test_SlashRedelegation_UndelegateAfterRedelegate validates the fix by setting up redelegation, partial undelegation from destination, slashing the source validator, and verifying the unbonding delegation is absorbed to zero and bonded shares are reduced as expected.

🎯 3 (Moderate) | ⏱️ ~20 minutes

A delegator dances between validators with care,
Redelegate, undelegate—a tangled affair,
But now the slash knows its proper bound,
No double-counting, the fix is sound! 🐰✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description is a template with unchecked checklists and placeholder text (Closes: #XXXX) but is generic rather than being completely unrelated to the changeset. It includes structural elements relevant to PRs but lacks concrete details about the actual changes. Provide a meaningful description explaining the bug being fixed, why the changes were necessary, and which files are critical to review instead of relying solely on the template.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(mstaking): bound redelegation slash by remaining amount' is specific and clearly related to the main change in the pull request, which bounds redelegation slash amounts by the remaining slash obligation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/redelegation-slash

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
x/mstaking/keeper/slash_test.go (1)

103-107: 💤 Low value

Consider clarifying the test documentation.

The comment mixes describing the current behavior with the old buggy behavior ("used to be slashed"), which is a bit confusing. Consider rewording:

-// Test_SlashRedelegation_UndelegateAfterRedelegate is a test for SlashRedelegation
-// when a delegator redelegates and then partially undelegates from the
-// destination validator, the destination-side unbonding delegation is slashed
-// AND the still-bonded delegation used to be slashed for the full `SharesDst * slashFactor`.
+// Test_SlashRedelegation_UndelegateAfterRedelegate verifies that SlashRedelegation
+// bounds the delegation-side slash by the remaining amount after the unbonding
+// delegation absorbs part of the slash. Previously, the still-bonded delegation
+// was slashed for the full `SharesDst * slashFactor`, causing double-counting.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@x/mstaking/keeper/slash_test.go` around lines 103 - 107, Update the test
comment for Test_SlashRedelegation_UndelegateAfterRedelegate to remove ambiguous
phrasing about past buggy behavior and clearly describe the expected behavior:
state that when a delegator redelegates and then partially undelegates from the
destination validator, the destination-side unbonding delegation is slashed and
the remaining bonded delegation is slashed by SharesDst * slashFactor (i.e.,
describe current expected outcome rather than saying "used to be slashed").
Ensure the function name Test_SlashRedelegation_UndelegateAfterRedelegate is
referenced in the comment for clarity.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@x/mstaking/keeper/slash_test.go`:
- Around line 103-107: Update the test comment for
Test_SlashRedelegation_UndelegateAfterRedelegate to remove ambiguous phrasing
about past buggy behavior and clearly describe the expected behavior: state that
when a delegator redelegates and then partially undelegates from the destination
validator, the destination-side unbonding delegation is slashed and the
remaining bonded delegation is slashed by SharesDst * slashFactor (i.e.,
describe current expected outcome rather than saying "used to be slashed").
Ensure the function name Test_SlashRedelegation_UndelegateAfterRedelegate is
referenced in the comment for clarity.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5394b7bf-498f-4e2b-85b3-0fa07b3bee20

📥 Commits

Reviewing files that changed from the base of the PR and between aa074b0 and 587e57b.

📒 Files selected for processing (2)
  • x/mstaking/keeper/slash.go
  • x/mstaking/keeper/slash_test.go

@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.44%. Comparing base (aa074b0) to head (cae7ee8).

Files with missing lines Patch % Lines
x/mstaking/keeper/slash.go 40.00% 4 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #524      +/-   ##
==========================================
+ Coverage   38.41%   38.44%   +0.02%     
==========================================
  Files         327      327              
  Lines       30685    30693       +8     
==========================================
+ Hits        11789    11801      +12     
+ Misses      17006    16999       -7     
- Partials     1890     1893       +3     
Files with missing lines Coverage Δ
x/mstaking/keeper/slash.go 49.04% <40.00%> (+4.37%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread x/mstaking/keeper/slash.go

@beer-1 beer-1 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.

LGTM

@traviolus
traviolus merged commit 0f29b42 into main Jun 8, 2026
14 checks passed
@traviolus
traviolus deleted the fix/redelegation-slash branch June 8, 2026 06:51
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.

2 participants