18#include <unordered_map>
22 shorttxids(block.vtx.size() - 1),
29 for (
size_t i = 1; i < block.
vtx.size(); i++) {
40 hasher.
Write((
unsigned char*)&(*stream.begin()), stream.end() - stream.begin());
48 static_assert(
SHORTTXIDS_LENGTH == 6,
"shorttxids calculation assumes 6-byte shorttxids");
72 int32_t lastprefilledindex = -1;
73 for (
size_t i = 0; i < cmpctblock.
prefilledtxn.size(); i++) {
77 lastprefilledindex += cmpctblock.
prefilledtxn[i].index + 1;
78 if (lastprefilledindex > std::numeric_limits<uint16_t>::max())
80 if ((uint32_t)lastprefilledindex > cmpctblock.
shorttxids.size() + i) {
94 std::unordered_map<uint64_t, uint16_t> shorttxids(cmpctblock.
shorttxids.size());
95 uint16_t index_offset = 0;
96 for (
size_t i = 0; i < cmpctblock.
shorttxids.size(); i++) {
99 shorttxids[cmpctblock.
shorttxids[i]] = i + index_offset;
110 if (shorttxids.bucket_size(shorttxids.bucket(cmpctblock.
shorttxids[i])) > 12)
115 if (shorttxids.size() != cmpctblock.
shorttxids.size())
121 for (
const auto& [wtxid, txit] :
pool->txns_randomized) {
122 uint64_t shortid = cmpctblock.
GetShortID(wtxid);
123 std::unordered_map<uint64_t, uint16_t>::iterator idit = shorttxids.find(shortid);
124 if (idit != shorttxids.end()) {
125 if (!have_txn[idit->second]) {
127 have_txn[idit->second] =
true;
147 for (
size_t i = 0; i < extra_txn.size(); i++) {
148 uint64_t shortid = cmpctblock.
GetShortID(extra_txn[i].first);
149 std::unordered_map<uint64_t, uint16_t>::iterator idit = shorttxids.find(shortid);
150 if (idit != shorttxids.end()) {
151 if (!have_txn[idit->second]) {
153 have_txn[idit->second] =
true;
164 txn_available[idit->second]->GetWitnessHash() != extra_txn[i].second->GetWitnessHash()) {
199 unsigned int tx_missing_size = 0;
200 size_t tx_missing_offset = 0;
203 if (vtx_missing.size() <= tx_missing_offset)
205 block.
vtx[i] = vtx_missing[tx_missing_offset++];
206 tx_missing_size += block.
vtx[i]->GetTotalSize();
215 if (vtx_missing.size() != tx_missing_offset)
220 if (check_mutated(block,
226 if (vtx_missing.size() < 5) {
227 for (
const auto& tx : vtx_missing) {
enum ReadStatus_t ReadStatus
#define Assert(val)
Identity function.
size_t BlockTxCount() const
CBlockHeaderAndShortTxIDs()=default
Dummy for deserialization.
void FillShortTxIDSelector() const
uint64_t GetShortID(const Wtxid &wtxid) const
std::vector< PrefilledTransaction > prefilledtxn
static constexpr int SHORTTXIDS_LENGTH
std::vector< uint64_t > shorttxids
std::optional< PresaltedSipHasher > m_hasher
std::vector< CTransactionRef > vtx
A hasher class for SHA-256.
void Finalize(unsigned char hash[OUTPUT_SIZE])
CSHA256 & Write(const unsigned char *data, size_t len)
The basic transaction that is broadcasted on the network and contained in blocks.
const Wtxid & GetWitnessHash() const LIFETIMEBOUND
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Double ended buffer combining vector and stream-like interfaces.
IsBlockMutatedFn m_check_block_mutated_mock
std::vector< CTransactionRef > txn_available
ReadStatus FillBlock(CBlock &block, const std::vector< CTransactionRef > &vtx_missing, bool segwit_active)
std::function< bool(const CBlock &, bool)> IsBlockMutatedFn
bool IsTxAvailable(size_t index) const
ReadStatus InitData(const CBlockHeaderAndShortTxIDs &cmpctblock, const std::vector< std::pair< Wtxid, CTransactionRef > > &extra_txn)
constexpr uint64_t GetUint64(int pos) const
std::string ToString() const
constexpr unsigned char * begin()
transaction_identifier represents the two canonical transaction identifier types (txid,...
const uint256 & ToUint256() const LIFETIMEBOUND
static const unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule)
static const size_t MIN_SERIALIZABLE_TRANSACTION_WEIGHT
#define LogDebug(category,...)
uint64_t GetSerializeSize(const T &t)
bool IsBlockMutated(const CBlock &block, bool check_witness_root)
Check if a block has been mutated (with respect to its merkle root and witness commitments).