veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
altintegration::DefaultPopRewardsCalculator Struct Reference

Detailed Description

Invariant
does not modify any on-disk state.

Definition at line 20 of file default_poprewards_calculator.hpp.

#include <default_poprewards_calculator.hpp>

+ Inheritance diagram for altintegration::DefaultPopRewardsCalculator:
+ Collaboration diagram for altintegration::DefaultPopRewardsCalculator:

Public Types

using index_t = AltBlockTree::index_t
 

Public Member Functions

 DefaultPopRewardsCalculator (AltBlockTree &tree)
 
bool getPopPayout (const AltBlockTree::hash_t &tip, PopPayouts &rewards, ValidationState &state) override
 Calculate POP rewards for miners. More...
 
bool calculatePayouts (const BlockIndex< AltBlock > &endorsedBlock, PopPayouts &rewards, ValidationState &state)
 Calculate POP rewards for miners. More...
 
PopRewardsBigDecimal scoreFromEndorsements (const BlockIndex< AltBlock > &endorsedBlock)
 Collect all endorsements for the endorsed block and calculate POP score. More...
 
uint32_t getRoundForBlockNumber (uint32_t height) const
 Calculate payout round from the given block height. More...
 
PopRewardsBigDecimal calculateBlockReward (uint32_t height, PopRewardsBigDecimal scoreForThisBlock, PopRewardsBigDecimal difficulty) const
 Calculate reward for the entire block from the block score, height of the VBK endorsement and current POP difficulty. More...
 
PopRewardsBigDecimal calculateMinerReward (uint32_t vbkRelativeHeight, const PopRewardsBigDecimal &scoreForThisBlock, const PopRewardsBigDecimal &blockReward) const
 Calculate reward for the miner from the block score, height of the VBK endorsement and total block reward. More...
 
virtual bool getPopPayout (const AltBlockTree::hash_t &tip, PopPayouts &rewards, ValidationState &state)=0
 Calculate POP rewards for miners. More...
 

Protected Member Functions

PopRewardsBigDecimal getScoreMultiplierFromRelativeBlock (int relativeBlock) const
 Applies penalty for distant endorsements in VBK chain. More...
 
PopRewardsBigDecimal calculateDifficulty (const BlockIndex< AltBlock > &tip)
 Calculate POP difficulty using a list of blocks. More...
 
bool calculatePayoutsInner (const BlockIndex< AltBlock > &endorsedBlock, const PopRewardsBigDecimal &endorsedBlockScore, const PopRewardsBigDecimal &popDifficulty, PopPayouts &rewards, ValidationState &state)
 Calculate POP rewards for miners. More...
 

Protected Attributes

AltBlockTreetree_
 

Member Typedef Documentation

◆ index_t

Constructor & Destructor Documentation

◆ DefaultPopRewardsCalculator()

altintegration::DefaultPopRewardsCalculator::DefaultPopRewardsCalculator ( AltBlockTree tree)
inline

Definition at line 23 of file default_poprewards_calculator.hpp.

24 : tree_(tree) {}

Member Function Documentation

◆ calculateBlockReward()

PopRewardsBigDecimal altintegration::DefaultPopRewardsCalculator::calculateBlockReward ( uint32_t  height,
PopRewardsBigDecimal  scoreForThisBlock,
PopRewardsBigDecimal  difficulty 
) const
Parameters
heightreward is calculated for the block at this height.
scoreForThisBlockblock score
difficultycurrent POP difficulty
Returns
PopRewardsBigDecimal resulting reward for the block

◆ calculateDifficulty()

PopRewardsBigDecimal altintegration::DefaultPopRewardsCalculator::calculateDifficulty ( const BlockIndex< AltBlock > &  tip)
protected

Should provide at least rewardSettlementInterval blocks. Will use first blocks (usually difficultyAveragingInterval blocks) to calculate their scores and average them to get difficulty.

Parameters
tipcalculate difficulty using chain ending with this tip
Returns
PopRewardsBigDecimal resulting difficulty

◆ calculateMinerReward()

PopRewardsBigDecimal altintegration::DefaultPopRewardsCalculator::calculateMinerReward ( uint32_t  vbkRelativeHeight,
const PopRewardsBigDecimal &  scoreForThisBlock,
const PopRewardsBigDecimal &  blockReward 
) const
Parameters
vbkRelativeHeightheight of the VBK block with endorsement
scoreForThisBlockblock score
blockRewardtotal block reward
Returns
PopRewardsBigDecimal resulting reward for each miner

◆ calculatePayouts()

bool altintegration::DefaultPopRewardsCalculator::calculatePayouts ( const BlockIndex< AltBlock > &  endorsedBlock,
PopPayouts rewards,
ValidationState state 
)

Rewards are calculated for the endorsed block. Score is calculated from the endorsements (slow).

Parameters
endorsedBlockendorsed altchain block which we are paying reward for.
[out]rewardsPopPayouts map with miner address as a key and reward amount as a value.
[out]statevalidation state.
Returns
true if rewards are calculated properly; false otherwise.

◆ calculatePayoutsInner()

bool altintegration::DefaultPopRewardsCalculator::calculatePayoutsInner ( const BlockIndex< AltBlock > &  endorsedBlock,
const PopRewardsBigDecimal &  endorsedBlockScore,
const PopRewardsBigDecimal &  popDifficulty,
PopPayouts rewards,
ValidationState state 
)
protected

Rewards are calculated for the endorsed block. Block score and POP difficulty are set as arguments to allow caching them.

Parameters
endorsedBlockendorsed altchain block which we are paying reward for.
endorsedBlockScoreendorsed altchain block score - see scoreFromEndorsements() for reference.
popDifficultyendorsed altchain block difficulty - see calculateDifficulty() for reference.
[out]rewardsPopPayouts map with miner address as a key and reward amount as a value.
[out]statevalidation state.
Returns
true if rewards are calculated properly; false otherwise.

◆ getPopPayout()

bool altintegration::DefaultPopRewardsCalculator::getPopPayout ( const AltBlockTree::hash_t &  tip,
PopPayouts rewards,
ValidationState state 
)
overridevirtual

Rewards are calculated for the endorsed block which is PopPayoutDelay blocks behind the tip.

Parameters
tiplast block of the active chain. Next block should contain POP payout calculated with this getPopPayout() call.
[out]rewardsPopPayouts map with miner address as a key and reward amount as a value.
[out]statevalidation state.
Returns
true if rewards are calculated properly; false otherwise.

Implements altintegration::PopRewardsCalculator.

◆ getRoundForBlockNumber()

uint32_t altintegration::DefaultPopRewardsCalculator::getRoundForBlockNumber ( uint32_t  height) const
Parameters
heightblock height
Returns
uint32_t current round

◆ getScoreMultiplierFromRelativeBlock()

PopRewardsBigDecimal altintegration::DefaultPopRewardsCalculator::getScoreMultiplierFromRelativeBlock ( int  relativeBlock) const
protected
Parameters
relativeBlockheight of the VBK block with endorsement
Returns
PopRewardsBigDecimal multiplier to apply to the block reward

◆ scoreFromEndorsements()

PopRewardsBigDecimal altintegration::DefaultPopRewardsCalculator::scoreFromEndorsements ( const BlockIndex< AltBlock > &  endorsedBlock)
Parameters
endorsedBlockcalculate score for this block
Returns
PopRewardsBigDecimal resulting score

Member Data Documentation

◆ tree_

AltBlockTree& altintegration::DefaultPopRewardsCalculator::tree_
protected

Definition at line 88 of file default_poprewards_calculator.hpp.


The documentation for this struct was generated from the following file: