Skip to content

fix: deduct region delegate interest when settlement interest#1394

Merged
jackz1024 merged 4 commits into
mainfrom
fix/region-interest
Jun 25, 2026
Merged

fix: deduct region delegate interest when settlement interest#1394
jackz1024 merged 4 commits into
mainfrom
fix/region-interest

Conversation

@jackz1024

@jackz1024 jackz1024 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • KYC reward settlement now validates “sufficient delegate interest” earlier and returns explicit errors when coverage is insufficient.
    • Reward settlement now deducts the required interest up front before sending settlement coins, avoiding inconsistent partial settlement behavior.
    • Unregistration KYC now errors out when delegate interest is too low instead of continuing with subsequent settlement logic.
  • Tests

    • Updated KYC region transfer tests to initialize the staking module at the correct block height.
    • Updated KYC update message server tests to begin staking during the updated block height.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6a7c7be5-5e20-4905-9a56-0aa60ddda30e

📥 Commits

Reviewing files that changed from the base of the PR and between 54444b2 and daa8880.

📒 Files selected for processing (2)
  • x/kyc/keeper/msg_server_test.go
  • x/wstaking/keeper/kyc_reward.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • x/kyc/keeper/msg_server_test.go
  • x/wstaking/keeper/kyc_reward.go

📝 Walkthrough

Walkthrough

KYC reward settlement now rejects insufficient DelegateInterest before payout in three keeper paths. Two tests also initialize staking block state before asserting next-block delegation behavior.

Changes

KYC Reward Interest Guard

Layer / File(s) Summary
DelegateInterest checks in reward settlement
x/wstaking/keeper/kyc_reward.go
RemoveKycReward, sendKycRewards, and transferUnRegisterMeid now return formatted errors when DelegateInterest is insufficient, and sendKycRewards uses experienceRegion.RegionId in its settlement tag.

Staking BeginBlock in region transfer test

Layer / File(s) Summary
Staking BeginBlock in region transfer test
x/wstaking/keeper/kyc_region_test.go, x/kyc/keeper/msg_server_test.go
Both tests import x/wstaking and call wstaking.BeginBlock after wmint.BeginBlocker before the next-block assertions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Suggested reviewers

  • koelzen
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning No description was provided, so the required Summary, Related Issues, Validation, and Checklist sections are missing. Add the template sections and fill in the change summary, issue reference, type, validation, checklist, and breaking-change notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main behavior change: deducting region delegate interest during settlement.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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/region-interest

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

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
x/wstaking/keeper/kyc_reward.go (1)

113-114: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Normalize the new error strings to Uber Go style.

These new errors start with function/camel-case names. Prefer lower-case, message-oriented strings.

Example wording update
-		return fmt.Errorf("RemoveKycReward err,region(%s) total interest not enough.need pay %s,only have %s",
+		return fmt.Errorf("remove kyc reward: region %s total interest not enough: need %s, have %s",

-			return fmt.Errorf("sendKycRewards err,region(%s) total interest not enough.need pay %s,only have %s",
+			return fmt.Errorf("send kyc rewards: region %s total interest not enough: need %s, have %s",

-		return amount, fmt.Errorf("transferUnRegisterMeid err,region(%s) total interest not enough.need pay %s,only have %s",
+		return amount, fmt.Errorf("transfer unregister meid: region %s total interest not enough: need %s, have %s",

As per path instructions, "**/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations."

Also applies to: 196-198, 445-446

🤖 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/wstaking/keeper/kyc_reward.go` around lines 113 - 114, The new error string
in RemoveKycReward should be normalized to Uber Go style by removing the
function/camel-case prefix and making it a lower-case, message-oriented
sentence. Update the fmt.Errorf message in RemoveKycReward, and apply the same
style cleanup to the other newly added error strings at the referenced locations
so all errors read naturally and consistently.

Source: Path instructions

🤖 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.

Inline comments:
In `@x/wstaking/keeper/kyc_reward.go`:
- Around line 110-115: The RemoveKycReward flow is subtracting the same rewards
twice from region.DelegateInterest, first in the guarded block and again later
after the transfer. Update RemoveKycReward in kyc_reward.go so the deduction
happens only once, and remove or refactor the later DelegateInterest subtraction
path to reuse the already-updated balance while keeping the existing GTE balance
check.

---

Nitpick comments:
In `@x/wstaking/keeper/kyc_reward.go`:
- Around line 113-114: The new error string in RemoveKycReward should be
normalized to Uber Go style by removing the function/camel-case prefix and
making it a lower-case, message-oriented sentence. Update the fmt.Errorf message
in RemoveKycReward, and apply the same style cleanup to the other newly added
error strings at the referenced locations so all errors read naturally and
consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: a3632d19-1e36-4405-b1d7-5ae921180e73

📥 Commits

Reviewing files that changed from the base of the PR and between 00657f7 and dc62f13.

📒 Files selected for processing (1)
  • x/wstaking/keeper/kyc_reward.go

Comment thread x/wstaking/keeper/kyc_reward.go Outdated
@jackz1024 jackz1024 changed the title Deduct region delegate interest when settlement interest fix: deduct region delegate interest when settlement interest Jun 24, 2026

@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/wstaking/keeper/kyc_region_test.go (1)

63-64: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a guard-failure test for insufficient DelegateInterest.

This covers the happy path after wstaking.BeginBlock, but not the new insufficient-interest failure contract. Add a companion case that skips interest accrual (or forces low interest), expects TransferKycRegion to fail, and verifies no state mutation.

Proposed test shape
 func (s *KeeperTestSuite) TestTransferKycRegion() {
+  s.Run("fails when source region interest is insufficient", func() {
+    s.SetupTest()
+    // Arrange identical setup, but do NOT call wstaking.BeginBlock on the transfer block.
+    // Act: call TransferKycRegion(...)
+    // Assert: require.Error(err) and delegation/region balances unchanged.
+  })
+
   // existing happy-path test...
 }

As per path instructions, "**/*_test.go: Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request."

🤖 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/wstaking/keeper/kyc_region_test.go` around lines 63 - 64, Add a companion
test in kyc_region_test.go around wstaking.BeginBlock that exercises the
insufficient DelegateInterest path: set up the same TransferKycRegion scenario
but skip interest accrual or force the balance below the required threshold,
then assert TransferKycRegion returns an error and that no state changes
occurred. Use the existing kyc region test helpers and the relevant
TransferKycRegion / BeginBlock flow to locate the coverage gap.

Source: Path instructions

🤖 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/wstaking/keeper/kyc_region_test.go`:
- Around line 63-64: Add a companion test in kyc_region_test.go around
wstaking.BeginBlock that exercises the insufficient DelegateInterest path: set
up the same TransferKycRegion scenario but skip interest accrual or force the
balance below the required threshold, then assert TransferKycRegion returns an
error and that no state changes occurred. Use the existing kyc region test
helpers and the relevant TransferKycRegion / BeginBlock flow to locate the
coverage gap.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 02ee3a9d-5b24-4d07-b2e0-9960cfda11c3

📥 Commits

Reviewing files that changed from the base of the PR and between dc62f13 and 34efd99.

📒 Files selected for processing (1)
  • x/wstaking/keeper/kyc_region_test.go

@jackz1024 jackz1024 merged commit d5a53db into main Jun 25, 2026
7 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.

1 participant