Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
stakingrewards.cpp
Go to the documentation of this file.
1// Copyright (c) 2023 The Bitcoin developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
6
9#include <blockindex.h>
10#include <common/args.h>
12#include <consensus/amount.h>
13#include <logging.h>
14#include <primitives/block.h>
15
16#include <vector>
17
21static constexpr int STAKING_REWARD_RATIO = 10;
22
24 if (!m_blockIndex.pprev ||
26 return true;
27 }
28
29 assert(m_block.vtx.size());
30
31 const BlockHash blockhash = m_blockIndex.GetBlockHash();
32
33 std::vector<CScript> winners;
36 winners)) {
38 "Staking rewards for block %s: not ready yet\n",
39 blockhash.ToString());
40 return true;
41 }
42
44 for (auto &o : m_block.vtx[0]->vout) {
45 if (o.nValue < required) {
46 // This output doesn't qualify because its amount is too low.
47 continue;
48 }
49
50 auto it = std::find(winners.begin(), winners.end(), o.scriptPubKey);
51 if (it != winners.end()) {
52 if (it != winners.begin()) {
54 "Staking rewards for block %s: selected winner is "
55 "flaky, accepting an alternative one\n",
56 blockhash.ToString());
57 }
58
59 return true;
60 }
61 }
62
64 "Staking rewards for block %s: payout script mismatch!\n",
65 blockhash.ToString());
66
68 "policy-bad-staking-reward",
69 strprintf("Block %s violates staking reward policy",
71}
72
76
78 const CBlockIndex *pprev) {
79 return IsCowperthwaiteEnabled(params, pprev) &&
80 gArgs.GetBoolArg("-avalanchestakingrewards",
82}
bool IsCowperthwaiteEnabled(const Consensus::Params &params, int32_t nHeight)
Check if Nov 15th, 2023 protocol upgrade has activated.
ArgsManager gArgs
Definition args.cpp:38
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition args.cpp:556
std::vector< CTransactionRef > vtx
Definition block.h:63
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition blockindex.h:25
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition blockindex.h:32
BlockHash GetBlockHash() const
Definition blockindex.h:146
const avalanche::Processor & m_avalanche
const CBlock & m_block
bool operator()(BlockPolicyValidationState &state) override
const Consensus::Params & m_consensusParams
const Amount & m_blockReward
const CBlockIndex & m_blockIndex
bool Invalid(Result result, const std::string &reject_reason="", const std::string &debug_message="")
Definition validation.h:101
bool getStakingRewardWinners(const BlockHash &prevBlockHash, std::vector< std::pair< ProofId, CScript > > &winners) const EXCLUSIVE_LOCKS_REQUIRED(!cs_stakingRewards)
std::string ToString() const
Definition uint256.h:80
#define LogPrint(category,...)
Definition logging.h:238
@ AVALANCHE
Definition logging.h:62
@ POLICY_VIOLATION
A block policy rule was violated. This block should be parked.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
bool IsStakingRewardsActivated(const Consensus::Params &params, const CBlockIndex *pprev)
static constexpr int STAKING_REWARD_RATIO
Percentage of the block reward to be sent to staking rewards.
Amount GetStakingRewardsAmount(const Amount &coinbaseValue)
bool IsStakingRewardsActivated(const Consensus::Params &params, const CBlockIndex *pprev)
Amount GetStakingRewardsAmount(const Amount &coinbaseValue)
A BlockHash is a unqiue identifier for a block.
Definition blockhash.h:13
Parameters that influence chain consensus.
Definition params.h:34
bool enableStakingRewards
Enable or disable the staking rewards by default.
Definition params.h:73
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
assert(!tx.IsCoinBase())