Skip to content

Staking v5 implementation#7386

Merged
sstanculeanu merged 29 commits into
masterfrom
stakingV5-implementation
Nov 24, 2025
Merged

Staking v5 implementation#7386
sstanculeanu merged 29 commits into
masterfrom
stakingV5-implementation

Conversation

@sasurobert

Copy link
Copy Markdown
Contributor

Technical Implementation: Tail Inflation and New Reward Buckets

Introduce Tail Inflation: Transition from an inflation model calculated against the initial genesis supply to a "tail inflation" model calculated against the current total supply. This new model includes an annual decay and a configurable floor, ensuring long-term network security and sustainability.
Add New Reward Buckets: Introduce two new reward destinations, EcosystemGrowth and GrowthDividend, to diversify the distribution of epoch rewards alongside the existing ProtocolSustainability bucket.
2. Configuration Changes
To support the new logic, the economics configuration file at cmd/node/config/economics.toml has been updated with new parameters.
2.1 Tail Inflation Settings
A new section, [tailInflation], has been added to control the new inflation mechanism:

[tailInflation]
activationEpoch = 100
firstYearInflation = 0.08757 # 8.757%
decayPercentage = 0.0025 # 0.25%
minimumInflation = 0.02 # 2%
activationEpoch: The epoch at which the tail inflation logic becomes active. Before this epoch, the chain continues to use the original genesis-based inflation calculation.
maximumYearlyInflation: The upper ceiling for the annual inflation rate.
decayPercentage: The percentage by which the inflation rate is reduced at the start of each new "economics year" (a full cycle of epochs).
minimumInflation: The floor for the annual inflation rate. The decayed inflation rate will not fall below this value.
2.2 New Reward Bucket Settings
The [rewardsSettings] section has been expanded to include percentages and destination addresses for the two new reward buckets:
[rewardsSettings]

... existing settings

ecosystemGrowthPercentage = 0.1
ecosystemGrowthAddress = "erd..."
growthDividendPercentage = 0.1
growthDividendAddress = "erd..."
ecosystemGrowthPercentage & ecosystemGrowthAddress: Defines the portion of the total epoch rewards allocated to the Ecosystem Growth fund and its destination address.
growthDividendPercentage & growthDividendAddress: Defines the portion of the total epoch rewards allocated to the Growth Dividend fund and its destination address.
3. Core Logic Implementation
The core logic resides in epochStart/metachain/economics.go and epochStart/metachain/rewards.go.

3.1 Inflation Calculation (economics.go)
The computeInflation function was modified to handle the transition to tail inflation.
Activation Check: The function first checks if the current epoch is greater than or equal to the tailInflation.activationEpoch.
If not activated: The original logic, which calculates inflation based on the genesis supply, is executed.
If activated: The new tail inflation logic is triggered.
Tail Inflation Logic:
The inflation rate is now calculated based on the currentTotalSupply, not the initial supply.
At the start of each new economics year, the inflation rate is decayed using the formula: currentInflation = previousInflation - decayPercentage
The resulting inflation rate is then constrained by the configured limits: it cannot fall below minimumInflation.
The final, adjusted inflation rate is used to calculate the TotalToDistribute rewards for the current epoch.
3.2 Reward Distribution (economics.go and rewards.go)

A key constraint of the implementation was to avoid making breaking changes to the core block.Economics struct, which is defined in an external dependency. This struct did not have fields for EcosystemGrowth and GrowthDividend. To work around this, the following approach was taken:
Individual Reward Calculation (economics.go): The rewards for all three buckets (ProtocolSustainability, EcosystemGrowth, GrowthDividend) are calculated individually by multiplying the TotalToDistribute amount by their respective percentages from the configuration.
Summing into a Single Field (economics.go): The three calculated reward amounts are summed together. This total sum is then assigned to the existing block.Economics.RewardsForProtocolSustainability field. From the perspective of the core block structure, it appears as one large reward for protocol sustainability.
Exposing Individual Amounts (interface.go): To enable the creation of separate transactions, the EpochEconomicsDataProvider interface was extended. It now includes getter methods that return the individual, pre-summed reward amounts:
RewardsForProtocolSustainability()
RewardsForEcosystemGrowth()
RewardsForGrowthDividend()
Creating Separate Transactions (rewards.go / rewardsV2.go):
The rewardsCreator structs were updated to use the enhanced EpochEconomicsDataProvider.
In the CreateRewardsMiniBlocks function, the creator now calls the new getters to retrieve the individual reward amounts for each of the three buckets.
It then creates three distinct rewardTx.RewardTx transactions, each with the correct value and destination address as specified in economics.toml.
These three transactions are then added to the rewards miniblocks to be processed by the network, ensuring each fund receives its correct allocation.

