Skip to content

Commit ab874b2

Browse files
authored
Merge pull request #7386 from multiversx/stakingV5-implementation
Staking v5 implementation
2 parents 327750c + b30a238 commit ab874b2

47 files changed

Lines changed: 1368 additions & 214 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/node/config/economics.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,23 @@
1818
Denomination = 18 # represents the smallest eGLD subdivision (10^-X eGLD for a denomination of X)
1919
GenesisMintingSenderAddress = "erd17rc0pu8s7rc0pu8s7rc0pu8s7rc0pu8s7rc0pu8s7rc0pu8s7rcqqkhty3"
2020

21+
[GlobalSettings.TailInflation]
22+
EnableEpoch = 10
23+
StartYearInflation = 0.08757
24+
DecayPercentage = 0.0025
25+
MinimumInflation = 0.02
26+
2127
[RewardsSettings]
2228
[[RewardsSettings.RewardsConfigByEpoch]]
2329
EpochEnable = 0
2430
LeaderPercentage = 0.1 #fraction of value 0.1 - 10%
2531
DeveloperPercentage = 0.3 #fraction of value 0.3 - 30%
2632
ProtocolSustainabilityPercentage = 0.1 #fraction of value 0.1 - 10%
2733
ProtocolSustainabilityAddress = "erd1j25xk97yf820rgdp3mj5scavhjkn6tjyn0t63pmv5qyjj7wxlcfqqe2rw5"
34+
EcosystemGrowthPercentage = 0.0
35+
EcosystemGrowthAddress = "erd1k8d58eve7aa64wjad35sx6z8ckgr738wl7jyz54pez0t4zr98fuqz6hxvs"
36+
GrowthDividendPercentage = 0.0
37+
GrowthDividendAddress = "erd1enva49yfy9ja0e4ttncfmzr0vjv9k9rawuyg2h2g8nepqwmz8ltssvkglr"
2838
TopUpGradientPoint = "3000000000000000000000000" # 3MIL eGLD (eligible topUp)
2939
TopUpFactor = 0.25 # fraction of value 0.25 - 25%
3040

@@ -34,6 +44,23 @@
3444
DeveloperPercentage = 0.3 #fraction of value 0.3 - 30%
3545
ProtocolSustainabilityPercentage = 0.1 #fraction of value 0.1 - 10%
3646
ProtocolSustainabilityAddress = "erd1e5cw5pegj9w2zfpzeq94wf3d5tp6g943xuhgnyysdwyr63rlkspqr0u05s"
47+
EcosystemGrowthPercentage = 0.0
48+
EcosystemGrowthAddress = "erd1k8d58eve7aa64wjad35sx6z8ckgr738wl7jyz54pez0t4zr98fuqz6hxvs"
49+
GrowthDividendPercentage = 0.0
50+
GrowthDividendAddress = "erd1enva49yfy9ja0e4ttncfmzr0vjv9k9rawuyg2h2g8nepqwmz8ltssvkglr"
51+
TopUpGradientPoint = "2000000000000000000000000" # 2MIL eGLD (eligible topUp)
52+
TopUpFactor = 0.5 # fraction of value 0.5 - 50%
53+
54+
[[RewardsSettings.RewardsConfigByEpoch]]
55+
EpochEnable = 10
56+
LeaderPercentage = 0.1 #fraction of value 0.1 - 10%
57+
DeveloperPercentage = 0.3 #fraction of value 0.3 - 30%
58+
ProtocolSustainabilityPercentage = 0.1 #fraction of value 0.1 - 10%
59+
ProtocolSustainabilityAddress = "erd1e5cw5pegj9w2zfpzeq94wf3d5tp6g943xuhgnyysdwyr63rlkspqr0u05s"
60+
EcosystemGrowthPercentage = 0.2 #fraction of value 0.2 - 20%
61+
EcosystemGrowthAddress = "erd1k8d58eve7aa64wjad35sx6z8ckgr738wl7jyz54pez0t4zr98fuqz6hxvs"
62+
GrowthDividendPercentage = 0.2 #fraction of value 0.2 - 20%
63+
GrowthDividendAddress = "erd1enva49yfy9ja0e4ttncfmzr0vjv9k9rawuyg2h2g8nepqwmz8ltssvkglr"
3764
TopUpGradientPoint = "2000000000000000000000000" # 2MIL eGLD (eligible topUp)
3865
TopUpFactor = 0.5 # fraction of value 0.5 - 50%
3966

