19#include <unordered_map>
22 : nonce(
GetRand<uint64_t>()), shorttxids(block.vtx.size() - 1),
23 prefilledtxn(1), header(block) {
28 for (
size_t i = 1; i < block.
vtx.size(); i++) {
29 const CTransaction &tx = *block.
vtx[i];
47 "shorttxids calculation assumes 6-byte shorttxids");
53 const std::vector<std::pair<TxHash, CTransactionRef>> &extra_txns) {
69 for (
const auto &prefilledtxn : cmpctblock.
prefilledtxn) {
70 if (prefilledtxn.tx->IsNull()) {
103 auto it =
pool->mapTx.begin();
104 while (it !=
pool->mapTx.end()) {
105 uint64_t shortid = cmpctblock.
GetShortID((*it)->GetTx().GetHash());
117 for (
auto &extra_txn : extra_txns) {
118 uint64_t shortid = cmpctblock.
GetShortID(extra_txn.first);
130 "Initialized PartiallyDownloadedBlock for block %s using a "
131 "cmpctblock of size %lu\n",
149 CBlock &block,
const std::vector<CTransactionRef> &vtx_missing) {
156 block.
vtx.resize(txnCount);
158 size_t tx_missing_offset = 0;
159 for (
size_t i = 0; i < txnCount; i++) {
161 if (!txn_available) {
162 if (vtx_missing.size() <= tx_missing_offset) {
165 block.
vtx[i] = vtx_missing[tx_missing_offset++];
167 block.
vtx[i] = txn_available;
175 if (vtx_missing.size() != tx_missing_offset) {
194 "Successfully reconstructed block %s with %lu txn prefilled, %lu "
195 "txn from mempool (incl at least %lu from extra pool) and %lu txn "
199 if (vtx_missing.size() < 5) {
200 for (
const auto &tx : vtx_missing) {
202 "Reconstructed block %s required tx %s\n", hash.
ToString(),
203 tx->GetId().ToString());
@ READ_STATUS_CHECKBLOCK_FAILED
enum ReadStatus_t ReadStatus
uint64_t GetShortID(const TxHash &txhash) const
void FillShortTxIDSelector() const
CBlockHeaderAndShortTxIDs()
std::vector< PrefilledTransaction > prefilledtxn
static constexpr int SHORTTXIDS_LENGTH
std::vector< uint64_t > shorttxids
std::vector< CTransactionRef > vtx
const Consensus::Params & GetConsensus() const
Double ended buffer combining vector and stream-like interfaces.
const_iterator begin() const
const_iterator end() const
A hasher class for SHA-256.
CSHA256 & Write(const uint8_t *data, size_t len)
void Finalize(uint8_t hash[OUTPUT_SIZE])
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
virtual uint64_t GetMaxBlockSize() const =0
virtual const CChainParams & GetChainParams() const =0
ReadStatus InitData(const CBlockHeaderAndShortTxIDs &cmpctblock, const std::vector< std::pair< TxHash, CTransactionRef > > &extra_txn)
bool IsTxAvailable(size_t index) const
ReadStatus FillBlock(CBlock &block, const std::vector< CTransactionRef > &vtx_missing)
std::shared_ptr< TransactionShortIdProcessor > shortidProcessor
std::string ToString() const
uint64_t GetUint64(int pos) const
@ BLOCK_MUTATED
the block's data didn't match the data committed to by the PoW
#define LogPrint(category,...)
bool CheckBlock(const CCheckpointData &data, int nHeight, const BlockHash &hash)
Returns true if block passes checkpoint checks.
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...
size_t GetSerializeSize(const T &t, int nVersion=0)
uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256 &val)
Optimized SipHash-2-4 implementation for uint256.
A TxHash is the double sha256 hash of the full transaction data.
#define MIN_TRANSACTION_SIZE
static const int PROTOCOL_VERSION
network protocol versioning