@github-actions

Copy link
Copy Markdown

Integration Tests completed with failures or errors.

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 09773ce1168c45f73f5983a8cb36310522ebac0f
  • Current Branch: stakingV5-implementation
  • mx-chain-go Target Branch: master
  • mx-chain-simulator-go Target Branch: main
  • mx-chain-testing-suite Target Branch: main
  • mx-chain-simulator-go Commit Hash: 9103035e808df39e6400b4cbf79c292fe4852830

🚀 Environment Variables:

  • TIMESTAMP: 2025_OCTOBER_31__18_02_42
  • PYTEST_EXIT_CODE: 1

@codecov

codecov Bot commented Oct 31, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.03774% with 37 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.59%. Comparing base (e3109b6) to head (b30a238).
⚠️ Report is 34 commits behind head on master.

Files with missing lines Patch % Lines
process/economics/rewardsConfigHandler.go 80.43% 4 Missing and 5 partials ⚠️
epochStart/metachain/economics.go 83.33% 4 Missing and 4 partials ⚠️
epochStart/metachain/rewardsV2.go 79.48% 4 Missing and 4 partials ⚠️
process/economics/globalSettings.go 82.97% 4 Missing and 4 partials ⚠️
process/economics/economicsData.go 73.33% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7386      +/-   ##
==========================================
+ Coverage   75.05%   76.59%   +1.53%     
==========================================
  Files         812      813       +1     
  Lines      134427   109824   -24603     
==========================================
- Hits       100892    84115   -16777     
+ Misses      27813    19973    -7840     
- Partials     5722     5736      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Nov 3, 2025

Copy link
Copy Markdown

Integration Tests completed with failures or errors.

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 8c3024fd322811db9a7f68807f25752e3412f1fb
  • Current Branch: stakingV5-implementation
  • mx-chain-go Target Branch: master
  • mx-chain-simulator-go Target Branch: main
  • mx-chain-testing-suite Target Branch: main
  • mx-chain-simulator-go Commit Hash: 9103035e808df39e6400b4cbf79c292fe4852830

🚀 Environment Variables:

  • TIMESTAMP: 2025_NOVEMBER_03__10_53_10
  • PYTEST_EXIT_CODE: 1

@github-actions

github-actions Bot commented Nov 3, 2025

Copy link
Copy Markdown

Integration Tests completed with failures or errors.

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 8c5858ab49f8f03da166e9d769fb26a66168a1a0
  • Current Branch: stakingV5-implementation
  • mx-chain-go Target Branch: master
  • mx-chain-simulator-go Target Branch: main
  • mx-chain-testing-suite Target Branch: main
  • mx-chain-simulator-go Commit Hash: 9103035e808df39e6400b4cbf79c292fe4852830

🚀 Environment Variables:

  • TIMESTAMP: 2025_NOVEMBER_03__11_35_05
  • PYTEST_EXIT_CODE: 1

@github-actions

github-actions Bot commented Nov 3, 2025

Copy link
Copy Markdown

Integration Tests completed with failures or errors.

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: cc7a8f6f5d0215c99f63586405d200e687ac8919
  • Current Branch: stakingV5-implementation
  • mx-chain-go Target Branch: master
  • mx-chain-simulator-go Target Branch: main
  • mx-chain-testing-suite Target Branch: main
  • mx-chain-simulator-go Commit Hash: 9103035e808df39e6400b4cbf79c292fe4852830

🚀 Environment Variables:

  • TIMESTAMP: 2025_NOVEMBER_03__13_31_15
  • PYTEST_EXIT_CODE: 1

@github-actions

github-actions Bot commented Nov 3, 2025

