Skip to content

Conversation

@troykessler
Copy link
Member

@troykessler troykessler commented Jul 17, 2025

This PR used the native $KYVE coin first to pay for the storage cost and only uses the remaining coins if $KYVE is not enough. This results in uploaders receiving more $KYVE with which they can pay for Turbo storage fees and delegators receiving more foreign coins which they receive by staking $KYVE.

Summary by CodeRabbit

  • Bug Fixes

    • Updated reward distribution to prioritize using KYVE tokens for storage costs before other coins, resulting in adjusted commission and delegation rewards for uploaders and delegators.
    • Adjusted test cases to reflect the new storage cost handling and updated expected reward values accordingly.
  • Style

    • Improved comment formatting for better readability.

@troykessler troykessler requested a review from mbreithecker July 17, 2025 08:45
@troykessler troykessler self-assigned this Jul 17, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 17, 2025

Walkthrough

The changes update the logic for distributing storage costs in the payout process: now, the native $KYVE token is used first to cover storage costs, with other coins only used if $KYVE is insufficient. Corresponding test assertions and comments are updated to reflect this new distribution method. Proto file comment indentation is also adjusted.

Changes

File(s) Change Summary
Proto comment formatting
proto/kyve/delegation/v1beta1/tx.proto
Adjusted indentation of a multi-line comment block for consistency; no functional changes.
Storage cost payout logic
x/bundles/keeper/logic_bundles.go
Modified storage cost payout logic: $KYVE covers storage costs first, remainder split among other coins; updated calculation flow.
Test updates reflecting payout logic
x/bundles/keeper/keeper_suite_inflation_splitting_test.go,
x/bundles/keeper/keeper_suite_valid_bundles_test.go
Updated test assertions and comments to reflect new storage cost payout logic; expectations now align with $KYVE-first deduction.
Changelog update
CHANGELOG.md
Added "Unreleased" section entry noting the storage cost payout improvement with breaking change indication.

Sequence Diagram(s)

sequenceDiagram
    participant System
    participant calculatePayouts
    participant KYVE
    participant OtherCoins

    System->>calculatePayouts: Initiate payout calculation
    calculatePayouts->>KYVE: Attempt to cover storage cost using $KYVE
    alt $KYVE sufficient
        KYVE-->>calculatePayouts: Full storage cost covered
        calculatePayouts->>calculatePayouts: Distribute remaining payout
    else $KYVE insufficient
        KYVE-->>calculatePayouts: Partial storage cost covered
        calculatePayouts->>OtherCoins: Split remaining storage cost among other coins
        OtherCoins-->>calculatePayouts: Cover remainder as possible
        calculatePayouts->>calculatePayouts: Distribute remaining payout
    end
    calculatePayouts-->>System: Return final payout distribution
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

A hop, a skip, a payout shift—
Now KYVE takes the storage lift!
If more is needed, coins will share,
But KYVE’s first, it’s only fair.
With tests aligned and logic neat,
This rabbit’s work is now complete!
🐇💰

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ff72cca and 3c1f7a1.

📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
⏰ 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). (2)
  • GitHub Check: test / test
  • GitHub Check: Summary
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/improve-storage-cost

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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: 0

🧹 Nitpick comments (2)
proto/kyve/delegation/v1beta1/tx.proto (1)

11-13: Minor cosmetic change unrelated to PR objective.

This indentation change from 2 spaces to 3 spaces is purely cosmetic and doesn't relate to the storage cost distribution improvements described in the PR. Consider whether this formatting change is necessary or if it should be part of a separate formatting-focused PR.

x/bundles/keeper/logic_bundles.go (1)

293-331: Complex but correct remaining storage cost distribution.

The logic correctly handles distributing remaining storage costs (after $KYVE contribution) among other coins. The implementation:

  • Properly separates $KYVE from remaining coins
  • Distributes remaining USD storage cost equally among coins
  • Correctly converts USD amounts to each coin's denomination
  • Uses Min() to prevent over-charging when insufficient funds

The early returns prevent processing when funds are exhausted, which is appropriate.

Consider extracting the storage cost calculation logic into separate helper functions to improve readability and testability of this complex mathematical logic.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 81d60e0 and 9ac707e.

