TARAXA
Loading...
Searching...
No Matches
block_stats.hpp
Go to the documentation of this file.
1#pragma once
2
4#include "common/types.hpp"
6#include "vote/pbft_vote.hpp"
7
8namespace taraxa::rewards {
9
15 public:
16 // Needed for RLP
17 BlockStats() = default;
25 BlockStats(const PeriodData& block, const std::vector<gas_t>& trxs_gas_used, uint64_t dpos_vote_count,
26 uint32_t committee_size, const bool aspen_dag_rewards = false);
27
29
30 private:
37 void processStats(const PeriodData& block, const bool aspen_dag_rewards);
38
44 void processDagBlocks(const PeriodData& block);
45
51 void processDagBlocksAspen(const PeriodData& block);
52
59 void initFeeByTrxHash(const SharedTransactions& transactions, const std::vector<gas_t>& trxs_gas_used);
60
69 bool addTransaction(const trx_hash_t& trx_hash, const addr_t& validator);
70
78 bool addVote(const std::shared_ptr<PbftVote>& vote);
79
80 protected:
82 // count of rewardable(with 1 or more unique transactions) DAG blocks produced by this validator
83 uint32_t dag_blocks_count_ = 0;
84
85 // Validator cert voted block weight
86 uint64_t vote_weight_ = 0;
87
88 u256 fees_rewards_ = 0;
89
91 };
92
93 // Pbft block author
95
96 // Fee by trx : trx hash -> fee
97 std::unordered_map<trx_hash_t, u256> fee_by_trx_hash_;
98
99 // Validator stats: validator -> ValidatorStats
100 std::unordered_map<addr_t, ValidatorStats> validators_stats_;
101
102 // Total rewardable(with 1 or more unique transactions) DAG blocks count
104
105 // Total weight of votes in block
107
108 // Max weight of votes in block
109 uint64_t max_votes_weight_{0};
110};
111
112} // namespace taraxa::rewards
Definition block_stats.hpp:14
bool addVote(const std::shared_ptr< PbftVote > &vote)
In case unique vote is provided, author's votes weight is updated. If provided vote was already proce...
Definition block_stats.cpp:45
bool addTransaction(const trx_hash_t &trx_hash, const addr_t &validator)
In case unique trx_hash is provided, it is mapped to it's validator's address + validator's unique tr...
Definition block_stats.cpp:31
addr_t block_author_
Definition block_stats.hpp:94
void initFeeByTrxHash(const SharedTransactions &transactions, const std::vector< gas_t > &trxs_gas_used)
Prepare fee_by_trx_hash_ map with trx fee by trx hash.
Definition block_stats.cpp:17
uint64_t total_votes_weight_
Definition block_stats.hpp:106
void processDagBlocks(const PeriodData &block)
Process Dag blocks and save stats in class for future serialization. returns.
Definition block_stats.cpp:86
uint32_t dag_blocks_count_
Definition block_stats.hpp:83
void processStats(const PeriodData &block, const bool aspen_dag_rewards)
Process PeriodData and save stats in class for future serialization. returns.
Definition block_stats.cpp:70
std::unordered_map< addr_t, ValidatorStats > validators_stats_
Definition block_stats.hpp:100
uint64_t vote_weight_
Definition block_stats.hpp:86
u256 fees_rewards_
Definition block_stats.hpp:88
uint64_t max_votes_weight_
Definition block_stats.hpp:109
void processDagBlocksAspen(const PeriodData &block)
Process Dag blocks and save stats in class for future serialization with aspen HF changes....
Definition block_stats.cpp:110
std::unordered_map< trx_hash_t, u256 > fee_by_trx_hash_
Definition block_stats.hpp:97
uint32_t total_dag_blocks_count_
Definition block_stats.hpp:103
Definition block_stats.hpp:81
#define HAS_RLP_FIELDS
Definition encoding_rlp.hpp:208
PeriodData class is for block execution, that includes PBFT block, certify votes, DAG blocks,...
Definition period_data.hpp:26
Definition block_stats.hpp:8
std::vector< SharedTransaction > SharedTransactions
Definition transaction.hpp:86