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

Tokenomics update #1478

Merged
merged 9 commits into from
Sep 3, 2024
Merged

Tokenomics update #1478

merged 9 commits into from
Sep 3, 2024

Conversation

psolstice
Copy link
Contributor

PR intention

Change of emission rules. According to the new rules instead of second halving at block 958655 block subsidy remains the same and the split of funds are: development fund - 15%, community fund - 10%, masternode reward - 70%, miner's reward - 5%.

Instead of the third halving (block 1798655) blockchain enters the tail emission phase and block subsidy becomes 1 FIRO. Split remains the same as above.

Code changes brief

Multiple changes in generation and verification functions as well as chain parameters and tests.

Copy link

coderabbitai bot commented Sep 2, 2024

Walkthrough

The changes involve significant modifications to the consensus parameters and subsidy distribution mechanisms across various classes. Key parameters related to subsidy halving have been removed, while new parameters for a fourth funding stage have been introduced. The logic for block subsidy calculations and payout distributions has been refined, enhancing the clarity and efficiency of the reward mechanism. Additionally, updates to test cases ensure alignment with the new consensus structure.

Changes

File Change Summary
src/chainparams.cpp Removed nSubsidyHalvingStopBlock; added parameters for stage 4 funding and tail emission.
src/consensus/params.h Removed nSubsidyHalvingStopBlock; added parameters for stage 4 funding and tail emission.
src/miner.cpp Updated block creation logic; refined reward distribution based on new stage parameters.
src/test/firsthalving_tests.cpp Adjusted test case logic for subsidy halving and payout calculations; updated assertions.
src/test/main_tests.cpp Simplified subsidy testing; focused on specific block heights instead of a loop.
src/test/mtp_halving_tests.cpp Enhanced testing setup for consensus parameters with temporary modifications.
src/validation.cpp Refactored subsidy calculation logic; consolidated payout checks for development and community funds.

Sequence Diagram(s)

sequenceDiagram
    participant Miner
    participant ConsensusParams
    participant Block
    participant PayoutSystem

    Miner->>ConsensusParams: Request subsidy parameters
    ConsensusParams->>Miner: Return updated parameters
    Miner->>Block: Create block with subsidy
    Block->>PayoutSystem: Calculate payouts
    PayoutSystem->>Block: Distribute rewards
Loading

🐰 In the meadow, I hop with glee,
New changes bloom, oh what a spree!
Subsidies dance in stages bright,
With tails of emission, a joyful sight!
Let's celebrate with a happy cheer,
For bunnies and funds, the future is clear! 🐇✨

Tip

We have updated our review workflow to use the Anthropic's Claude family of models. Please share any feedback in the discussion post on our Discord.


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 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 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: 1

Outside diff range, codebase verification and nitpick comments (2)
src/test/firsthalving_tests.cpp (1)

272-273: Update the comment to match the 5% miner reward allocation.

The assertion correctly checks for the 1.25 coins miner reward, which is 5% of the total block subsidy. However, the comment mentions a 10% miner reward allocation.

Update the comment to match the 5% miner reward allocation mentioned in the PR objective:

-// miner's reward should be 1.25 (10%)
+// miner's reward should be 1.25 (5%) 
src/consensus/params.h (1)

164-172: Inconsistencies in Stage 4 Parameters

The stage4StartBlock and fund share percentages for stage 4 are inconsistent across the codebase:

  • stage4StartBlock is set to different values in various files:

    • consensus.nSubsidyHalvingSecond
    • 167500
    • consensus.nSubsidyHalvingSecond + 500
  • Fund Share Percentages:

    • In most cases, stage4CommunityFundShare is 10%, stage4DevelopmentFundShare is 15%, and stage4MasternodeShare is 70%, totaling 95%.
    • In one instance, they are set to 15%, 25%, and 50%, totaling 90%.

These discrepancies suggest a need for further verification or clarification to ensure the parameters align with the intended design for stage 4. Please review and confirm the correct values.

Analysis chain

New parameters for stage 4 coinbase payment distribution.

The code changes introduce new parameters for stage 4 of the coinbase payment distribution, including:

  • stage4StartBlock: The starting block for stage 4.
  • stage4DevelopmentFundShare: The percentage share for the development fund.
  • stage4CommunityFundShare: The percentage share for the community fund.
  • stage4MasternodeShare: The percentage share for masternodes.

