-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refector: move process rewards stats functionality to separate class
- Loading branch information
Showing
10 changed files
with
90 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
libraries/core_libs/consensus/include/rewards/rewards_stats.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "config/hardfork.hpp" | ||
#include "rewards/block_stats.hpp" | ||
|
||
namespace taraxa::rewards { | ||
class Stats { | ||
public: | ||
Stats(uint32_t committee_size, std::function<uint64_t(EthBlockNumber)>&& dpos_eligible_total_vote_count); | ||
|
||
std::vector<BlockStats> getStats(const PeriodData& current_blk); | ||
|
||
private: | ||
BlockStats getBlockStats(const PeriodData& current_blk); | ||
|
||
const uint32_t kCommitteeSize; | ||
const std::function<uint64_t(EthBlockNumber)> dpos_eligible_total_vote_count_; | ||
}; | ||
} // namespace taraxa::rewards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
libraries/core_libs/consensus/src/rewards/rewards_stats.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "rewards/rewards_stats.hpp" | ||
|
||
#include "storage/storage.hpp" | ||
|
||
namespace taraxa::rewards { | ||
Stats::Stats(uint32_t committee_size, std::function<uint64_t(EthBlockNumber)>&& dpos_eligible_total_vote_count) | ||
: kCommitteeSize(committee_size), dpos_eligible_total_vote_count_(dpos_eligible_total_vote_count) {} | ||
|
||
// std::vector<RewardsStats> processBlockHardfork(const PeriodData& current_blk, uint32_t interval) { | ||
// const auto current = current_blk.pbft_blk->getPeriod(); | ||
// // skip for intermediate blocks | ||
// if (current % interval != 0) { | ||
// return {}; | ||
// } | ||
|
||
// std::vector<RewardsStats> rewards_stats; | ||
// rewards_stats.reserve(interval); | ||
// // add rewards stats for (last_distribution_block, current_block) | ||
// for (auto p = current - interval + 1; p < current; ++p) { | ||
// auto blk = PeriodData(db_->getPeriodDataRaw(p)); | ||
// rewards_stats.emplace_back(get_block_rewards_stats(blk)); | ||
// } | ||
// // add current block rewards stats | ||
// rewards_stats.emplace_back(get_block_rewards_stats(current_blk)); | ||
|
||
// return rewards_stats; | ||
// } | ||
|
||
BlockStats Stats::getBlockStats(const PeriodData& blk) { | ||
uint64_t dpos_vote_count = kCommitteeSize; | ||
|
||
// Block zero | ||
if (!blk.previous_block_cert_votes.empty()) [[likely]] { | ||
dpos_vote_count = dpos_eligible_total_vote_count_(blk.previous_block_cert_votes[0]->getPeriod() - 1); | ||
} | ||
|
||
return BlockStats{blk, dpos_vote_count, kCommitteeSize}; | ||
} | ||
|
||
std::vector<BlockStats> Stats::getStats(const PeriodData& current_blk) { return {getBlockStats(current_blk)}; } | ||
} // namespace taraxa::rewards |
Submodule taraxa-evm
updated
10 files