Copy link
Copy Markdown

Integration Tests completed with failures or errors.

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 5635cffaf5d6c08ec36082103b89574b7ec8943c
  • Current Branch: stakingV5-implementation
  • mx-chain-go Target Branch: master
  • mx-chain-simulator-go Target Branch: main
  • mx-chain-testing-suite Target Branch: main
  • mx-chain-simulator-go Commit Hash: 9103035e808df39e6400b4cbf79c292fe4852830

🚀 Environment Variables:

  • TIMESTAMP: 2025_NOVEMBER_03__15_55_56
  • PYTEST_EXIT_CODE: 1

@github-actions

github-actions Bot commented Nov 3, 2025

Copy link
Copy Markdown

Integration Tests completed with failures or errors.

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 5635cffaf5d6c08ec36082103b89574b7ec8943c
  • Current Branch: stakingV5-implementation
  • mx-chain-go Target Branch: master
  • mx-chain-simulator-go Target Branch: main
  • mx-chain-testing-suite Target Branch: main
  • mx-chain-simulator-go Commit Hash: 9103035e808df39e6400b4cbf79c292fe4852830

🚀 Environment Variables:

  • TIMESTAMP: 2025_NOVEMBER_03__16_37_11
  • PYTEST_EXIT_CODE: ``

Comment thread epochStart/metachain/economics.go Outdated

