19#include <unordered_map>
23 : nonce(nonce), shorttxids(block.vtx.size() - 1), prefilledtxn(1),
29 for (
size_t i = 1; i < block.
vtx.size(); i++) {
30 const CTransaction &tx = *block.
vtx[i];
39 hasher.
Write((uint8_t *)&(*stream.begin()), stream.end() - stream.begin());
48 "shorttxids calculation assumes 6-byte shorttxids");
54 const std::vector<CTransactionRef> &extra_txns) {
70 for (
const auto &prefilledtxn : cmpctblock.
prefilledtxn) {
71 if (prefilledtxn.tx->IsNull()) {
104 auto it =
pool->mapTx.begin();
105 while (it !=
pool->mapTx.end()) {
106 uint64_t shortid = cmpctblock.
GetShortID((*it)->GetTx().GetHash());
118 for (
auto &extra_txn : extra_txns) {
119 if (extra_txn ==
nullptr) {
122 uint64_t shortid = cmpctblock.
GetShortID(extra_txn->GetHash());
134 "Initialized PartiallyDownloadedBlock for block %s using a "
135 "cmpctblock of size %lu\n",
153 CBlock &block,
const std::vector<CTransactionRef> &vtx_missing) {
160 block.
vtx.resize(txnCount);
162 size_t tx_missing_offset = 0;
163 for (
size_t i = 0; i < txnCount; i++) {
165 if (!txn_available) {
166 if (vtx_missing.size() <= tx_missing_offset) {
169 block.
vtx[i] = vtx_missing[tx_missing_offset++];
171 block.
vtx[i] = txn_available;
179 if (vtx_missing.size() != tx_missing_offset) {
198 "Successfully reconstructed block %s with %lu txn prefilled, %lu "
199 "txn from mempool (incl at least %lu from extra pool) and %lu txn "
203 if (vtx_missing.size() < 5) {
204 for (
const auto &tx : vtx_missing) {
206 "Reconstructed block %s required tx %s\n", hash.
ToString(),
207 tx->GetId().ToString());
@ READ_STATUS_CHECKBLOCK_FAILED
enum ReadStatus_t ReadStatus
uint64_t GetShortID(const TxHash &txhash) const
void FillShortTxIDSelector() const
CBlockHeaderAndShortTxIDs()
Dummy for deserialization.
std::vector< PrefilledTransaction > prefilledtxn
static constexpr int SHORTTXIDS_LENGTH
std::vector< uint64_t > shorttxids
std::vector< CTransactionRef > vtx
const Consensus::Params & GetConsensus() 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
Double ended buffer combining vector and stream-like interfaces.
ReadStatus InitData(const CBlockHeaderAndShortTxIDs &cmpctblock, const std::vector< 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.
size_t GetSerializeSize(const T &t)
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