Bitcoin ABC 0.30.7
P2P Digital Currency
Public Member Functions | Private Types | Private Attributes | List of all members
avalanche::StakeContenderCache Class Reference

Cache to track stake contenders for recent blocks. More...

#include <stakecontendercache.h>

Public Member Functions

 StakeContenderCache ()
 
void cleanup (const int requestedMinHeight)
 
bool isEmpty () const
 For tests. More...
 
bool add (const CBlockIndex *pindex, const ProofRef &proof, uint8_t status=StakeContenderStatus::UNKNOWN)
 Add a proof to consider in staking rewards pre-consensus. More...
 
void promoteToBlock (const CBlockIndex *activeTip, PeerManager &pm)
 Promote cache entries to a the active chain tip. More...
 
bool setWinners (const CBlockIndex *pindex, const std::vector< CScript > &payoutScripts)
 Set proof(s) that should be treated as winners (already finalized). More...
 
bool accept (const StakeContenderId &contenderId)
 Helpers to set avalanche state of a contender. More...
 
bool finalize (const StakeContenderId &contenderId)
 
bool reject (const StakeContenderId &contenderId)
 
bool invalidate (const StakeContenderId &contenderId)
 
int getVoteStatus (const StakeContenderId &contenderId, BlockHash &prevblockhashout) const
 Get contender acceptance state for avalanche voting. More...
 
bool getWinners (const BlockHash &prevblockhash, std::vector< CScript > &payouts) const
 Get payout scripts of the winning proofs. More...
 

Private Types

using ContenderSet = 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 > > > >
 
using ManualWinnersSet = 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 > > > >
 

Private Attributes

int lastPromotedHeight {0}
 
ContenderSet contenders
 
ManualWinnersSet manualWinners
 

Detailed Description

Cache to track stake contenders for recent blocks.

Definition at line 90 of file stakecontendercache.h.

Member Typedef Documentation

◆ ContenderSet

using avalanche::StakeContenderCache::ContenderSet = 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> >> >
private

Definition at line 93 of file stakecontendercache.h.

◆ ManualWinnersSet

using avalanche::StakeContenderCache::ManualWinnersSet = 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> >> >
private

Definition at line 113 of file stakecontendercache.h.

Constructor & Destructor Documentation

◆ StakeContenderCache()

avalanche::StakeContenderCache::StakeContenderCache ( )
inline

Definition at line 129 of file stakecontendercache.h.

Member Function Documentation

◆ accept()

bool avalanche::StakeContenderCache::accept ( const StakeContenderId contenderId)

Helpers to set avalanche state of a contender.

Definition at line 85 of file stakecontendercache.cpp.

Here is the caller graph for this function:

◆ add()

bool avalanche::StakeContenderCache::add ( const CBlockIndex pindex,
const ProofRef proof,
uint8_t  status = StakeContenderStatus::UNKNOWN 
)

Add a proof to consider in staking rewards pre-consensus.

Definition at line 42 of file stakecontendercache.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanup()

void avalanche::StakeContenderCache::cleanup ( const int  requestedMinHeight)

Definition at line 13 of file stakecontendercache.cpp.

Here is the caller graph for this function:

◆ finalize()

bool avalanche::StakeContenderCache::finalize ( const StakeContenderId contenderId)

Definition at line 97 of file stakecontendercache.cpp.

Here is the caller graph for this function:

◆ getVoteStatus()

int avalanche::StakeContenderCache::getVoteStatus ( const StakeContenderId contenderId,
BlockHash prevblockhashout 
) const

Get contender acceptance state for avalanche voting.

Returns 0 for accepted, 1 for rejected, -1 for not in cache, and -2 for pending. prevblockhashout gets set if the contender is in the cache.

Definition at line 135 of file stakecontendercache.cpp.

Here is the caller graph for this function:

◆ getWinners()

bool avalanche::StakeContenderCache::getWinners ( const BlockHash prevblockhash,
std::vector< CScript > &  payouts 
) const

Get payout scripts of the winning proofs.

Definition at line 165 of file stakecontendercache.cpp.

Here is the caller graph for this function:

◆ invalidate()

bool avalanche::StakeContenderCache::invalidate ( const StakeContenderId contenderId)

Definition at line 122 of file stakecontendercache.cpp.

Here is the caller graph for this function:

◆ isEmpty()

bool avalanche::StakeContenderCache::isEmpty ( ) const
inline

For tests.

Definition at line 136 of file stakecontendercache.h.

Here is the caller graph for this function:

◆ promoteToBlock()

void avalanche::StakeContenderCache::promoteToBlock ( const CBlockIndex activeTip,
PeerManager pm 
)

Promote cache entries to a the active chain tip.

Definition at line 50 of file stakecontendercache.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reject()

bool avalanche::StakeContenderCache::reject ( const StakeContenderId contenderId)

Definition at line 110 of file stakecontendercache.cpp.

Here is the caller graph for this function:

◆ setWinners()

bool avalanche::StakeContenderCache::setWinners ( const CBlockIndex pindex,
const std::vector< CScript > &  payoutScripts 
)

Set proof(s) that should be treated as winners (already finalized).

This should only be used for manually added winners via RPC.

Definition at line 71 of file stakecontendercache.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ contenders

ContenderSet avalanche::StakeContenderCache::contenders
private

Definition at line 111 of file stakecontendercache.h.

◆ lastPromotedHeight

int avalanche::StakeContenderCache::lastPromotedHeight {0}
private

Definition at line 91 of file stakecontendercache.h.

◆ manualWinners

ManualWinnersSet avalanche::StakeContenderCache::manualWinners
private

Definition at line 126 of file stakecontendercache.h.


The documentation for this class was generated from the following files: