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++) {
47 "shorttxids calculation assumes 6-byte shorttxids");
53 const std::vector<std::pair<TxHash, CTransactionRef>> &extra_txns) {
67 for (
const auto &prefilledtxn : cmpctblock.
prefilledtxn) {
68 if (prefilledtxn.tx->IsNull()) {
101 auto it =
pool->mapTx.begin();
102 while (it !=
pool->mapTx.end()) {
103 uint64_t shortid = cmpctblock.
GetShortID((*it)->GetTx().GetHash());
115 for (
auto &extra_txn : extra_txns) {
116 uint64_t shortid = cmpctblock.
GetShortID(extra_txn.first);
128 "Initialized PartiallyDownloadedBlock for block %s using a "
129 "cmpctblock of size %lu\n",
143 CBlock &block,
const std::vector<CTransactionRef> &vtx_missing) {
148 block.
vtx.resize(txnCount);
150 size_t tx_missing_offset = 0;
151 for (
size_t i = 0; i < txnCount; i++) {
153 if (!txn_available) {
154 if (vtx_missing.size() <= tx_missing_offset) {
157 block.
vtx[i] = vtx_missing[tx_missing_offset++];
159 block.
vtx[i] = std::move(txn_available);
167 if (vtx_missing.size() != tx_missing_offset) {
186 "Successfully reconstructed block %s with %lu txn prefilled, %lu "
187 "txn from mempool (incl at least %lu from extra pool) and %lu txn "
191 if (vtx_missing.size() < 5) {
192 for (
const auto &tx : vtx_missing) {
194 "Reconstructed block %s required tx %s\n", hash.
ToString(),
195 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])
The basic transaction that is broadcasted on the network and contained in blocks.
const TxHash GetHash() const
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