@@ -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
4748type 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
10798func (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
327317func (brc * baseRewardsCreator ) isSystemDelegationSC (address []byte ) bool {
@@ -345,14 +335,14 @@ func (brc *baseRewardsCreator) isSystemDelegationSC(address []byte) bool {
345335
346336func (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}
0 commit comments