Please verify that the stage4StartBlock and the fund share percentages align with the intended design for stage 4. Consider running the following script to confirm the values:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify stage 4 parameters are set as intended.

# Test: Check if stage4StartBlock is set correctly. Expect: Correct block number.
rg --type cpp -A 5 $'stage4StartBlock'

# Test: Check if fund share percentages add up to 100%. Expect: Sum of percentages is 100.
rg --type cpp -A 5 $'stage4\w+Share'

Length of output: 9942

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5a1bb0b and a1e9870.

Files selected for processing (7)
  • src/chainparams.cpp (6 hunks)
  • src/consensus/params.h (2 hunks)
  • src/miner.cpp (2 hunks)
  • src/test/firsthalving_tests.cpp (4 hunks)
  • src/test/main_tests.cpp (2 hunks)
  • src/test/mtp_halving_tests.cpp (2 hunks)
  • src/validation.cpp (4 hunks)
Additional comments not posted (24)
src/test/mtp_halving_tests.cpp (3)

45-46: LGTM!

The addition of the new member variables mutableParams and oldParams to the MtpHalvingTestingSetup struct is approved.


48-54: LGTM!

The changes to the constructor of the MtpHalvingTestingSetup struct are approved. The initialization of the new member variables and disabling of stage 3 functionality during the test setup is correct.


78-80: LGTM!

The addition of the destructor to the MtpHalvingTestingSetup struct is approved. Restoring the original consensus parameters in the destructor is a good practice to ensure that modifications made during the test do not persist.

src/test/firsthalving_tests.cpp (7)

157-157: LGTM!

The change aligns the second subsidy halving with the start of stage 4 at block 620, which is consistent with the PR objective.


228-228: LGTM!

Assigning the current chain height to consensusParams.stage3StartBlock enhances the tracking of block stages by capturing when stage 3 begins.


264-265: LGTM!

The comment and assertion are consistent with the PR objective of keeping the block subsidy unchanged in stage 4 instead of implementing a second halving.


275-286: LGTM!

The assertions correctly verify the payment amounts to the development and community funds based on the new allocation percentages mentioned in the PR objective.


289-296: LGTM!

The comment and assertion are consistent with the PR objective of transitioning to a tail emission phase with a 1 FIRO block subsidy at block 1798655.


308-308: LGTM!

Setting consensusParams.stage3StartTime to INT_MAX effectively disables stage 3 for the test case, allowing the focus to be on testing the behavior of other stages.


Line range hint 309-343:
The remaining code segments are part of the devpayoutverification test case and do not have any alterations. Skipping the review.

src/consensus/params.h (2)

Line range hint 1-1: Removal of nSubsidyHalvingStopBlock parameter.

The code changes involve the removal of the nSubsidyHalvingStopBlock parameter from the Params struct.

Please verify that the removal of nSubsidyHalvingStopBlock is intentional and doesn't introduce any unintended consequences or inconsistencies in the codebase. Consider running the following script to check for any remaining references to nSubsidyHalvingStopBlock:

Verification successful

Removal of nSubsidyHalvingStopBlock verified.

The removal of the nSubsidyHalvingStopBlock parameter from the Params struct has been verified. There are no remaining references to this parameter in the codebase, indicating that the removal was complete and did not introduce any inconsistencies.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the removal of nSubsidyHalvingStopBlock doesn't introduce inconsistencies.

# Test: Search for any remaining references to nSubsidyHalvingStopBlock. Expect: No occurrences.
rg --type cpp $'nSubsidyHalvingStopBlock'

Length of output: 40


174-175: New parameter for tail emission block subsidy.

The code changes introduce a new parameter tailEmissionBlockSubsidy to define the block subsidy value during the tail emission phase.

Please verify that the tailEmissionBlockSubsidy value is set as intended for the tail emission phase. Consider running the following script to confirm the value:

Verification successful

Tail emission block subsidy is set as intended.

