Bitcoin ABC 0.30.5
P2P Digital Currency
stakecontender.h
Go to the documentation of this file.
1// Copyright (c) 2024 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
5#ifndef BITCOIN_AVALANCHE_STAKECONTENDER_H
6#define BITCOIN_AVALANCHE_STAKECONTENDER_H
7
8#include <arith_uint256.h>
9#include <hash.h>
10#include <uint256.h>
11
12#include <cmath>
13
14struct BlockHash;
15
16namespace avalanche {
17
18struct ProofId;
19
25struct StakeContenderId : public uint256 {
26 explicit StakeContenderId() : uint256() {}
27 explicit StakeContenderId(const uint256 &b) : uint256(b) {}
28 explicit StakeContenderId(const BlockHash &prevblockhash,
29 const ProofId &proofid)
30 : uint256(Hash(prevblockhash, proofid)) {}
31
39 double ComputeProofRewardRank(uint32_t proofScore) {
40 return (256.0 - std::log2(UintToArith256(*this).getdouble())) /
41 proofScore;
42 }
43};
44
45} // namespace avalanche
46
47#endif // BITCOIN_AVALANCHE_STAKECONTENDER_H
arith_uint256 UintToArith256(const uint256 &a)
double getdouble() const
256-bit opaque blob.
Definition: uint256.h:129
uint256 Hash(const T &in1)
Compute the 256-bit hash of an object.
Definition: hash.h:74
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
StakeContenderIds are unique for each block to ensure that the peer polling for their acceptance has ...
double ComputeProofRewardRank(uint32_t proofScore)
To make sure the selection is properly weighted according to the proof score, we normalize the conten...
StakeContenderId(const uint256 &b)
StakeContenderId(const BlockHash &prevblockhash, const ProofId &proofid)