📒 Files selected for processing (4)
  • proto/kyve/delegation/v1beta1/tx.proto (1 hunks)
  • x/bundles/keeper/keeper_suite_inflation_splitting_test.go (2 hunks)
  • x/bundles/keeper/keeper_suite_valid_bundles_test.go (1 hunks)
  • x/bundles/keeper/logic_bundles.go (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
x/bundles/keeper/keeper_suite_valid_bundles_test.go (1)
Learnt from: troykessler
PR: KYVENetwork/chain#211
File: x/stakers/keeper/exported_functions.go:334-342
Timestamp: 2024-12-20T08:52:36.443Z
Learning: The `GetValidatorPoolStakes()` method ensures that the effective stake cannot exceed the validator's total bonded tokens, so no additional check is necessary.
x/bundles/keeper/logic_bundles.go (1)
Learnt from: troykessler
PR: KYVENetwork/chain#244
File: x/multi_coin_rewards/keeper/exported.go:19-23
Timestamp: 2025-02-11T09:41:10.529Z
Learning: When handling errors in reward distribution, prefer returning all rewards as a fallback to prevent potential loss of funds, rather than restricting to native rewards only.
⏰ 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). (1)
  • GitHub Check: test / test
🔇 Additional comments (6)
x/bundles/keeper/logic_bundles.go (3)

260-291: Well-implemented $KYVE-first storage cost logic.

The implementation correctly prioritizes native $KYVE tokens for storage costs as described in the PR objective. The logic properly:

  • Calculates storage cost in USD terms
  • Converts to $KYVE amount using coin weight and currency unit
  • Takes the minimum of available $KYVE and required storage cost
  • Handles the early return case when payout is exhausted

The mathematical calculations appear correct and the approach aligns with the PR's goal of increasing $KYVE token usage for storage fees.


313-320: Correct currency conversion mathematics.

The currency conversion logic properly handles the complex calculation from USD storage cost to individual coin amounts:

  • Correctly calculates currency unit as 10^decimals for base denomination
  • Proper USD-to-coin conversion using weight
  • Appropriate truncation to integer for token amounts
  • Correctly skips $KYVE (already processed) and zero-weight coins

The mathematical approach is sound and handles the multi-currency storage cost distribution correctly.


322-331: Conservative approach prevents fund loss.

The implementation uses Min() to ensure storage rewards don't exceed available payout, which aligns with the retrieved learning about preventing fund loss. The early return when totalPayout.IsZero() prevents potential issues in subsequent commission/delegation calculations.

This conservative approach is appropriate given the critical nature of reward distribution logic.

x/bundles/keeper/keeper_suite_inflation_splitting_test.go (2)

1515-1529: Well-documented test updates reflecting new storage cost logic.

The test assertions have been correctly updated to reflect the $KYVE-first storage cost approach. The comprehensive comments explaining the changes and preserving previous expected values for reference demonstrate good testing practices.

The new expected values correctly show:

  • Higher $KYVE amounts for uploader commission (778 vs 748)
  • Lower amounts for other coins (990 vs 1004 acoin, 1980 vs 1987 bcoin)
  • Complementary changes in delegator rewards

This aligns perfectly with the PR objective of increasing $KYVE token usage for storage fees.


1634-1648: Consistent test updates for 100% inflation splitting scenario.

The test assertions for the 100% inflation splitting scenario have been updated consistently with the same $KYVE-first approach. The documentation follows the same high-quality pattern as the 10% test case.

The expected value changes show the same behavior pattern:

  • Higher $KYVE for uploader commission (2492 vs 2461)
  • Lower amounts for other coins (same acoin/bcoin values as 10% test)
  • Appropriate delegator reward adjustments

The consistency across different inflation scenarios demonstrates thorough testing of the new storage cost distribution logic.

x/bundles/keeper/keeper_suite_valid_bundles_test.go (1)

1960-1972: Updated test assertions correctly reflect the new storage cost distribution logic.

The test comments and assertions have been properly updated to reflect the change where $KYVE is now prioritized for storage cost coverage. The comments clearly explain:

  1. Commission rewards: Higher $KYVE amounts for uploaders since $KYVE covers storage costs first
  2. Self delegation rewards: Lower $KYVE amounts for delegators since more $KYVE is allocated to commission rewards
  3. The "VALUES BEFORE" comments provide helpful context for the change

The updated expected values in the test assertions are consistent with this new distribution logic where native $KYVE tokens are used first to cover storage costs, with other coins only used if $KYVE is insufficient.

@mbreithecker mbreithecker merged commit c530a95 into main Jul 30, 2025
4 checks passed
@mbreithecker mbreithecker deleted the chore/improve-storage-cost branch July 30, 2025 13: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.

3 participants