18 std::set<BlockHash> hashesToErase;
20 for (
auto it = mwHeightView.begin();
21 it != mwHeightView.lower_bound(minHeight); it++) {
22 hashesToErase.insert(it->prevblockhash);
25 auto &cHeightView =
contenders.get<by_blockheight>();
26 for (
auto it = cHeightView.begin();
27 it != cHeightView.lower_bound(minHeight); it++) {
28 hashesToErase.insert(it->prevblockhash);
31 for (
const auto &blockhash : hashesToErase) {
33 auto [mwHashBegin, mwHashEnd] = mwHashView.equal_range(blockhash);
34 mwHashView.erase(mwHashBegin, mwHashEnd);
36 auto &cHashView =
contenders.get<by_prevblockhash>();
37 auto [cHashBegin, cHashEnd] = cHashView.equal_range(blockhash);
38 cHashView.erase(cHashBegin, cHashEnd);
46 status, proof->getPayoutScript(), proof->getScore())
58 const int height = activeTip->
nHeight;
61 const ProofId &proofid = contender.proofid;
66 contender.payoutScriptPubkey, contender.score);
72 const CBlockIndex *pindex,
const std::vector<CScript> &payoutScripts) {
75 auto it = view.find(prevblockhash);
76 if (it == view.end()) {
78 .emplace(prevblockhash, pindex->
nHeight, payoutScripts)
86 auto &view =
contenders.get<by_stakecontenderid>();
87 auto it = view.find(contenderId);
88 if (it == view.end()) {
98 auto &view =
contenders.get<by_stakecontenderid>();
99 auto it = view.find(contenderId);
100 if (it == view.end()) {
111 auto &view =
contenders.get<by_stakecontenderid>();
112 auto it = view.find(contenderId);
113 if (it == view.end()) {
123 auto &view =
contenders.get<by_stakecontenderid>();
124 auto it = view.find(contenderId);
125 if (it == view.end()) {
137 auto &view =
contenders.get<by_stakecontenderid>();
138 auto it = view.find(contenderId);
139 if (it == view.end()) {
143 prevblockhashout = it->prevblockhash;
146 if (it->isAccepted()) {
151 auto &manualWinnersView =
manualWinners.get<by_prevblockhash>();
152 auto manualWinnerIt = manualWinnersView.find(it->prevblockhash);
154 for (
auto &payoutScript : manualWinnerIt->payoutScripts) {
155 if (payoutScript == it->payoutScriptPubkey) {
166 std::vector<CScript> &payouts)
const {
168 std::vector<const StakeContenderCacheEntry *> rankedWinners;
169 auto &view =
contenders.get<by_prevblockhash>();
170 auto [begin, end] = view.equal_range(prevblockhash);
171 for (
auto it = begin; it != end; it++) {
172 if (it->isInWinnerSet()) {
173 rankedWinners.push_back(&(*it));
177 std::sort(rankedWinners.begin(), rankedWinners.end(),
180 return left->computeRewardRank() < right->computeRewardRank();
186 auto &manualWinnersView =
manualWinners.get<by_prevblockhash>();
187 auto manualWinnerIt = manualWinnersView.find(prevblockhash);
189 payouts.reserve(manualWinnerIt->payoutScripts.size() +
190 rankedWinners.size());
192 payouts.insert(payouts.begin(), manualWinnerIt->payoutScripts.begin(),
193 manualWinnerIt->payoutScripts.end());
195 payouts.reserve(rankedWinners.size());
199 for (
const auto &rankedWinner : rankedWinners) {
200 payouts.push_back(rankedWinner->payoutScriptPubkey);
203 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.
void cleanup(const int requestedMinHeight)
bool reject(const StakeContenderId &contenderId)
bool setWinners(const CBlockIndex *pindex, const std::vector< CScript > &payoutScripts)
Set proof(s) that should be treated as winners (already finalized).
bool add(const CBlockIndex *pindex, const ProofRef &proof, uint8_t status=StakeContenderStatus::UNKNOWN)
Add a proof to consider in staking rewards pre-consensus.
int getVoteStatus(const StakeContenderId &contenderId, BlockHash &prevblockhashout) const
Get contender acceptance state for avalanche voting.
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 ...