16 #include <unordered_map> 20 shorttxids(block.vtx.
size() - 1), prefilledtxn(1), header(block) {
24 for (
size_t i = 1; i < block.
vtx.size(); i++) {
42 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;
67 if ((uint32_t)lastprefilledindex > cmpctblock.
shorttxids.size() + i) {
73 txn_available[lastprefilledindex] = cmpctblock.
prefilledtxn[i].tx;
82 uint16_t index_offset = 0;
83 for (
size_t i = 0; i < cmpctblock.
shorttxids.size(); i++) {
84 while (txn_available[i + index_offset])
105 std::vector<bool> have_txn(txn_available.size());
108 const std::vector<std::pair<uint256, CTxMemPool::txiter> >& vTxHashes = pool->vTxHashes;
109 for (
size_t i = 0; i < vTxHashes.size(); i++) {
110 uint64_t shortid = cmpctblock.
GetShortID(vTxHashes[i].first);
111 std::unordered_map<uint64_t, uint16_t>::iterator idit =
shorttxids.find(shortid);
113 if (!have_txn[idit->second]) {
114 txn_available[idit->second] = vTxHashes[i].second->GetSharedTx();
115 have_txn[idit->second] =
true;
121 if (txn_available[idit->second]) {
122 txn_available[idit->second].reset();
135 for (
size_t i = 0; i < extra_txn.size(); i++) {
136 uint64_t shortid = cmpctblock.
GetShortID(extra_txn[i].first);
137 std::unordered_map<uint64_t, uint16_t>::iterator idit =
shorttxids.find(shortid);
139 if (!have_txn[idit->second]) {
140 txn_available[idit->second] = extra_txn[i].second;
141 have_txn[idit->second] =
true;
151 if (txn_available[idit->second] &&
152 txn_available[idit->second]->GetWitnessHash() != extra_txn[i].second->GetWitnessHash()) {
153 txn_available[idit->second].reset();
173 assert(index < txn_available.size());
174 return txn_available[index] !=
nullptr;
181 block.
vtx.resize(txn_available.size());
183 size_t tx_missing_offset = 0;
184 for (
size_t i = 0; i < txn_available.size(); i++) {
185 if (!txn_available[i]) {
186 if (vtx_missing.size() <= tx_missing_offset)
188 block.
vtx[i] = vtx_missing[tx_missing_offset++];
190 block.
vtx[i] = std::move(txn_available[i]);
195 txn_available.clear();
197 if (vtx_missing.size() != tx_missing_offset)
211 LogPrint(
BCLog::CMPCTBLOCK,
"Successfully reconstructed block %s with %lu txn prefilled, %lu txn from mempool (incl at least %lu from extra pool) and %lu txn requested\n", hash.ToString(), prefilled_count, mempool_count, extra_count, vtx_missing.size());
212 if (vtx_missing.size() < 5) {
213 for (
const auto& tx : vtx_missing) {
enum ReadStatus_t ReadStatus
CSHA256 & Write(const unsigned char *data, size_t len)
CBlockHeaderAndShortTxIDs()
size_t BlockTxCount() const
ReadStatus FillBlock(CBlock &block, const std::vector< CTransactionRef > &vtx_missing)
const_iterator begin() const
uint256 GetWitnessHash() const
size_t GetSerializeSize(const T &t, int nType, int nVersion=0)
bool CorruptionPossible() const
static const int SHORTTXIDS_LENGTH
std::hash for asio::adress
assert(len-trim+(2 *lenIndices)<=WIDTH)
Double ended buffer combining vector and stream-like interfaces.
uint64_t GetUint64(int pos) const
unsigned int dgpMaxBlockSize
std::string ToString() const
void FillShortTxIDSelector() const
bool CheckBlock(const CBlock &block, CValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW, bool fCheckMerkleRoot)
Functions for validating blocks and updating the block tree.
bool IsTxAvailable(size_t index) const
void Finalize(unsigned char hash[OUTPUT_SIZE])
#define LogPrint(category,...)
Capture information about block/transaction validation.
std::vector< uint64_t > shorttxids
std::vector< CTransactionRef > vtx
std::vector< PrefilledTransaction > prefilledtxn
uint8_t const size_t const size
const CChainParams & Params()
Return the currently selected parameters.
uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256 &val)
Optimized SipHash-2-4 implementation for uint256.
ReadStatus InitData(const CBlockHeaderAndShortTxIDs &cmpctblock, const std::vector< std::pair< uint256, CTransactionRef >> &extra_txn)
const uint256 & GetHash() const
The basic transaction that is broadcasted on the network and contained in blocks. ...
A hasher class for SHA-256.
uint64_t GetRand(uint64_t nMax)
const_iterator end() const
uint64_t GetShortID(const uint256 &txhash) const