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 Community Pool Calculation #300

Merged
merged 4 commits into from
Feb 10, 2025

Conversation

cloud8little
Copy link
Contributor

@cloud8little cloud8little commented Feb 8, 2025

Description

The community Pool amount should be the remaining amount that exclude all validators and stakers reward.


Closes #XXX

Summary by CodeRabbit

  • Refactor

    • Updated the community pool allocation to reflect the remaining rewards after distributing to individual stakers, enhancing the accuracy of the community pool balance while maintaining the existing reward distribution logic.
  • Chores

    • Updated the curl package version from 8.11 to 8.12 in the Dockerfile for the Exocore project.
    • Updated the curl package version from 8.11 to 8.12 in the run stage of the Dockerfile for the local Exocore network.

Copy link
Contributor

coderabbitai bot commented Feb 8, 2025

Walkthrough

The change modifies the AllocateTokensToStakers method within the keeper package by updating the logic for how the CommunityPool is adjusted. Instead of reflecting the total rewards allocated to stakers, it now updates the pool with the remaining amount after individual rewards are distributed. The calculations for individual staker rewards based on their power fractions remain unchanged, and there are no alterations to exported entities or other methods.

Changes

File Path Change Summary
x/feedistribution/keeper/allocation.go Updated the CommunityPool adjustment in AllocateTokensToStakers to reflect the remaining amount after distributing rewards, while individual reward calculations remain unchanged.
Dockerfile Updated curl package version from 8.11 to 8.12 in the installation command.
networks/local/exocore/Dockerfile Updated curl package version from 8.11 to 8.12 in the run stage of the Dockerfile.

Possibly related issues

  • Community Pool value is incorrect #301: The change addresses the issue of the community pool value being incorrect by ensuring that the CommunityPool reflects the remaining amount after rewards are allocated rather than the total fee pool amount.

Suggested reviewers

  • magj2006
  • adu-web3
  • TimmyExogenous
  • bwhour

Poem

I’m a bunny coder, hopping with delight,
No community pool update—oh, what a sight!
Tokens for stakers dance in line,
A smoother flow, oh so fine.
Carrots and code, all feeling light! 🐰✨


📜 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 edf018b and f77b4d0.

📒 Files selected for processing (1)
  • x/feedistribution/keeper/allocation.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • x/feedistribution/keeper/allocation.go
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test-unit-cover
  • GitHub Check: goreleaser
  • GitHub Check: Analyze (go)

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>, please review it.
    • 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 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 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 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. (Beta)
  • @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.

@@ -158,7 +158,6 @@ func (k Keeper) AllocateTokensToStakers(ctx sdk.Context, operatorAddress sdk.Acc
remaining = remaining.Sub(rewardToSingleStaker)
}
}
feePool.CommunityPool = feePool.CommunityPool.Add(rewardToAllStakers...)
logger.Info("allocate tokens to stakers successfully", "allocated amount is", rewardToAllStakers.String())
Copy link
Contributor

Choose a reason for hiding this comment

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

rewardToAllStakers.Sub(remaining).String()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@leonz789 updated, plz have a review

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please update the log.Info as well ?
logger.Info("allocate tokens to stakers successfully", "allocated amount is", rewardToAllStakers.Sub(remaining).String())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you please update the log.Info as well ? logger.Info("allocate tokens to stakers successfully", "allocated amount is", rewardToAllStakers.Sub(remaining).String())

done

Copy link
Contributor

@mikebraver mikebraver left a comment

Choose a reason for hiding this comment

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

Use feePool.CommunityPool = feePool.CommunityPool.Add(remaining...)

@cloud8little
Copy link
Contributor Author

Test result:

the community pool amount plus total stakers rewards plus total validator commission equals to total fee amount after an epoch.

    "feedistribution": {
     "fee_pool": {
       "community_pool": [
         {
           "amount": "37809145232010505155.033079946781459508",
           "denom": "hua"
         }
       ]
     },
     "params": {
       "community_tax": "0.030000000000000000",
       "epoch_identifier": "minute"
     },
     "staker_outstanding_rewards_list": [
       {
         "staker_addr": "0x0b34c4d876cd569129cf56bafabb3f9e97a4ff42_0x9ce1",
         "staker_outstanding_rewards": {
           "rewards": [
             {
               "amount": "203749271671928217527.426704935838611259",
               "denom": "hua"
             }
           ]
         }
       },
       {
         "staker_addr": "0x6bc4938f35e12690d833b7d6fdf52e289cd78f1d_0x9ce1",
         "staker_outstanding_rewards": {
           "rewards": [
             {
               "amount": "407498564792103121982.023114265178730712",
               "denom": "hua"
             }
           ]
         }
       },
       {
         "staker_addr": "0x7e7a484a60f3bd5e8276d01118e932f36d4ad5f8_0x9ce1",
         "staker_outstanding_rewards": {
           "rewards": [
             {
               "amount": "305623919150454444835.158147596464267976",
               "denom": "hua"
             }
           ]
         }
       },
       {
         "staker_addr": "0xda82c2dba1871a21905480cef2f2e10729ec56ed_0x9ce1",
         "staker_outstanding_rewards": {
           "rewards": [
             {
               "amount": "305623940220520459691.358953255736930545",
               "denom": "hua"
             }
           ]
         }
       }
     ],
     "validator_accumulated_commissions": [
       {
         "commission": {
           "commission": []
         },
         "val_addr": "exo192mgay9r8mdgwcprcvgdm47td36n974h9r8z6q"
       },
       {
         "commission": {
           "commission": []
         },
         "val_addr": "exo13py43laj8zz6zw6a29sh7p0jhzeq7pq96054r3"
       },
       {
         "commission": {
           "commission": []
         },
         "val_addr": "exo1hj3qk6wg7se6l8g3s3ept7aas37dc75fk3lm2s"
       },
       {
         "commission": {
           "commission": []
         },
         "val_addr": "exo1m4mewv4fr2qphdjuft8cvlz4vphur93sp0kxm0"
       }
     ],
     "validator_current_rewards_list": [],
     "validator_outstanding_rewards_list": [
       {
         "outstanding_rewards": {
           "rewards": [
             {
               "amount": "275061525290479830373.317748758278508106",
               "denom": "hua"
             }
           ]
         },
         "val_addr": "exo192mgay9r8mdgwcprcvgdm47td36n974h9r8z6q"
       },
       {
         "outstanding_rewards": {
           "rewards": [
             {
               "amount": "203749268700508651381.173576869505019474",
               "denom": "hua"
             }
           ]
         },
         "val_addr": "exo13py43laj8zz6zw6a29sh7p0jhzeq7pq96054r3"
       },
       {
         "outstanding_rewards": {
           "rewards": [
             {
               "amount": "305623944866740145063.378938860736224073",
               "denom": "hua"
             }
           ]
         },
         "val_addr": "exo1hj3qk6wg7se6l8g3s3ept7aas37dc75fk3lm2s"
       },
       {
         "outstanding_rewards": {
           "rewards": [
             {
               "amount": "438060956977277618674.904039676474001630",
               "denom": "hua"
             }
           ]
         },
         "val_addr": "exo1m4mewv4fr2qphdjuft8cvlz4vphur93sp0kxm0"
       }
     ]
   },

@cloud8little cloud8little merged commit c871d19 into imua-xyz:develop Feb 10, 2025
20 checks passed
@cloud8little cloud8little deleted the fix_feepool branch February 10, 2025 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants