12 std::set<BlockHash> hashesToErase;
14 for (
auto it = mwHeightView.begin();
15 it != mwHeightView.lower_bound(minHeight); it++) {
16 hashesToErase.insert(it->prevblockhash);
19 auto &cHeightView =
contenders.get<by_blockheight>();
20 for (
auto it = cHeightView.begin();
21 it != cHeightView.lower_bound(minHeight); it++) {
22 hashesToErase.insert(it->prevblockhash);
25 for (
const auto &blockhash : hashesToErase) {
27 auto [mwHashBegin, mwHashEnd] = mwHashView.equal_range(blockhash);
28 mwHashView.erase(mwHashBegin, mwHashEnd);
30 auto &cHashView =
contenders.get<by_prevblockhash>();
31 auto [cHashBegin, cHashEnd] = cHashView.equal_range(blockhash);
32 cHashView.erase(cHashBegin, cHashEnd);
40 status, proof->getPayoutScript(), proof->getScore())
52 const int height = activeTip->
nHeight;
54 const ProofId &proofid = contender.proofid;
59 contender.payoutScriptPubkey, contender.score);
65 const CBlockIndex *pindex,
const std::vector<CScript> &payoutScripts) {
68 auto it = view.find(prevblockhash);
69 if (it == view.end()) {
71 .emplace(prevblockhash, pindex->
nHeight, payoutScripts)
79 auto &view =
contenders.get<by_stakecontenderid>();
80 auto it = view.find(contenderId);
81 if (it == view.end()) {
91 auto &view =
contenders.get<by_stakecontenderid>();
92 auto it = view.find(contenderId);
93 if (it == view.end()) {
104 auto &view =
contenders.get<by_stakecontenderid>();
105 auto it = view.find(contenderId);
106 if (it == view.end()) {
116 auto &view =
contenders.get<by_stakecontenderid>();
117 auto it = view.find(contenderId);
118 if (it == view.end()) {
130 auto &view =
contenders.get<by_stakecontenderid>();
131 auto it = view.find(contenderId);
132 if (it == view.end()) {
137 if (it->isAccepted()) {
142 auto &manualWinnersView =
manualWinners.get<by_prevblockhash>();
143 auto manualWinnerIt = manualWinnersView.find(it->prevblockhash);
145 for (
auto &payoutScript : manualWinnerIt->payoutScripts) {
146 if (payoutScript == it->payoutScriptPubkey) {
157 std::vector<CScript> &payouts)
const {
159 std::vector<const StakeContenderCacheEntry *> rankedWinners;
160 auto &view =
contenders.get<by_prevblockhash>();
161 auto [begin, end] = view.equal_range(prevblockhash);
162 for (
auto it = begin; it != end; it++) {
163 if (it->isInWinnerSet()) {
164 rankedWinners.push_back(&(*it));
168 std::sort(rankedWinners.begin(), rankedWinners.end(),
171 return left->computeRewardRank() < right->computeRewardRank();
177 auto &manualWinnersView =
manualWinners.get<by_prevblockhash>();
178 auto manualWinnerIt = manualWinnersView.find(prevblockhash);
180 payouts.reserve(manualWinnerIt->payoutScripts.size() +
181 rankedWinners.size());
183 payouts.insert(payouts.begin(), manualWinnerIt->payoutScripts.begin(),
184 manualWinnerIt->payoutScripts.end());
186 payouts.reserve(rankedWinners.size());
190 for (
const auto &rankedWinner : rankedWinners) {
191 payouts.push_back(rankedWinner->payoutScriptPubkey);
194 return payouts.size() > 0;
The block chain is a tree shaped structure starting with the genesis block at the root,...
BlockHash GetBlockHash() const
int nHeight
height of the entry in the chain. The genesis block has height 0
bool isDangling(const ProofId &proofid) const
bool isRemoteProof(const ProofId &proofid) const
bool isBoundToPeer(const ProofId &proofid) const
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 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.
StakeContenderIds are unique for each block to ensure that the peer polling for their acceptance has ...