20#include <unordered_set>
30 const uint256 &hash = ss.GetHash();
53 if (!
IsHex(hexProof)) {
54 errorOut =
_(
"Proof must be an hexadecimal string.");
62 }
catch (std::exception &e) {
63 errorOut =
strprintf(
_(
"Proof has invalid format: %s"), e.what());
94 total += s.getStake().getAmount();
101 return (100 * amount) /
COIN;
107 return current + ss.getStake().getAmount();
133 "payout-script-non-standard");
138 "invalid-proof-signature");
142 std::unordered_set<COutPoint, SaltedOutpointHasher> utxos;
144 const Stake &s = ss.getStake();
145 if (s.
getAmount() < stakeUtxoDustThreshold) {
147 "amount-below-dust-threshold",
149 stakeUtxoDustThreshold.
ToString()));
152 if (s.
getId() < prevId) {
154 "wrong-stake-ordering");
158 if (!utxos.insert(s.
getUTXO()).second) {
166 "invalid-stake-signature",
178 if (!
verify(stakeUtxoDustThreshold, state)) {
184 const int64_t tipMedianTimePast =
191 const int64_t stakeUtxoMinConfirmations =
196 const Stake &s = ss.getStake();
197 const COutPoint &utxo = s.
getUTXO();
203 "utxo-missing-or-spent");
206 if ((s.
getHeight() + stakeUtxoMinConfirmations - 1) > activeHeight) {
209 strprintf(
"TxId: %s, block height: %d, chaintip height: %d",
243 "non-standard-destination");
246 PKHash *pkhash = std::get_if<PKHash>(&dest);
251 "destination-type-not-supported");
255 if (*pkhash !=
PKHash(pubkey)) {
258 "destination-mismatch");
static constexpr Amount COIN
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
The block chain is a tree shaped structure starting with the genesis block at the root,...
int64_t GetMedianTimePast() const
Double ended buffer combining vector and stream-like interfaces.
An encapsulated public key.
bool VerifySchnorr(const uint256 &hash, const std::array< uint8_t, SCHNORR_SIZE > &sig) const
Verify a Schnorr signature (=64 bytes).
An output of a transaction.
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
SnapshotCompletionResult MaybeCompleteSnapshotValidation(std::function< void(bilingual_str)> shutdown_fnc=[](bilingual_str msg) { AbortNode(msg.original, msg);}) EXCLUSIVE_LOCKS_REQUIRED(Chainstate & ActiveChainstate() const
Once the background validation chainstate has reached the height which is the base of the UTXO snapsh...
int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
uint32_t GetHeight() const
A writer stream (for serialization) that computes a 256-bit hash.
bool Invalid(Result result, const std::string &reject_reason="", const std::string &debug_message="")
static bool FromHex(Proof &proof, const std::string &hexProof, bilingual_str &errorOut)
bool verify(const Amount &stakeUtxoDustThreshold, ProofValidationState &state) const
Amount getStakedAmount() const
CScript payoutScriptPubKey
std::string ToHex() const
const StakeCommitment getStakeCommitment() const
LimitedProofId limitedProofId
std::vector< SignedStake > stakes
static uint32_t amountToScore(Amount amount)
bool verify(const StakeCommitment &commitment) const
uint256 getHash(const StakeCommitment &commitment) const
uint32_t getHeight() const
const CPubKey & getPubkey() const
const COutPoint & getUTXO() const
const StakeId & getId() const
const uint8_t * data() const
static const uint256 ZERO
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
@ DESTINATION_NOT_SUPPORTED
@ NON_STANDARD_DESTINATION
@ INVALID_PROOF_SIGNATURE
@ INVALID_STAKE_SIGNATURE
static bool IsStandardPayoutScript(const CScript &scriptPubKey)
bool IsStandard(const CScript &scriptPubKey, const std::optional< unsigned > &max_datacarrier_bytes, TxoutType &whichType)
static constexpr int AVALANCHE_DEFAULT_STAKE_UTXO_CONFIRMATIONS
Minimum number of confirmations before a stake utxo is mature enough to be included into a proof.
static constexpr int AVALANCHE_MAX_PROOF_STAKES
How many UTXOs can be used for a single proof.
void WriteCompactSize(CSizeComputer &os, uint64_t nSize)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
static const unsigned int MAX_OP_RETURN_RELAY
Default setting for nMaxDatacarrierBytes.
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
static constexpr Amount zero() noexcept
std::string ToString() const
ProofId computeProofId(const CPubKey &proofMaster) const
StakeCommitment(int64_t expirationTime, const CPubKey &master)
bilingual_str _(const char *psz)
Translation function.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
template std::vector< std::byte > ParseHex(std::string_view)
bool IsHex(std::string_view str)
Returns true if each character in str is a hex character, and has an even number of hex digits.
static const int PROTOCOL_VERSION
network protocol versioning