The tailEmissionBlockSubsidy is consistently set to 4 * COIN across different configurations, with a comment explaining that the effective value is 1 FIRO due to halvings. This setup appears intentional and aligns with the expected behavior for the tail emission phase.

  • src/chainparams.cpp: consensus.tailEmissionBlockSubsidy = 4 * COIN; // real value would be 1 FIRO
  • src/validation.cpp: Utilizes tailEmissionBlockSubsidy for subsidy calculations.
  • src/test/main_tests.cpp: Includes tests involving tailEmissionBlockSubsidy.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify tail emission block subsidy is set as intended.

# Test: Check if tailEmissionBlockSubsidy is set correctly. Expect: Correct subsidy value.
rg --type cpp -A 5 $'tailEmissionBlockSubsidy'

Length of output: 2941

src/miner.cpp (5)

195-195: LGTM!

Deriving fShorterBlockDistance from nHeight compared to params.stage3StartBlock makes the block reward logic more consistent and predictable.


838-841: LGTM!

The expanded conditional logic and introduction of fStage3 and fStage4 boolean flags improve the clarity and maintainability of the block reward calculations for different stages.


846-852: LGTM!

Calculating the development and community fund payouts based on the appropriate share percentages for the current stage ensures alignment with the consensus rules.


854-857: LGTM!

Skipping the development fund payout when the value is zero enhances the efficiency of the reward distribution mechanism.


859-862: LGTM!

Skipping the community fund payout when the value is zero enhances the efficiency of the reward distribution mechanism.

src/chainparams.cpp (6)

208-212: LGTM!

The changes introduce the stage 4 funding parameters as per the PR description:

  • stage4StartBlock is set to nSubsidyHalvingSecond block number.
  • Fund share percentages are defined for community fund, development fund, and masternodes.
  • tailEmissionBlockSubsidy is set to 4 FIRO.

535-539: LGTM!

The stage 4 funding parameters are correctly added for testnet, mirroring the changes made in CMainParams:

  • stage4StartBlock is explicitly set to 167500.
  • Fund share percentages are defined.
  • tailEmissionBlockSubsidy is set to 4 FIRO.

802-803: LGTM!

The subsidy halving schedule for devnet is adjusted:

  • nSubsidyHalvingSecond is set to block 3000.
  • nSubsidyHalvingInterval is set to 10000 blocks.

810-817: Verify the stage3StartBlock value for devnet.

The comment indicates that the stage3StartBlock value of 1514 is incorrect for devnet but will be retained for now.

Please confirm if the stage3StartBlock value needs to be updated. If it's intentionally kept as 1514 for some reason, consider removing the comment to avoid confusion.


817-821: LGTM!

The stage 4 funding parameters are correctly added for devnet:

  • stage4StartBlock is set to nSubsidyHalvingSecond.
  • Fund share percentages are defined.
  • tailEmissionBlockSubsidy is set to 4 FIRO.

1055-1067: LGTM!

The changes for regtest params look good:

  • stage3StartTime is set to 0.
  • stage3StartBlock is set to 1500.
  • Stage 4 funding parameters are added:
    • stage4StartBlock is set to 500 blocks after nSubsidyHalvingSecond.
    • Fund share percentages are defined.
    • tailEmissionBlockSubsidy is set to 4 FIRO.
src/validation.cpp (1)

1921-1933: Update to the block subsidy calculation logic

The changes to the GetBlockSubsidyWithMTPFlag function modify the block subsidy calculation:

  • The initial subsidy remains at 50 coins until the first halving (nSubsidyHalvingFirst).
  • Between the first and second halvings, the subsidy is 25 coins.
  • After the stage4StartBlock, the subsidy is set to a fixed 25 coins.
  • After stage4StartBlock + nSubsidyHalvingInterval, the subsidy switches to a fixed tail emission of 1 coin.

Verify that the fixed subsidy values (25 coins, 1 coin) and the block height thresholds (stage4StartBlock, stage4StartBlock + nSubsidyHalvingInterval) match the intended emission schedule.

src/test/main_tests.cpp Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a1e9870 and a7abf11.

Files selected for processing (1)
  • src/chainparams.cpp (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/chainparams.cpp

@reubenyap reubenyap merged commit bfd992e into master Sep 3, 2024
5 of 6 checks passed
@reubenyap reubenyap deleted the tokenomics-update branch September 3, 2024 15:17
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