-
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.
feat: add option to change rewards distribution frequency with hardfork
- Loading branch information
Showing
18 changed files
with
350 additions
and
44 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
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
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
43 changes: 40 additions & 3 deletions
43
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 |
---|---|---|
@@ -1,17 +1,54 @@ | ||
#include "config/hardfork.hpp" | ||
#include "rewards/block_stats.hpp" | ||
#include "storage/storage.hpp" | ||
|
||
namespace taraxa::rewards { | ||
/* | ||
* @brief class that is managing rewards stats processing and hardforks(intervals changes) | ||
* So intermediate blocks stats are stored in the vector in data(to restore on the node restart) | ||
* and full list of interval stats is returned in the end of interval | ||
*/ | ||
class Stats { | ||
public: | ||
Stats(uint32_t committee_size, std::function<uint64_t(EthBlockNumber)>&& dpos_eligible_total_vote_count); | ||
Stats(uint32_t committee_size, const Hardforks::RewardsDistributionMap& rdm, std::shared_ptr<DB> db, | ||
std::function<uint64_t(EthBlockNumber)>&& dpos_eligible_total_vote_count); | ||
|
||
std::vector<BlockStats> getStats(const PeriodData& current_blk); | ||
/* | ||
* @brief processing passed block and returns stats that should be processed at this block | ||
* @param current_blk block to process | ||
* @return vector<BlockStats> that should be processed at current block | ||
*/ | ||
std::vector<BlockStats> processStats(const PeriodData& current_blk); | ||
|
||
private: | ||
protected: | ||
/* | ||
* @brief load current interval stats from database | ||
*/ | ||
void loadFromDb(); | ||
/* | ||
* @brief returns rewards distribution frequency for specified period | ||
*/ | ||
uint32_t getCurrentDistributionFrequency(uint64_t current_period) const; | ||
/* | ||
* @brief gets all needed data and makes(processes) BlocksStats | ||
* @param current_blk block to process | ||
* @return block statistics needed for rewards distribution | ||
*/ | ||
BlockStats getBlockStats(const PeriodData& current_blk); | ||
/* | ||
* @brief saves stats to database to not lose this data in case of node restart | ||
*/ | ||
void saveBlockStats(uint64_t number, const BlockStats& stats); | ||
/* | ||
* @brief called on start of new rewards interval. clears blocks_stats_ collection | ||
* and removes all data saved in db column | ||
*/ | ||
void clear(); | ||
|
||
const uint32_t kCommitteeSize; | ||
const Hardforks::RewardsDistributionMap kRewardsDistributionFrequency; | ||
std::shared_ptr<DB> db_; | ||
const std::function<uint64_t(EthBlockNumber)> dpos_eligible_total_vote_count_; | ||
std::vector<BlockStats> blocks_stats_; | ||
}; | ||
} // 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
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
Oops, something went wrong.