config/economicsConfig.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ type GlobalSettings struct {
77
YearSettings []*YearSetting
88
Denomination int
99
GenesisMintingSenderAddress string
10+
TailInflation TailInflationSettings
11+
}
12+
13+
// TailInflationSettings will hold the tail inflation settings
14+
type TailInflationSettings struct {
15+
EnableEpoch uint32
16+
StartYearInflation float64
17+
DecayPercentage float64
18+
MinimumInflation float64
1019
}
1120

1221
// YearSetting will hold the maximum inflation rate for year
@@ -26,6 +35,10 @@ type EpochRewardSettings struct {
2635
DeveloperPercentage float64
2736
ProtocolSustainabilityPercentage float64
2837
ProtocolSustainabilityAddress string
38+
EcosystemGrowthPercentage float64
39+
EcosystemGrowthAddress string
40+
GrowthDividendPercentage float64
41+
GrowthDividendAddress string
2942
TopUpGradientPoint string
3043
TopUpFactor float64
3144
EpochEnable uint32

epochStart/interface.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,19 @@ type EpochEconomicsDataProvider interface {
183183
SetLeadersFees(fees *big.Int)
184184
SetRewardsToBeDistributed(rewards *big.Int)
185185
SetRewardsToBeDistributedForBlocks(rewards *big.Int)
186+
SetRewardsForProtocolSustainability(rewards *big.Int)
187+
SetRewardsForEcosystemGrowth(rewards *big.Int)
188+
SetRewardsForGrowthDividend(rewards *big.Int)
186189
NumberOfBlocks() uint64
187190
NumberOfBlocksPerShard() map[uint32]uint64
188191
LeaderFees() *big.Int
189192
RewardsToBeDistributed() *big.Int
190193
RewardsToBeDistributedForBlocks() *big.Int
194+
RewardsForProtocolSustainability() *big.Int
195+
RewardsForEcosystemGrowth() *big.Int
196+
RewardsForGrowthDividend() *big.Int
197+
RewardsForAccelerator() *big.Int
198+
Clean()
191199
IsInterfaceNil() bool
192200
}
193201

@@ -199,7 +207,7 @@ type RewardsCreator interface {
199207
VerifyRewardsMiniBlocks(
200208
metaBlock data.MetaHeaderHandler, validatorsInfo state.ShardValidatorsInfoMapHandler, computedEconomics *block.Economics,
201209
) error
202-
GetProtocolSustainabilityRewards() *big.Int
210+
GetAcceleratorRewards() *big.Int
203211
GetLocalTxCache() TransactionCacher
204212
CreateMarshalledData(body *block.Body) map[string][][]byte
205213
GetRewardsTxs(body *block.Body) map[string]data.TransactionHandler

epochStart/metachain/baseRewards.go

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type BaseRewardsCreatorArgs struct {
4242
EnableEpochsHandler common.EnableEpochsHandler
4343
ExecutionOrderHandler common.TxExecutionOrderHandler
4444
RewardsHandler process.RewardsHandler
45+
EconomicsData epochStart.EpochEconomicsDataProvider
4546
}
4647

4748
type baseRewardsCreator struct {
@@ -56,7 +57,6 @@ type baseRewardsCreator struct {
5657
dataPool dataRetriever.PoolsHolder
5758
mapBaseRewardsPerBlockPerValidator map[uint32]*big.Int
5859
accumulatedRewards *big.Int
59-
protocolSustainabilityValue *big.Int
6060
flagDelegationSystemSCEnabled atomic.Flag // nolint
6161
userAccountsDB state.AccountsAdapter
6262
enableEpochsHandler common.EnableEpochsHandler
@@ -84,7 +84,6 @@ func NewBaseRewardsCreator(args BaseRewardsCreatorArgs) (*baseRewardsCreator, er
8484
dataPool: args.DataPool,
8585
nodesConfigProvider: args.NodesConfigProvider,
8686
accumulatedRewards: big.NewInt(0),
87-
protocolSustainabilityValue: big.NewInt(0),
8887
userAccountsDB: args.UserAccountsDB,
8988
mapBaseRewardsPerBlockPerValidator: make(map[uint32]*big.Int),
9089
enableEpochsHandler: args.EnableEpochsHandler,
@@ -95,14 +94,6 @@ func NewBaseRewardsCreator(args BaseRewardsCreatorArgs) (*baseRewardsCreator, er
9594
return brc, nil
9695
}
9796

98-
// GetProtocolSustainabilityRewards returns the sum of all rewards
99-
func (brc *baseRewardsCreator) GetProtocolSustainabilityRewards() *big.Int {
100-
brc.mutRewardsData.RLock()
101-
defer brc.mutRewardsData.RUnlock()
102-
103-
return brc.protocolSustainabilityValue
104-
}
105-
10697
// GetLocalTxCache returns the local tx cache which holds all the rewards
10798
func (brc *baseRewardsCreator) GetLocalTxCache() epochStart.TransactionCacher {
10899
return brc.currTxs
@@ -321,7 +312,6 @@ func (brc *baseRewardsCreator) clean() {
321312
brc.mapBaseRewardsPerBlockPerValidator = make(map[uint32]*big.Int)
322313
brc.currTxs.Clean()
323314
brc.accumulatedRewards = big.NewInt(0)
324-
brc.protocolSustainabilityValue = big.NewInt(0)
325315
}
326316

327317
func (brc *baseRewardsCreator) isSystemDelegationSC(address []byte) bool {
@@ -345,14 +335,14 @@ func (brc *baseRewardsCreator) isSystemDelegationSC(address []byte) bool {
345335

346336
func (brc *baseRewardsCreator) createProtocolSustainabilityRewardTransaction(
347337
metaBlock data.HeaderHandler,
348-
computedEconomics *block.Economics,
338+
protocolSustainability *big.Int,
349339
) (*rewardTx.RewardTx, uint32, error) {
350340

351341
protocolSustainabilityAddressForEpoch := brc.rewardsHandler.ProtocolSustainabilityAddressInEpoch(metaBlock.GetEpoch())
352342
protocolSustainabilityShardID := brc.shardCoordinator.ComputeId([]byte(protocolSustainabilityAddressForEpoch))
353343
protocolSustainabilityRwdTx := &rewardTx.RewardTx{
354344
Round: metaBlock.GetRound(),
355-
Value: big.NewInt(0).Set(computedEconomics.RewardsForProtocolSustainability),
345+
Value: big.NewInt(0).Set(protocolSustainability),
356346
RcvAddr: []byte(protocolSustainabilityAddressForEpoch),
357347
Epoch: metaBlock.GetEpoch(),
358348
}
@@ -402,19 +392,25 @@ func (brc *baseRewardsCreator) initializeRewardsMiniBlocks() block.MiniBlockSlic
402392
return miniBlocks
403393
}
404394

405-
func (brc *baseRewardsCreator) addProtocolRewardToMiniBlocks(
406-
protocolSustainabilityRwdTx *rewardTx.RewardTx,
395+
func (brc *baseRewardsCreator) addAcceleratorRewardToMiniBlocks(
396+
acceleratorRewardTx *rewardTx.RewardTx,
407397
miniBlocks block.MiniBlockSlice,
408-
protocolSustainabilityShardId uint32,
398+
shardID uint32,
409399
) error {
410-
protocolSustainabilityRwdHash, errHash := core.CalculateHash(brc.marshalizer, brc.hasher, protocolSustainabilityRwdTx)
400+
protocolSustainabilityRwdHash, errHash := core.CalculateHash(brc.marshalizer, brc.hasher, acceleratorRewardTx)
411401
if errHash != nil {
412402
return errHash
413403
}
404+
if acceleratorRewardTx.Value.Cmp(zero) < 0 {
405+
return errNegativeAcceleratorReward
406+
}
407+
if acceleratorRewardTx.Value.Cmp(zero) == 0 {
408+
// do not add to the miniblock
409+
return nil
410+
}
414411

415-
brc.currTxs.AddTx(protocolSustainabilityRwdHash, protocolSustainabilityRwdTx)
416-
miniBlocks[protocolSustainabilityShardId].TxHashes = append(miniBlocks[protocolSustainabilityShardId].TxHashes, protocolSustainabilityRwdHash)
417-
brc.protocolSustainabilityValue.Set(protocolSustainabilityRwdTx.Value)
412+
brc.currTxs.AddTx(protocolSustainabilityRwdHash, acceleratorRewardTx)
413+
miniBlocks[shardID].TxHashes = append(miniBlocks[shardID].TxHashes, protocolSustainabilityRwdHash)
418414

419415
return nil
420416
}

epochStart/metachain/baseRewards_test.go

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,12 @@ func TestBaseRewardsCreator_clean(t *testing.T) {
185185
require.Nil(t, err)
186186

187187
rwd.accumulatedRewards = big.NewInt(1000)
188-
rwd.protocolSustainabilityValue = big.NewInt(100)
189188
rwd.mapBaseRewardsPerBlockPerValidator[0] = big.NewInt(10)
190189
txHash := []byte("txHash")
191190
rwd.currTxs.AddTx(txHash, &rewardTx.RewardTx{})
192191

193192
rwd.clean()
194193
require.Equal(t, big.NewInt(0), rwd.accumulatedRewards)
195-
require.Equal(t, big.NewInt(0), rwd.protocolSustainabilityValue)
196194
require.Equal(t, 0, len(rwd.mapBaseRewardsPerBlockPerValidator))
197195
tx, err := rwd.currTxs.GetTx(txHash)
198196
require.Nil(t, tx)
@@ -220,28 +218,15 @@ func TestBaseRewardsCreator_GetLocalTxCache(t *testing.T) {
220218
require.False(t, check.IfNil(txCache))
221219
}
222220

223-
func TestBaseRewardsCreator_GetProtocolSustainabilityRewards(t *testing.T) {
221+
func TestBaseRewardsCreator_addAcceleratorRewardToMiniBlocks(t *testing.T) {
224222
t.Parallel()
225223

226224
args := getBaseRewardsArguments()
227225
rwd, err := NewBaseRewardsCreator(args)
228226
require.Nil(t, err)
229227
require.NotNil(t, rwd)
230228

231-
// should return 0 as just initialized
232-
rewards := rwd.GetProtocolSustainabilityRewards()
233-
require.Zero(t, big.NewInt(0).Cmp(rewards))
234-
}
235-
236-
func TestBaseRewardsCreator_addProtocolRewardToMiniblocks(t *testing.T) {
237-
t.Parallel()
238-
239-
args := getBaseRewardsArguments()
240-
rwd, err := NewBaseRewardsCreator(args)
241-
require.Nil(t, err)
242-
require.NotNil(t, rwd)
243-
244-
initialProtRewardValue := big.NewInt(-100)
229+
initialProtRewardValue := big.NewInt(100)
245230
protRwAddr, _ := args.PubkeyConverter.Decode(args.RewardsHandler.ProtocolSustainabilityAddressInEpoch(0))
246231
protRwTx := &rewardTx.RewardTx{
247232
Round: 100,
@@ -257,7 +242,7 @@ func TestBaseRewardsCreator_addProtocolRewardToMiniblocks(t *testing.T) {
257242

258243
protRwShard := args.ShardCoordinator.ComputeId(protRwAddr)
259244
mbSlice := createDefaultMiniBlocksSlice()
260-
err = rwd.addProtocolRewardToMiniBlocks(protRwTx, mbSlice, protRwShard)
245+
err = rwd.addAcceleratorRewardToMiniBlocks(protRwTx, mbSlice, protRwShard)
261246
require.Nil(t, err)
262247

263248
found := false
@@ -898,7 +883,7 @@ func TestBaseRewardsCreator_createProtocolSustainabilityRewardTransaction(t *tes
898883
DevFeesInEpoch: big.NewInt(0),
899884
}
900885

901-
rwTx, _, err := rwd.createProtocolSustainabilityRewardTransaction(metaBlk, &metaBlk.EpochStart.Economics)
886+
rwTx, _, err := rwd.createProtocolSustainabilityRewardTransaction(metaBlk, metaBlk.EpochStart.Economics.RewardsForProtocolSustainability)
902887
require.Nil(t, err)
903888
require.NotNil(t, rwTx)
904889
require.Equal(t, metaBlk.EpochStart.Economics.RewardsForProtocolSustainability, rwTx.Value)

0 commit comments

Comments
 (0)