Staking v5 implementation#7386
Conversation
|
❌ Integration Tests completed with failures or errors. 📊 MultiversX Automated Test Report: View Report 🔄 Build Details:
🚀 Environment Variables:
|
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
|
❌ Integration Tests completed with failures or errors. 📊 MultiversX Automated Test Report: View Report 🔄 Build Details:
🚀 Environment Variables:
|
|
❌ Integration Tests completed with failures or errors. 📊 MultiversX Automated Test Report: View Report 🔄 Build Details:
🚀 Environment Variables:
|
|
❌ Integration Tests completed with failures or errors. 📊 MultiversX Automated Test Report: View Report 🔄 Build Details:
🚀 Environment Variables:
|
|
❌ Integration Tests completed with failures or errors. 📊 MultiversX Automated Test Report: View Report 🔄 Build Details:
🚀 Environment Variables:
|
|
❌ Integration Tests completed with failures or errors. 📊 MultiversX Automated Test Report: View Report 🔄 Build Details:
🚀 Environment Variables:
|
|
|
||
| supplyToUseForRewardsperBlock := e.genesisTotalSupply | ||
| if metaBlock.Epoch >= e.accRewardsEnableEpoch { | ||
| supplyToUseForRewardsperBlock = prevEpochEconomics.TotalSupply |
There was a problem hiding this comment.
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.
| totalNumBlocksInEpoch := e.computeNumOfTotalCreatedBlocks(noncesPerShardPrevEpoch, noncesPerShardCurrEpoch) | ||
|
|
||
| supplyToUseForRewardsperBlock := e.genesisTotalSupply | ||
| if metaBlock.Epoch >= e.accRewardsEnableEpoch { |
There was a problem hiding this comment.
should this be switched to >?
shouldn't we still use genesis total supply if metaBlock.Epoch == activation epoch?
There was a problem hiding this comment.
it can happen at activation epoch.
| } | ||
|
|
||
| func (e *economics) computeRewardsForAccelerator(totalRewards *big.Int, epoch uint32) *big.Int { | ||
| if e.accRewardsEnableEpoch >= epoch { |
There was a problem hiding this comment.
this >= will be true for activation epoch, which means on L139, if metaBlock.Epoch >= e.accRewardsEnableEpoch must use >, right?
There was a problem hiding this comment.
it can start happening at activation epoch. No strong opinion on this.
|
|
||
| supplyToUseForRewardsperBlock := e.genesisTotalSupply | ||
| if metaBlock.Epoch >= e.accRewardsEnableEpoch { | ||
| supplyToUseForRewardsperBlock = prevEpochEconomics.TotalSupply |
There was a problem hiding this comment.
| supplyToUseForRewardsperBlock = prevEpochEconomics.TotalSupply | |
| supplyToUseForRewardsPerBlock = prevEpochEconomics.TotalSupply |
| year1Inflation := 0.1 | ||
| minInflation := 0.01 | ||
| enableEpochHandler := &mock.EnableEpochsHandlerMock{} | ||
| gsh := &globalSettingsHandler{ |
There was a problem hiding this comment.
use constructor for extra coverage
|
❌ Integration Tests completed with failures or errors. 📊 MultiversX Automated Test Report: View Report 🔄 Build Details:
🚀 Environment Variables:
|
|
❌ Integration Tests completed with failures or errors. 📊 MultiversX Automated Test Report: View Report 🔄 Build Details:
🚀 Environment Variables:
|
|
❌ Integration Tests completed with failures or errors. 📊 MultiversX Automated Test Report: View Report 🔄 Build Details:
🚀 Environment Variables:
|
|
❌ Integration Tests completed with failures or errors. 📊 MultiversX Automated Test Report: View Report 🔄 Build Details:
🚀 Environment Variables:
|
|
✅ Integration Tests passed successfully! 📊 MultiversX Automated Test Report: View Report 🔄 Build Details:
🚀 Environment Variables:
|
|
✅ Integration Tests passed successfully! 📊 MultiversX Automated Test Report: View Report 🔄 Build Details:
🚀 Environment Variables:
|
|
✅ Integration Tests passed successfully! 📊 MultiversX Automated Test Report: View Report 🔄 Build Details:
🚀 Environment Variables:
|
|
✅ Integration Tests passed successfully! 📊 MultiversX Automated Test Report: View Report 🔄 Build Details:
🚀 Environment Variables:
|
a9ee9cd
|
❌ Integration Tests completed with failures or errors. 📊 MultiversX Automated Test Report: View Report 🔄 Build Details:
🚀 Environment Variables:
|
|
❌ Integration Tests completed with failures or errors. 📊 MultiversX Automated Test Report: View Report 🔄 Build Details:
🚀 Environment Variables:
|
raduchis
left a comment
There was a problem hiding this comment.
some imports in the tests are not ok
|
✅ Integration Tests passed successfully! 📊 MultiversX Automated Test Report: View Report 🔄 Build Details:
🚀 Environment Variables:
|
b30a238
|
✅ Integration Tests passed successfully! 📊 MultiversX Automated Test Report: View Report 🔄 Build Details:
🚀 Environment Variables:
|
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.