5#ifndef BITCOIN_AVALANCHE_STAKECONTENDERCACHE_H
6#define BITCOIN_AVALANCHE_STAKECONTENDERCACHE_H
14#include <boost/multi_index/hashed_index.hpp>
15#include <boost/multi_index/member.hpp>
16#include <boost/multi_index/ordered_index.hpp>
17#include <boost/multi_index_container.hpp>
44 const ProofId &_proofid, uint8_t _status,
45 const CScript &_payoutScriptPubkey,
69 const std::vector<CScript> &_payoutScripts)
81struct by_stakecontenderid;
82struct by_prevblockhash;
85namespace bmi = boost::multi_index;
95 bmi::hashed_unique<bmi::tag<by_stakecontenderid>,
98 bmi::hashed_non_unique<
99 bmi::tag<by_prevblockhash>,
104 bmi::ordered_non_unique<
105 bmi::tag<by_blockheight>,
115 bmi::hashed_unique<bmi::tag<by_prevblockhash>,
121 bmi::tag<by_blockheight>,
122 bmi::member<ManualWinners, int, &ManualWinners::blockheight>>>>;
129 void cleanup(
const int minHeight);
154 const std::vector<CScript> &payoutScripts);
174 std::vector<CScript> &payouts)
const;
The block chain is a tree shaped structure starting with the genesis block at the root,...
Serialized script, used inside transaction inputs and outputs.
Cache to track stake contenders for recent blocks.
bool invalidate(const StakeContenderId &contenderId)
ManualWinnersSet manualWinners
bool accept(const StakeContenderId &contenderId)
Helpers to set avalanche state of a contender.
bool reject(const StakeContenderId &contenderId)
int getVoteStatus(const StakeContenderId &contenderId) const
Get contender acceptance state for avalanche voting.
bool setWinners(const CBlockIndex *pindex, const std::vector< CScript > &payoutScripts)
Set proof(s) that should be treated as winners (already finalized).
void cleanup(const int minHeight)
bool add(const CBlockIndex *pindex, const ProofRef &proof, uint8_t status=StakeContenderStatus::UNKNOWN)
Add a proof to consider in staking rewards pre-consensus.
bool isEmpty() const
For tests.
boost::multi_index_container< StakeContenderCacheEntry, bmi::indexed_by< bmi::hashed_unique< bmi::tag< by_stakecontenderid >, stakecontenderid_index, SaltedUint256Hasher >, bmi::hashed_non_unique< bmi::tag< by_prevblockhash >, bmi::member< StakeContenderCacheEntry, BlockHash, &StakeContenderCacheEntry::prevblockhash >, SaltedUint256Hasher >, bmi::ordered_non_unique< bmi::tag< by_blockheight >, bmi::member< StakeContenderCacheEntry, int, &StakeContenderCacheEntry::blockheight > > > > ContenderSet
boost::multi_index_container< ManualWinners, bmi::indexed_by< bmi::hashed_unique< bmi::tag< by_prevblockhash >, bmi::member< ManualWinners, BlockHash, &ManualWinners::prevblockhash >, SaltedUint256Hasher >, bmi::ordered_unique< bmi::tag< by_blockheight >, bmi::member< ManualWinners, int, &ManualWinners::blockheight > > > > ManualWinnersSet
bool finalize(const StakeContenderId &contenderId)
bool getWinners(const BlockHash &prevblockhash, std::vector< CScript > &payouts) const
Get payout scripts of the winning proofs.
void promoteToBlock(const CBlockIndex *activeTip, PeerManager &pm)
Promote cache entries to a the active chain tip.
A BlockHash is a unqiue identifier for a block.
ManualWinners(const BlockHash &_prevblockhash, int _blockheight, const std::vector< CScript > &_payoutScripts)
std::vector< CScript > payoutScripts
CScript payoutScriptPubkey
bool isInWinnerSet() const
double computeRewardRank() const
StakeContenderCacheEntry(const BlockHash &_prevblockhash, int _blockheight, const ProofId &_proofid, uint8_t _status, const CScript &_payoutScriptPubkey, uint32_t _score)
StakeContenderId getStakeContenderId() const
StakeContenderIds are unique for each block to ensure that the peer polling for their acceptance has ...
double ComputeProofRewardRank(uint32_t proofScore)
To make sure the selection is properly weighted according to the proof score, we normalize the conten...
result_type operator()(const StakeContenderCacheEntry &entry) const