18 #include <unordered_map> 22 shorttxids(block.vtx.size() - 1), prefilledtxn(1), header(block) {
26 for (
size_t i = 1; i < block.
vtx.size(); i++) {
36 hasher.
Write((
unsigned char*)&(*stream.begin()), stream.end() - stream.begin());
44 static_assert(
SHORTTXIDS_LENGTH == 6,
"shorttxids calculation assumes 6-byte shorttxids");
61 int32_t lastprefilledindex = -1;
62 for (
size_t i = 0; i < cmpctblock.
prefilledtxn.size(); i++) {
66 lastprefilledindex += cmpctblock.
prefilledtxn[i].index + 1;
67 if (lastprefilledindex > std::numeric_limits<uint16_t>::max())
69 if ((uint32_t)lastprefilledindex > cmpctblock.
shorttxids.size() + i) {
83 std::unordered_map<uint64_t, uint16_t> shorttxids(cmpctblock.
shorttxids.size());
84 uint16_t index_offset = 0;
85 for (
size_t i = 0; i < cmpctblock.
shorttxids.size(); i++) {
88 shorttxids[cmpctblock.
shorttxids[i]] = i + index_offset;
99 if (shorttxids.bucket_size(shorttxids.bucket(cmpctblock.
shorttxids[i])) > 12)
104 if (shorttxids.size() != cmpctblock.
shorttxids.size())
110 for (
const auto& tx :
pool->txns_randomized) {
111 uint64_t shortid = cmpctblock.
GetShortID(tx->GetWitnessHash());
112 std::unordered_map<uint64_t, uint16_t>::iterator idit = shorttxids.find(shortid);
113 if (idit != shorttxids.end()) {
114 if (!have_txn[idit->second]) {
116 have_txn[idit->second] =
true;
136 for (
size_t i = 0; i < extra_txn.size(); i++) {
137 if (extra_txn[i] ==
nullptr) {
140 uint64_t shortid = cmpctblock.
GetShortID(extra_txn[i]->GetWitnessHash());
141 std::unordered_map<uint64_t, uint16_t>::iterator idit = shorttxids.find(shortid);
142 if (idit != shorttxids.end()) {
143 if (!have_txn[idit->second]) {
145 have_txn[idit->second] =
true;
156 txn_available[idit->second]->GetWitnessHash() != extra_txn[i]->GetWitnessHash()) {
191 size_t tx_missing_offset = 0;
194 if (vtx_missing.size() <= tx_missing_offset)
196 block.
vtx[i] = vtx_missing[tx_missing_offset++];
205 if (vtx_missing.size() != tx_missing_offset)
210 if (!check_block(block, state,
Params().GetConsensus(),
true,
true)) {
221 if (vtx_missing.size() < 5) {
222 for (
const auto& tx : vtx_missing) {
enum ReadStatus_t ReadStatus
CSHA256 & Write(const unsigned char *data, size_t len)
uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256 &val)
Optimized SipHash-2-4 implementation for uint256.
ReadStatus FillBlock(CBlock &block, const std::vector< CTransactionRef > &vtx_missing)
#define LogPrint(category,...)
std::vector< CTransactionRef > txn_available
size_t GetSerializeSize(const T &t)
CheckBlockFn m_check_block_mock
void FillShortTxIDSelector() const
constexpr unsigned char * begin()
static const unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule)
CBlockHeaderAndShortTxIDs()=default
Dummy for deserialization.
std::function< bool(const CBlock &, BlockValidationState &, const Consensus::Params &, bool, bool)> CheckBlockFn
Double ended buffer combining vector and stream-like interfaces.
void Finalize(unsigned char hash[OUTPUT_SIZE])
static constexpr int SHORTTXIDS_LENGTH
std::string ToString() const
bool CheckBlock(const CBlock &block, BlockValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW, bool fCheckMerkleRoot)
Functions for validating blocks and updating the block tree.
ReadStatus InitData(const CBlockHeaderAndShortTxIDs &cmpctblock, const std::vector< CTransactionRef > &extra_txn)
static const size_t MIN_SERIALIZABLE_TRANSACTION_WEIGHT
std::vector< uint64_t > shorttxids
std::vector< CTransactionRef > vtx
the block's data didn't match the data committed to by the PoW
std::vector< PrefilledTransaction > prefilledtxn
const CChainParams & Params()
Return the currently selected parameters.
bool IsTxAvailable(size_t index) const
constexpr uint64_t GetUint64(int pos) const
The basic transaction that is broadcasted on the network and contained in blocks. ...
size_t BlockTxCount() const
A hasher class for SHA-256.
const Wtxid & GetWitnessHash() const LIFETIMEBOUND
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it...
uint64_t GetShortID(const Wtxid &wtxid) const
transaction_identifier represents the two canonical transaction identifier types (txid, wtxid).