16 #include <unordered_map>
18 #define MIN_TRANSACTION_BASE_SIZE (::GetSerializeSize(CTransaction(), SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS))
21 nonce(
GetRand(std::numeric_limits<uint64_t>::max())),
22 shorttxids(block.vtx.size() - 1), prefilledtxn(1), header(block) {
26 for (
size_t i = 1; i < block.
vtx.size(); i++) {
44 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 const std::vector<std::pair<uint256, CTxMemPool::txiter> >& vTxHashes =
pool->
vTxHashes;
110 for (
size_t i = 0; i < vTxHashes.size(); i++) {
111 uint64_t shortid = cmpctblock.
GetShortID(vTxHashes[i].first);
112 std::unordered_map<uint64_t, uint16_t>::iterator idit = shorttxids.find(shortid);
113 if (idit != shorttxids.end()) {
114 if (!have_txn[idit->second]) {
115 txn_available[idit->second] = vTxHashes[i].second->GetSharedTx();
116 have_txn[idit->second] =
true;
136 for (
size_t i = 0; i < extra_txn.size(); i++) {
137 uint64_t shortid = cmpctblock.
GetShortID(extra_txn[i].first);
138 std::unordered_map<uint64_t, uint16_t>::iterator idit = shorttxids.find(shortid);
139 if (idit != shorttxids.end()) {
140 if (!have_txn[idit->second]) {
142 have_txn[idit->second] =
true;
153 txn_available[idit->second]->GetWitnessHash() != extra_txn[i].second->GetWitnessHash()) {
184 size_t tx_missing_offset = 0;
187 if (vtx_missing.size() <= tx_missing_offset)
189 block.
vtx[i] = vtx_missing[tx_missing_offset++];
198 if (vtx_missing.size() != tx_missing_offset)
214 if (vtx_missing.size() < 5) {
215 for (
const auto& tx : vtx_missing)
216 LogPrint(
"cmpctblock",
"Reconstructed block %s required tx %s\n", hash.
ToString(), tx->GetHash().ToString());
#define MIN_TRANSACTION_BASE_SIZE
@ READ_STATUS_CHECKBLOCK_FAILED
enum ReadStatus_t ReadStatus
size_t BlockTxCount() const
void FillShortTxIDSelector() const
CBlockHeaderAndShortTxIDs()
std::vector< PrefilledTransaction > prefilledtxn
uint64_t GetShortID(const uint256 &txhash) const
std::vector< uint64_t > shorttxids
static const int SHORTTXIDS_LENGTH
std::vector< CTransactionRef > vtx
Double ended buffer combining vector and stream-like interfaces.
const_iterator begin() const
const_iterator end() const
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 & GetHash() const
uint256 GetWitnessHash() const
std::vector< std::pair< uint256, txiter > > vTxHashes
All tx witness hashes/entries in mapTx, in random order.
Capture information about block/transaction validation.
bool CorruptionPossible() const
ReadStatus InitData(const CBlockHeaderAndShortTxIDs &cmpctblock, const std::vector< std::pair< uint256, CTransactionRef >> &extra_txn)
std::vector< CTransactionRef > txn_available
bool IsTxAvailable(size_t index) const
ReadStatus FillBlock(CBlock &block, const std::vector< CTransactionRef > &vtx_missing)
std::string ToString() const
uint64_t GetUint64(int pos) const
uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256 &val)
Optimized SipHash-2-4 implementation for uint256.
uint64_t GetRand(uint64_t nMax)
size_t GetSerializeSize(const T &t, int nType, int nVersion=0)
#define LogPrint(category,...)
bool CheckBlock(const CBlock &block, CValidationState &state, bool fCheckPOW, bool fCheckMerkleRoot)