Skip to content

fix(mstaking): detect zero-token exchange rates#526

Merged
beer-1 merged 1 commit into
mainfrom
fix/mstaking-invalid-exrate
Jun 10, 2026
Merged

fix(mstaking): detect zero-token exchange rates#526
beer-1 merged 1 commit into
mainfrom
fix/mstaking-invalid-exrate

Conversation

@beer-1

@beer-1 beer-1 commented Jun 9, 2026

Copy link
Copy Markdown
Member

Description

Closes: 0xWeb3boy/Initia-Move-Bug#1

Update Validator.InvalidExRate() to detect the zero-token exchange-rate state by iterating delegator shares instead of validator tokens. sdk.Coins drops zero-amount denoms, so a fully removed token balance is represented by an absent denom rather than a 0 coin entry.

This keeps the guard aligned with the condition it is meant to catch: positive outstanding shares for a denom whose validator token balance is zero.

Validation:

  • go test ./x/mstaking/types -run TestInvalidExRate -count=1
  • go test ./x/mstaking/types -count=1

Breaking change: no.


Author Checklist

I have...

  • included the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change: not applicable
  • targeted the correct branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary: not applicable
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code: not applicable
  • confirmed all CI checks have passed

Reviewers Checklist

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

@coderabbitai

coderabbitai Bot commented Jun 9, 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: 66e1cad3-aa44-4ad0-acaa-b1b2be43a06b

📥 Commits

Reviewing files that changed from the base of the PR and between 0f29b42 and b4ff7ba.

📒 Files selected for processing (2)
  • x/mstaking/types/validator.go
  • x/mstaking/types/validator_test.go

📝 Walkthrough

Walkthrough

This PR updates the Validator.InvalidExRate() method to correctly detect invalid exchange rates by iterating over delegator shares instead of tokens, checking whether positive shares exist for denoms with zero token balance. A corresponding unit test validates the updated behavior.

Changes

Invalid Exchange Rate Detection

Layer / File(s) Summary
InvalidExRate logic and test
x/mstaking/types/validator.go, x/mstaking/types/validator_test.go
Validator.InvalidExRate() iterates over DelegatorShares and returns true when a positive share amount exists for a denom where the validator's token balance is zero. Test verifies the method returns false on a newly created validator and true after all tokens are removed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 When shares dance freely with no tokens to show,
The validator's exchange rate will steal the show!
A swift iteration, a balance to seek—
Invalid rates caught, the ledger's critique.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: updating InvalidExRate() to detect zero-token exchange rates, which is the core fix in the validator.go modifications.
Description check ✅ Passed The description is directly related to the changeset, explaining the rationale for the InvalidExRate() fix, the underlying issue with sdk.Coins dropping zero denoms, and providing validation steps.
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/mstaking-invalid-exrate

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 9, 2026

Copy link
Copy Markdown
Contributor

Dependency Review

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

Scanned Files

None

@beer-1 beer-1 marked this pull request as ready for review June 9, 2026 04:40
@beer-1 beer-1 requested a review from a team as a code owner June 9, 2026 04:40
@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 38.46%. Comparing base (aa074b0) to head (b4ff7ba).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #526      +/-   ##
==========================================
+ Coverage   38.41%   38.46%   +0.04%     
==========================================
  Files         327      327              
  Lines       30685    30693       +8     
==========================================
+ Hits        11789    11807      +18     
+ Misses      17006    16993      -13     
- Partials     1890     1893       +3     
Files with missing lines Coverage Δ
x/mstaking/types/validator.go 53.76% <100.00%> (+1.61%) ⬆️

... and 2 files with indirect coverage changes

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

@traviolus traviolus 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

@beer-1 beer-1 merged commit fbed5d1 into main Jun 10, 2026
14 checks passed
@beer-1 beer-1 deleted the fix/mstaking-invalid-exrate branch June 10, 2026 09:48
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