 |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Go to the documentation of this file.
17 #include <unordered_map>
21 shorttxids(block.vtx.size() - 1), prefilledtxn(1), header(block) {
25 for (
size_t i = 1; i < block.
vtx.size(); i++) {
43 static_assert(
SHORTTXIDS_LENGTH == 6,
"shorttxids calculation assumes 6-byte shorttxids");
59 int32_t lastprefilledindex = -1;
60 for (
size_t i = 0; i < cmpctblock.
prefilledtxn.size(); i++) {
64 lastprefilledindex += cmpctblock.
prefilledtxn[i].index + 1;
65 if (lastprefilledindex > std::numeric_limits<uint16_t>::max())
67 if ((uint32_t)lastprefilledindex > cmpctblock.
shorttxids.size() + i) {
81 std::unordered_map<uint64_t, uint16_t> shorttxids(cmpctblock.
shorttxids.size());
82 uint16_t index_offset = 0;
83 for (
size_t i = 0; i < cmpctblock.
shorttxids.size(); i++) {
86 shorttxids[cmpctblock.
shorttxids[i]] = i + index_offset;
97 if (shorttxids.bucket_size(shorttxids.bucket(cmpctblock.
shorttxids[i])) > 12)
102 if (shorttxids.size() != cmpctblock.
shorttxids.size())
108 for (
size_t i = 0; i <
pool->vTxHashes.
size(); i++) {
109 uint64_t shortid = cmpctblock.
GetShortID(
pool->vTxHashes[i].first);
110 std::unordered_map<uint64_t, uint16_t>::iterator idit = shorttxids.find(shortid);
111 if (idit != shorttxids.end()) {
112 if (!have_txn[idit->second]) {
114 have_txn[idit->second] =
true;
134 for (
size_t i = 0; i <
extra_txn.size(); i++) {
136 std::unordered_map<uint64_t, uint16_t>::iterator idit = shorttxids.find(shortid);
137 if (idit != shorttxids.end()) {
138 if (!have_txn[idit->second]) {
140 have_txn[idit->second] =
true;
182 size_t tx_missing_offset = 0;
185 if (vtx_missing.size() <= tx_missing_offset)
187 block.
vtx[i] = vtx_missing[tx_missing_offset++];
196 if (vtx_missing.size() != tx_missing_offset)
211 if (vtx_missing.size() < 5) {
212 for (
const auto& tx : vtx_missing) {
size_t GetSerializeSize(const T &t, int nVersion=0)
static constexpr int SHORTTXIDS_LENGTH
@ BLOCK_MUTATED
the block's data didn't match the data committed to by the PoW
CSHA256 & Write(const unsigned char *data, size_t len)
ReadStatus FillBlock(CBlock &block, const std::vector< CTransactionRef > &vtx_missing)
@ READ_STATUS_CHECKBLOCK_FAILED
const_iterator begin() const
CBlockHeaderAndShortTxIDs()
std::vector< std::pair< uint256, CTransactionRef > > extra_txn
uint64_t GetUint64(int pos) const
std::vector< uint64_t > shorttxids
bool IsTxAvailable(size_t index) const
uint64_t GetRand(uint64_t nMax) noexcept
Generate a uniform random integer in the range [0..range).
The basic transaction that is broadcasted on the network and contained in blocks.
std::vector< PrefilledTransaction > prefilledtxn
ReadStatus InitData(const CBlockHeaderAndShortTxIDs &cmpctblock, const std::vector< std::pair< uint256, CTransactionRef >> &extra_txn)
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
std::vector< CTransactionRef > txn_available
uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256 &val)
Optimized SipHash-2-4 implementation for uint256.
const_iterator end() const
std::string ToString() const
void Finalize(unsigned char hash[OUTPUT_SIZE])
#define LogPrint(category,...)
bool CheckBlock(const CBlock &block, BlockValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW, bool fCheckMerkleRoot)
Functions for validating blocks and updating the block tree.
size_t BlockTxCount() const
std::vector< CTransactionRef > vtx
uint64_t GetShortID(const uint256 &txhash) const
static const size_t MIN_SERIALIZABLE_TRANSACTION_WEIGHT
static const unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule)
unsigned long size() const
A hasher class for SHA-256.
const CChainParams & Params()
Return the currently selected parameters.
void FillShortTxIDSelector() const
enum ReadStatus_t ReadStatus
Double ended buffer combining vector and stream-like interfaces.
const uint256 & GetWitnessHash() const
const uint256 & GetHash() const
static const int PROTOCOL_VERSION
network protocol versioning