veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
default_poprewards_calculator.hpp
1// Copyright (c) 2019-2022 Xenios SEZC
2// https://www.veriblock.org
3// Distributed under the MIT software license, see the accompanying
4// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef ALT_INTEGRATION_INCLUDE_VERIBLOCK_DEFAULT_POPREWARDS_CALCULATOR_HPP_
7#define ALT_INTEGRATION_INCLUDE_VERIBLOCK_DEFAULT_POPREWARDS_CALCULATOR_HPP_
8
9#include <veriblock/pop/blockchain/alt_block_tree.hpp>
10#include <veriblock/pop/entities/pop_payouts.hpp>
11
12#include "poprewards_bigdecimal.hpp"
13#include "poprewards_calculator.hpp"
14
15namespace altintegration {
16
22
24 : tree_(tree) {}
25 ~DefaultPopRewardsCalculator() override = default;
26
27 bool getPopPayout(const AltBlockTree::hash_t& tip,
28 PopPayouts& rewards,
29 ValidationState& state) override;
30
41 bool calculatePayouts(const BlockIndex<AltBlock>& endorsedBlock,
42 PopPayouts& rewards,
43 ValidationState& state);
44
51 PopRewardsBigDecimal scoreFromEndorsements(
52 const BlockIndex<AltBlock>& endorsedBlock);
53
59 uint32_t getRoundForBlockNumber(uint32_t height) const;
60
69 PopRewardsBigDecimal calculateBlockReward(
70 uint32_t height,
71 PopRewardsBigDecimal scoreForThisBlock,
72 PopRewardsBigDecimal difficulty) const;
73
82 PopRewardsBigDecimal calculateMinerReward(
83 uint32_t vbkRelativeHeight,
84 const PopRewardsBigDecimal& scoreForThisBlock,
85 const PopRewardsBigDecimal& blockReward) const;
86
87 protected:
88 AltBlockTree& tree_;
89
96 int relativeBlock) const;
97
106 PopRewardsBigDecimal calculateDifficulty(const BlockIndex<AltBlock>& tip);
107
124 const PopRewardsBigDecimal& endorsedBlockScore,
125 const PopRewardsBigDecimal& popDifficulty,
126 PopPayouts& rewards,
127 ValidationState& state);
128};
129
130} // namespace altintegration
131
132#endif // ALT_INTEGRATION_INCLUDE_VERIBLOCK_DEFAULT_POPREWARDS_CALCULATOR_HPP_
Class that is used for storing validation state.
Defines logging helpers.
Definition: block.hpp:14
Represents simplified view on Altchain's block tree, maintains VBK tree and BTC tree.
A node in a block tree.
Definition: block_index.hpp:31
PopRewardsBigDecimal calculateDifficulty(const BlockIndex< AltBlock > &tip)
Calculate POP difficulty using a list of blocks.
PopRewardsBigDecimal getScoreMultiplierFromRelativeBlock(int relativeBlock) const
Applies penalty for distant endorsements in VBK chain.
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 re...
bool calculatePayoutsInner(const BlockIndex< AltBlock > &endorsedBlock, const PopRewardsBigDecimal &endorsedBlockScore, const PopRewardsBigDecimal &popDifficulty, PopPayouts &rewards, ValidationState &state)
Calculate POP rewards for miners.
bool calculatePayouts(const BlockIndex< AltBlock > &endorsedBlock, PopPayouts &rewards, ValidationState &state)
Calculate POP rewards for miners.
PopRewardsBigDecimal scoreFromEndorsements(const BlockIndex< AltBlock > &endorsedBlock)
Collect all endorsements for the endorsed block and calculate POP score.
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...
uint32_t getRoundForBlockNumber(uint32_t height) const
Calculate payout round from the given block height.
bool getPopPayout(const AltBlockTree::hash_t &tip, PopPayouts &rewards, ValidationState &state) override
Calculate POP rewards for miners.
A container for Pop payouts information.
Definition: pop_payouts.hpp:28