Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(streamer): don't distribute abstained part of sponsored distribution #1097

Merged
merged 1 commit into from
Aug 15, 2024

Conversation

keruch
Copy link
Contributor

@keruch keruch commented Aug 13, 2024

Description

Don't distribute the abstained part of the sponsored distribution.


Closes #1095

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.

PR review checkboxes:

I have...

  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Targeted PR against the correct branch
  • included the correct type prefix in the PR title
  • Linked to the GitHub issue with discussion and accepted design
  • Targets only one GitHub issue
  • Wrote unit and integration tests
  • Wrote relevant migration scripts if necessary
  • All CI checks have passed
  • Added relevant godoc comments
  • Updated the scripts for local run, e.g genesis_config_commands.sh if the PR changes parameters
  • Add an issue in the e2e-tests repo if necessary

SDK Checklist

  • Import/Export Genesis
  • Registered Invariants
  • Registered Events
  • Updated openapi.yaml
  • No usage of go map
  • No usage of time.Now()
  • Used fixed point arithmetic and not float arithmetic
  • Avoid panicking in Begin/End block as much as possible
  • No unexpected math Overflow
  • Used sendCoin and not SendCoins
  • Out-of-block compute is bounded
  • No serialized ID at the end of store keys
  • UInt to byte conversion should use BigEndian

Full security checklist here


For Reviewer:

  • Confirmed the correct type prefix in the PR title
  • Reviewers assigned
  • Confirmed all author checklist items have been addressed

After reviewer approval:

  • In case the PR targets the main branch, PR should not be squash merge in order to keep meaningful git history.
  • In case the PR targets a release branch, PR must be rebased.

Summary by CodeRabbit

  • New Features

    • Simplified weight calculation in the distribution function for better performance and clarity.
    • Introduced a comprehensive test suite for the DistrInfoFromDistribution function to ensure accuracy and reliability.
  • Bug Fixes

    • Enhanced logic to handle various distribution scenarios, including empty and multi-gauge distributions.
  • Documentation

    • Updated comments for clarity concerning the new weight calculation process.

@keruch keruch added the c:sponsorship x/sponsorship module label Aug 13, 2024
@keruch keruch self-assigned this Aug 13, 2024
@keruch keruch requested a review from a team as a code owner August 13, 2024 16:30
Copy link
Contributor

coderabbitai bot commented Aug 13, 2024

Walkthrough

The changes streamline the DistrInfoFromDistribution function by removing unnecessary calculations related to weight assignment and abstained voting power. The logic now assigns weights directly based on gauge power and adjusts total weight calculations to be directly based on voting power, enhancing clarity and efficiency. A new test suite has been introduced to ensure robust validation of this updated functionality, addressing various scenarios including abstained gauges.

Changes

Files Change Summary
x/streamer/types/distr_info.go, x/streamer/types/distr_info_test.go Modified DistrInfoFromDistribution for simplified weight calculation and total weight assignment; added comprehensive tests.

Assessment against linked issues

Objective Addressed Explanation
Change the distribution logic if some part of the sponsored stream is abstained (#1095)

🐰 In the meadow where choices prevail,
The weights of the gauges now tell a new tale.
With power direct, and no math to confound,
Our DYM flows freely, with joy all around!
A hop and a skip, the records align,
Thanks to fresh tests, our code’s simply divine! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @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.

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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c0216b0 and 2ce2f0c.

Files selected for processing (2)
  • x/streamer/types/distr_info.go (2 hunks)
  • x/streamer/types/distr_info_test.go (1 hunks)
Additional comments not posted (5)
x/streamer/types/distr_info.go (1)

38-50: Simplified Distribution Logic Looks Good!

The changes to DistrInfoFromDistribution simplify the logic by directly assigning g.Power to Weight and using d.VotingPower for TotalWeight. This aligns with the PR objective of preventing redistribution of abstained portions. Ensure that this logic is consistent with the overall distribution strategy.

x/streamer/types/distr_info_test.go (4)

19-26: Test Case for Empty Distribution is Well-Defined

The test case for an empty distribution ensures that the function correctly handles scenarios with no gauges. This is a good edge case to validate.


27-47: Test Case for Single Gauge Distribution is Correct

The test case effectively verifies the function's handling of a distribution with one gauge, ensuring the correct assignment of weight and total weight.


48-76: Test Case for Multiple Gauges is Comprehensive

The test case for multiple gauges ensures the function aggregates weights correctly, validating the logic for handling several gauges.


77-107: Test Case for Abstained Gauge is Well-Constructed

The test case correctly verifies that abstained portions remain unallocated, ensuring the function's behavior aligns with the intended distribution logic.

Copy link
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c0216b0 and 2ce2f0c.

Files selected for processing (2)
  • x/streamer/types/distr_info.go (2 hunks)
  • x/streamer/types/distr_info_test.go (1 hunks)
Additional comments not posted (2)
x/streamer/types/distr_info.go (1)

38-50: Simplified function logic improves readability.

The function DistrInfoFromDistribution now directly assigns d.VotingPower to TotalWeight and appends DistrRecord instances more concisely. This change enhances readability and maintains the intended functionality of handling abstained portions by not redistributing them.

x/streamer/types/distr_info_test.go (1)

13-115: Comprehensive test coverage for DistrInfoFromDistribution.

The test cases effectively cover scenarios such as empty distributions, single and multiple gauges, and handling of abstained gauges. This ensures the function's correctness and robustness across different inputs.

Copy link
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c0216b0 and 2ce2f0c.

Files selected for processing (2)
  • x/streamer/types/distr_info.go (2 hunks)
  • x/streamer/types/distr_info_test.go (1 hunks)
Additional comments not posted (2)
x/streamer/types/distr_info.go (1)

38-50: Simplified weight calculation logic.

The changes streamline the function by directly assigning Weight from g.Power and TotalWeight from d.VotingPower, removing unnecessary calculations. This enhances clarity and aligns with the PR objective of preventing redistribution of abstained portions.

x/streamer/types/distr_info_test.go (1)

13-115: Comprehensive test coverage for DistrInfoFromDistribution.

The test cases effectively cover scenarios such as empty distributions, single and multiple gauges, and abstained gauges. This ensures robust validation of the updated distribution logic and aligns with the PR objectives.

Copy link
Contributor

@danwt danwt left a comment

Choose a reason for hiding this comment

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

Curiuos what is the difference between streamer DistrInfo and sponsorship Distribution?

x/streamer/types/distr_info.go Show resolved Hide resolved
@keruch keruch merged commit f1df3d7 into main Aug 15, 2024
11 of 118 checks passed
@keruch keruch deleted the kirill/1095-sponsored-streams-distr branch August 15, 2024 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c:sponsorship x/sponsorship module dym-internal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change the distribution logic if some part of the sponsored stream is abstained
3 participants