supplyToUseForRewardsperBlock := e.genesisTotalSupply
if metaBlock.Epoch >= e.accRewardsEnableEpoch {
supplyToUseForRewardsperBlock = prevEpochEconomics.TotalSupply

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this will still compound daily so it will end up larger than initially configured.
To have the exact inflation configured, you need to either use the same supply for the entire year when computing rewards, or dynamically decrease the starting inflation rate daily to have a constant emission each epoch.

Comment thread epochStart/metachain/economics.go Outdated
totalNumBlocksInEpoch := e.computeNumOfTotalCreatedBlocks(noncesPerShardPrevEpoch, noncesPerShardCurrEpoch)

supplyToUseForRewardsperBlock := e.genesisTotalSupply
if metaBlock.Epoch >= e.accRewardsEnableEpoch {

@sstanculeanu sstanculeanu Nov 4, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should this be switched to >?

shouldn't we still use genesis total supply if metaBlock.Epoch == activation epoch?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it can happen at activation epoch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

reworked

Comment thread epochStart/metachain/economics.go Outdated
}

func (e *economics) computeRewardsForAccelerator(totalRewards *big.Int, epoch uint32) *big.Int {
if e.accRewardsEnableEpoch >= epoch {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this >= will be true for activation epoch, which means on L139, if metaBlock.Epoch >= e.accRewardsEnableEpoch must use >, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it can start happening at activation epoch. No strong opinion on this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

reworked

Comment thread epochStart/metachain/economics.go Outdated

supplyToUseForRewardsperBlock := e.genesisTotalSupply
if metaBlock.Epoch >= e.accRewardsEnableEpoch {
supplyToUseForRewardsperBlock = prevEpochEconomics.TotalSupply

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
supplyToUseForRewardsperBlock = prevEpochEconomics.TotalSupply
supplyToUseForRewardsPerBlock = prevEpochEconomics.TotalSupply

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

year1Inflation := 0.1
minInflation := 0.01
enableEpochHandler := &mock.EnableEpochsHandlerMock{}
gsh := &globalSettingsHandler{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

use constructor for extra coverage

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@github-actions

github-actions Bot commented Nov 5, 2025

Copy link
Copy Markdown

Integration Tests completed with failures or errors.

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 17a770d3d88228920f3bdb1ce3369945db6d1422
  • Current Branch: stakingV5-implementation
  • mx-chain-go Target Branch: master
  • mx-chain-simulator-go Target Branch: main
  • mx-chain-testing-suite Target Branch: main
  • mx-chain-simulator-go Commit Hash: 9103035e808df39e6400b4cbf79c292fe4852830

🚀 Environment Variables:

  • TIMESTAMP: 2025_NOVEMBER_05__08_02_49
  • PYTEST_EXIT_CODE: ``

@github-actions

github-actions Bot commented Nov 5, 2025

Copy link
Copy Markdown

Integration Tests completed with failures or errors.

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 17a770d3d88228920f3bdb1ce3369945db6d1422
  • Current Branch: stakingV5-implementation
  • mx-chain-go Target Branch: master
  • mx-chain-simulator-go Target Branch: main
  • mx-chain-testing-suite Target Branch: main
  • mx-chain-simulator-go Commit Hash: 9103035e808df39e6400b4cbf79c292fe4852830

🚀 Environment Variables:

  • TIMESTAMP: 2025_NOVEMBER_05__08_19_37
  • PYTEST_EXIT_CODE: 1

@github-actions

github-actions Bot commented Nov 5, 2025

Copy link
Copy Markdown

Integration Tests completed with failures or errors.

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 9b90751425e0e1fbc2923dd1d27304c2de37176c
  • Current Branch: stakingV5-implementation
  • mx-chain-go Target Branch: master
  • mx-chain-simulator-go Target Branch: main
  • mx-chain-testing-suite Target Branch: main
  • mx-chain-simulator-go Commit Hash: 9103035e808df39e6400b4cbf79c292fe4852830

🚀 Environment Variables:

  • TIMESTAMP: 2025_NOVEMBER_05__16_59_35
  • PYTEST_EXIT_CODE: ``

@github-actions

github-actions Bot commented Nov 6, 2025

Copy link
Copy Markdown

Integration Tests completed with failures or errors.

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 9b90751425e0e1fbc2923dd1d27304c2de37176c
  • Current Branch: stakingV5-implementation
  • mx-chain-go Target Branch: master
  • mx-chain-simulator-go Target Branch: main
  • mx-chain-testing-suite Target Branch: main
  • mx-chain-simulator-go Commit Hash: 9103035e808df39e6400b4cbf79c292fe4852830

🚀 Environment Variables:

  • TIMESTAMP: 2025_NOVEMBER_06__08_36_09
  • PYTEST_EXIT_CODE: 1

AdoAdoAdo
AdoAdoAdo previously approved these changes Nov 13, 2025
@github-actions

Copy link
Copy Markdown

Integration Tests passed successfully!

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 34cb16919ae6ec65972f5dd38458a4c6d2db1be1
  • Current Branch: stakingV5-implementation
  • mx-chain-go Target Branch: master
  • mx-chain-simulator-go Target Branch: stakingV5-implementation
  • mx-chain-testing-suite Target Branch: rc/barnard-patch-3
  • mx-chain-simulator-go Commit Hash: 6f715baf23b5560bd585619c28332c896a978f9f

🚀 Environment Variables:

  • TIMESTAMP: 2025_NOVEMBER_13__16_21_10
  • PYTEST_EXIT_CODE: 0

@github-actions

Copy link
Copy Markdown

Integration Tests passed successfully!

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 34cb16919ae6ec65972f5dd38458a4c6d2db1be1
  • Current Branch: stakingV5-implementation
  • mx-chain-go Target Branch: master
  • mx-chain-simulator-go Target Branch: stakingV5-implementation
  • mx-chain-testing-suite Target Branch: rc/barnard-patch-3
  • mx-chain-simulator-go Commit Hash: 6f715baf23b5560bd585619c28332c896a978f9f

🚀 Environment Variables:

  • TIMESTAMP: 2025_NOVEMBER_13__17_08_32
  • PYTEST_EXIT_CODE: 0

@github-actions

Copy link
Copy Markdown

Integration Tests passed successfully!

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 34cb16919ae6ec65972f5dd38458a4c6d2db1be1
  • Current Branch: stakingV5-implementation
  • mx-chain-go Target Branch: master
  • mx-chain-simulator-go Target Branch: stakingV5-implementation
  • mx-chain-testing-suite Target Branch: rc/barnard-patch-3
  • mx-chain-simulator-go Commit Hash: 6f715baf23b5560bd585619c28332c896a978f9f

🚀 Environment Variables:

  • TIMESTAMP: 2025_NOVEMBER_13__18_26_17
  • PYTEST_EXIT_CODE: 0

@github-actions

Copy link
Copy Markdown

Integration Tests passed successfully!

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 34cb16919ae6ec65972f5dd38458a4c6d2db1be1
  • Current Branch: stakingV5-implementation
  • mx-chain-go Target Branch: master
  • mx-chain-simulator-go Target Branch: stakingV5-implementation
  • mx-chain-testing-suite Target Branch: rc/barnard-patch-3
  • mx-chain-simulator-go Commit Hash: 6f715baf23b5560bd585619c28332c896a978f9f

🚀 Environment Variables:

  • TIMESTAMP: 2025_NOVEMBER_14__00_56_08
  • PYTEST_EXIT_CODE: 0

sstanculeanu
sstanculeanu previously approved these changes Nov 14, 2025
@sasurobert sasurobert dismissed stale reviews from sstanculeanu and AdoAdoAdo via a9ee9cd November 14, 2025 14:11
@github-actions

Copy link
Copy Markdown

Integration Tests completed with failures or errors.

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: a9ee9cd26bc58768e44aee81ff86d1aaf29878af
  • Current Branch: stakingV5-implementation
  • mx-chain-go Target Branch: master
  • mx-chain-simulator-go Target Branch: stakingV5-implementation
  • mx-chain-testing-suite Target Branch: rc/barnard-patch-3
  • mx-chain-simulator-go Commit Hash: ea407377979389afb6d0f22eba70dbf0c0d12ad4

🚀 Environment Variables:

  • TIMESTAMP: 2025_NOVEMBER_14__14_15_28
  • PYTEST_EXIT_CODE: ``

@github-actions

Copy link
Copy Markdown

Integration Tests completed with failures or errors.

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: a9ee9cd26bc58768e44aee81ff86d1aaf29878af
  • Current Branch: stakingV5-implementation
  • mx-chain-go Target Branch: master
  • mx-chain-simulator-go Target Branch: stakingV5-implementation
  • mx-chain-testing-suite Target Branch: rc/barnard-patch-3
  • mx-chain-simulator-go Commit Hash: ea407377979389afb6d0f22eba70dbf0c0d12ad4

🚀 Environment Variables:

  • TIMESTAMP: 2025_NOVEMBER_15__05_14_26
  • PYTEST_EXIT_CODE: ``

sstanculeanu
sstanculeanu previously approved these changes Nov 17, 2025
raduchis
raduchis previously approved these changes Nov 17, 2025

@raduchis raduchis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

some imports in the tests are not ok

@github-actions

Copy link
Copy Markdown

Integration Tests passed successfully!

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: a9ee9cd26bc58768e44aee81ff86d1aaf29878af
  • Current Branch: stakingV5-implementation
  • mx-chain-go Target Branch: master
  • mx-chain-simulator-go Target Branch: stakingV5-implementation
  • mx-chain-testing-suite Target Branch: rc/barnard-patch-3
  • mx-chain-simulator-go Commit Hash: ea407377979389afb6d0f22eba70dbf0c0d12ad4

🚀 Environment Variables:

  • TIMESTAMP: 2025_NOVEMBER_17__22_48_21
  • PYTEST_EXIT_CODE: 0

btc-fan
btc-fan previously approved these changes Nov 19, 2025
elvisboghiu
elvisboghiu previously approved these changes Nov 19, 2025
AdoAdoAdo
AdoAdoAdo previously approved these changes Nov 19, 2025
@github-actions

Copy link
Copy Markdown

Integration Tests passed successfully!

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: b30a238bc60091295685a48cdd2c7c1f1501d411
  • Current Branch: stakingV5-implementation
  • mx-chain-go Target Branch: master
  • mx-chain-simulator-go Target Branch: stakingV5-implementation
  • mx-chain-testing-suite Target Branch: rc/barnard-patch-3
  • mx-chain-simulator-go Commit Hash: ea407377979389afb6d0f22eba70dbf0c0d12ad4

🚀 Environment Variables:

  • TIMESTAMP: 2025_NOVEMBER_20__18_21_19
  • PYTEST_EXIT_CODE: 0

@sstanculeanu sstanculeanu merged commit ab874b2 into master Nov 24, 2025
14 of 15 checks passed
@sstanculeanu sstanculeanu deleted the stakingV5-implementation branch November 24, 2025 19:38
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.

7 participants