17 #include <unordered_map>
21 shorttxids(block.vtx.size() - 1), prefilledtxn(1), header(block) {
25 for (
size_t i = 1; i < block.
vtx.size(); i++) {
35 hasher.
Write((
unsigned char*)&(*stream.begin()), stream.end() - stream.begin());
43 static_assert(
SHORTTXIDS_LENGTH == 6,
"shorttxids calculation assumes 6-byte shorttxids");
60 int32_t lastprefilledindex = -1;
61 for (
size_t i = 0; i < cmpctblock.
prefilledtxn.size(); i++) {
65 lastprefilledindex += cmpctblock.
prefilledtxn[i].index + 1;
66 if (lastprefilledindex > std::numeric_limits<uint16_t>::max())
68 if ((uint32_t)lastprefilledindex > cmpctblock.
shorttxids.size() + i) {
82 std::unordered_map<uint64_t, uint16_t> shorttxids(cmpctblock.
shorttxids.size());
83 uint16_t index_offset = 0;
84 for (
size_t i = 0; i < cmpctblock.
shorttxids.size(); i++) {
87 shorttxids[cmpctblock.
shorttxids[i]] = i + index_offset;
98 if (shorttxids.bucket_size(shorttxids.bucket(cmpctblock.
shorttxids[i])) > 12)
103 if (shorttxids.size() != cmpctblock.
shorttxids.size())
109 for (
size_t i = 0; i <
pool->vTxHashes.
size(); i++) {
110 uint64_t shortid = cmpctblock.
GetShortID(
pool->vTxHashes[i].first);
111 std::unordered_map<uint64_t, uint16_t>::iterator idit = shorttxids.find(shortid);
112 if (idit != shorttxids.end()) {
113 if (!have_txn[idit->second]) {
115 have_txn[idit->second] =
true;
135 for (
size_t i = 0; i <
extra_txn.size(); i++) {
137 std::unordered_map<uint64_t, uint16_t>::iterator idit = shorttxids.find(shortid);
138 if (idit != shorttxids.end()) {
139 if (!have_txn[idit->second]) {
141 have_txn[idit->second] =
true;
187 size_t tx_missing_offset = 0;
190 if (vtx_missing.size() <= tx_missing_offset)
192 block.
vtx[i] = vtx_missing[tx_missing_offset++];
201 if (vtx_missing.size() != tx_missing_offset)
206 if (!check_block(block, state,
Params().GetConsensus(),
true,
true)) {
217 if (vtx_missing.size() < 5) {
218 for (
const auto& tx : vtx_missing) {
@ READ_STATUS_CHECKBLOCK_FAILED
enum ReadStatus_t ReadStatus
std::vector< std::pair< uint256, CTransactionRef > > extra_txn
const CChainParams & Params()
Return the currently selected parameters.
size_t BlockTxCount() const
void FillShortTxIDSelector() const
CBlockHeaderAndShortTxIDs()
std::vector< PrefilledTransaction > prefilledtxn
uint64_t GetShortID(const uint256 &txhash) const
static constexpr int SHORTTXIDS_LENGTH
std::vector< uint64_t > shorttxids
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 uint256 & GetWitnessHash() const
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
unsigned long size() const
Double ended buffer combining vector and stream-like interfaces.
ReadStatus InitData(const CBlockHeaderAndShortTxIDs &cmpctblock, const std::vector< std::pair< uint256, CTransactionRef >> &extra_txn)
CheckBlockFn m_check_block_mock
std::vector< CTransactionRef > txn_available
bool IsTxAvailable(size_t index) const
ReadStatus FillBlock(CBlock &block, const std::vector< CTransactionRef > &vtx_missing)
std::function< bool(const CBlock &, BlockValidationState &, const Consensus::Params &, bool, bool)> CheckBlockFn
constexpr uint64_t GetUint64(int pos) const
std::string ToString() const
constexpr unsigned char * begin()
@ BLOCK_MUTATED
the block's data didn't match the data committed to by the PoW
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 LogPrint(category,...)
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.
bool CheckBlock(const CBlock &block, BlockValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW, bool fCheckMerkleRoot)
Functions for validating blocks and updating the block tree.
static const int PROTOCOL_VERSION
network protocol versioning