Skip to content

Conversation

@mbreithecker
Copy link
Member

@mbreithecker mbreithecker commented Aug 21, 2025

Summary by CodeRabbit

  • New Features

    • No user-facing features added.
  • Bug Fixes

    • Correctly initializes and exports the multi-coin rewards distribution policy from genesis, preventing inconsistent state after chain start or export/import cycles.
  • Documentation

    • Updated changelog to clarify an existing improvement and record the bug fix.
  • Tests

    • Revised tests to validate policy retrieval and empty state after invalid updates, ensuring predictable behavior without relying on retrieval errors.

@coderabbitai
Copy link

coderabbitai bot commented Aug 21, 2025

Walkthrough

Adds genesis initialization for MultiCoinDistributionPolicy in x/multi_coin_rewards, updates related tests to verify empty policy state instead of retrieval errors after invalid updates, and amends CHANGELOG with scoped module notation and a bug fix entry.

Changes

Cohort / File(s) Summary
Changelog updates
CHANGELOG.md
Scoped an existing “storage cost payout” entry to x/bundles and added a Bug Fixes section noting correct export of policy in x/multi_coin_rewards genesis.
Genesis policy initialization
x/multi_coin_rewards/genesis.go
InitGenesis now sets MultiCoinDistributionPolicy from genesis state via keeper; panics on setter error. Executed after queue state setup. Potential nil dereference if policy is nil.
Distribution policy tests
x/multi_coin_rewards/keeper/msg_server_distribution_policy_test.go
Tests now retrieve policy without expecting errors after invalid updates and assert zero entries for duplicates, negative, or zero weights.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant App
  participant Module as x/multi_coin_rewards
  participant Keeper
  participant Store

  App->>Module: InitGenesis(genState)
  Module->>Keeper: SetQueueState(...)
  Module->>Keeper: Set(MultiCoinDistributionPolicy from genState)
  alt policy provided
    Keeper->>Store: Write policy
    Store-->>Keeper: OK
    Keeper-->>Module: nil error
  else policy missing / nil
    Module->>Module: Potential nil deref (panic)
  end
  Module-->>App: Init complete (or panic)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • troykessler
  • christopherbrumm

Poem

A bunny taps the genesis drum,
Policies planted—here they come!
Tests now peek with gentle care,
Empty baskets? We’re aware.
Changelog whispers, neat and bright—
Rewards aligned, set just right.
Hippity-hop, ship it tonight! 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mbreithecker/fix-genesis-export

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
x/multi_coin_rewards/keeper/msg_server_distribution_policy_test.go (1)

211-219: “Zero weights” test uses -1 instead of 0 — fix to actually test zero.

The scenario name says “Zero weights” but the data sets the weight to -1 again. Set it to "0" so the test covers the intended case.

Apply this diff:

-							Weight: math.LegacyMustNewDecFromStr("-1"),
+							Weight: math.LegacyMustNewDecFromStr("0"),
🧹 Nitpick comments (6)
x/multi_coin_rewards/genesis.go (1)

42-47: Optional: make ExportGenesis resilient to missing policy.

Right now, export panics on any Get error. With the InitGenesis fix this should be fine, but if ExportGenesis can be called in tests before policy is set, consider treating “not found” as an empty policy while still panicking on other errors. This is optional since the InitGenesis guard already ensures presence in normal flows.

x/multi_coin_rewards/keeper/msg_server_distribution_policy_test.go (5)

129-134: Strengthen assertion: check error presence before inspecting message; keep state assertion.

Prevent potential nil dereference if the tx unexpectedly succeeds by asserting HaveOccurred() first.

Apply this diff:

-	// ASSERT
-	Expect(err.Error()).To(Equal("duplicate entry for denom acoin"))
+	// ASSERT
+	Expect(err).To(HaveOccurred())
+	Expect(err.Error()).To(Equal("duplicate entry for denom acoin"))
 	policy, err := s.App().MultiCoinRewardsKeeper.MultiCoinDistributionPolicy.Get(s.Ctx())
 	Expect(err).To(BeNil())
 	Expect(policy.Entries).To(HaveLen(0))

171-174: Repeat the nil-safety assertion for duplicate pool entries case.

Same reasoning as above.

Apply this diff:

-	// ASSERT
-	Expect(err.Error()).To(Equal("duplicate distribution weight for pool id 0"))
+	// ASSERT
+	Expect(err).To(HaveOccurred())
+	Expect(err.Error()).To(Equal("duplicate distribution weight for pool id 0"))
 	policy, err := s.App().MultiCoinRewardsKeeper.MultiCoinDistributionPolicy.Get(s.Ctx())
 	Expect(err).To(BeNil())
 	Expect(policy.Entries).To(HaveLen(0))

199-202: Repeat the nil-safety assertion for negative weights case.

Same reasoning as above.

Apply this diff:

-	// ASSERT
-	Expect(err.Error()).To(Equal("invalid weight for pool id 0"))
+	// ASSERT
+	Expect(err).To(HaveOccurred())
+	Expect(err.Error()).To(Equal("invalid weight for pool id 0"))
 	policy, err := s.App().MultiCoinRewardsKeeper.MultiCoinDistributionPolicy.Get(s.Ctx())
 	Expect(err).To(BeNil())
 	Expect(policy.Entries).To(HaveLen(0))

225-230: Repeat the nil-safety assertion for zero weights case.

Same reasoning as the other invalid policy tests.

Apply this diff:

-	// ASSERT
-	Expect(err.Error()).To(Equal("invalid weight for pool id 0"))
+	// ASSERT
+	Expect(err).To(HaveOccurred())
+	Expect(err.Error()).To(Equal("invalid weight for pool id 0"))
 	policy, err := s.App().MultiCoinRewardsKeeper.MultiCoinDistributionPolicy.Get(s.Ctx())
 	Expect(err).To(BeNil())
 	Expect(policy.Entries).To(HaveLen(0))

56-94: Nice: post-update verification checks the normalized distribution map.

Valid-case assertions look good and exercise the parsing logic. Consider also asserting a couple of exact per-denom totals to catch future normalization regressions (optional).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c530a95 and 576a51d.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • x/multi_coin_rewards/genesis.go (1 hunks)
  • x/multi_coin_rewards/keeper/msg_server_distribution_policy_test.go (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
x/multi_coin_rewards/genesis.go (1)
x/multi_coin_rewards/types/types.pb.go (3)
  • MultiCoinDistributionPolicy (162-164)
  • MultiCoinDistributionPolicy (168-168)
  • MultiCoinDistributionPolicy (169-171)
x/multi_coin_rewards/keeper/msg_server_distribution_policy_test.go (2)
app/app.go (1)
  • App (116-165)
x/multi_coin_rewards/types/types.pb.go (3)
  • MultiCoinDistributionPolicy (162-164)
  • MultiCoinDistributionPolicy (168-168)
  • MultiCoinDistributionPolicy (169-171)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Summary
  • GitHub Check: lint / golangci
  • GitHub Check: test / test
🔇 Additional comments (1)
CHANGELOG.md (1)

21-26: Changelog entry scope and placement look correct.

  • Scoped the storage payout improvement to x/bundles.
  • Added a clear Bug Fix entry for x/multi_coin_rewards.

Nothing else to change here.

@mbreithecker mbreithecker merged commit 5e5ecd0 into main Aug 22, 2025
4 checks passed
@mbreithecker mbreithecker deleted the mbreithecker/fix-genesis-export branch August 22, 2025 09:40
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