MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / validateCompactBlock

Function validateCompactBlock

src/blockencodings.cpp:80–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80void validateCompactBlock(const CompactBlock& cmpctblock, uint64_t currMaxBlockSize) {
81 if (cmpctblock.header.IsNull() || (cmpctblock.shorttxids.empty() && cmpctblock.prefilledtxn.empty()))
82 throw std::invalid_argument("empty data in compact block");
83
84 validateNumTxs(cmpctblock.shorttxids.size() + cmpctblock.prefilledtxn.size(), currMaxBlockSize);
85
86 int32_t lastprefilledindex = -1;
87 for (size_t i = 0; i < cmpctblock.prefilledtxn.size(); i++) {
88 if (cmpctblock.prefilledtxn[i].tx.IsNull())
89 throw std::invalid_argument("null tx in compact block");
90
91 lastprefilledindex += cmpctblock.prefilledtxn[i].index + 1; //index is a uint16_t, so cant overflow here
92 if (lastprefilledindex > std::numeric_limits<uint16_t>::max())
93 throw std::invalid_argument("tx index overflows");
94
95 if (static_cast<uint32_t>(lastprefilledindex) > cmpctblock.shorttxids.size() + i) {
96 // If we are inserting a tx at an index greater than our full list of shorttxids
97 // plus the number of prefilled txn we've inserted, then we have txn for which we
98 // have neither a prefilled txn or a shorttxid!
99 throw std::invalid_argument("invalid index for tx");
100 }
101 }
102}

Callers 2

operator()Method · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 4

validateNumTxsFunction · 0.85
IsNullMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68