Changeset View
Changeset View
Standalone View
Standalone View
src/blockencodings.h
Show All 27 Lines | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(tx); | READWRITE(tx); | ||||
} | } | ||||
}; | }; | ||||
class BlockTransactionsRequest { | class BlockTransactionsRequest { | ||||
public: | public: | ||||
// A BlockTransactionsRequest message | // A BlockTransactionsRequest message | ||||
uint256 blockhash; | uint256 blockhash; | ||||
std::vector<uint16_t> indices; | std::vector<uint32_t> indices; | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(blockhash); | READWRITE(blockhash); | ||||
uint64_t indices_size = uint64_t(indices.size()); | uint64_t indices_size = uint64_t(indices.size()); | ||||
READWRITE(COMPACTSIZE(indices_size)); | READWRITE(COMPACTSIZE(indices_size)); | ||||
if (ser_action.ForRead()) { | if (ser_action.ForRead()) { | ||||
size_t i = 0; | size_t i = 0; | ||||
while (indices.size() < indices_size) { | while (indices.size() < indices_size) { | ||||
indices.resize( | indices.resize( | ||||
std::min(uint64_t(1000 + indices.size()), indices_size)); | std::min(uint64_t(1000 + indices.size()), indices_size)); | ||||
for (; i < indices.size(); i++) { | for (; i < indices.size(); i++) { | ||||
uint64_t n = 0; | uint64_t n = 0; | ||||
READWRITE(COMPACTSIZE(n)); | READWRITE(COMPACTSIZE(n)); | ||||
if (indices[i] > std::numeric_limits<uint16_t>::max()) { | if (n > std::numeric_limits<uint32_t>::max()) { | ||||
throw std::ios_base::failure( | throw std::ios_base::failure( | ||||
"index overflowed 16 bits"); | "index overflowed 32 bits"); | ||||
} | } | ||||
indices[i] = n; | indices[i] = n; | ||||
} | } | ||||
} | } | ||||
uint16_t offset = 0; | uint32_t offset = 0; | ||||
for (auto &index : indices) { | for (auto &index : indices) { | ||||
if (uint64_t(index) + uint64_t(offset) > | if (uint64_t(index) + uint64_t(offset) > | ||||
std::numeric_limits<uint16_t>::max()) { | std::numeric_limits<uint32_t>::max()) { | ||||
throw std::ios_base::failure("indices overflowed 16 bits"); | throw std::ios_base::failure("indices overflowed 32 bits"); | ||||
} | } | ||||
index = index + offset; | index = index + offset; | ||||
offset = index + 1; | offset = index + 1; | ||||
} | } | ||||
} else { | } else { | ||||
for (size_t i = 0; i < indices.size(); i++) { | for (size_t i = 0; i < indices.size(); i++) { | ||||
uint64_t index = | uint64_t index = | ||||
indices[i] - (i == 0 ? 0 : (indices[i - 1] + 1)); | indices[i] - (i == 0 ? 0 : (indices[i - 1] + 1)); | ||||
Show All 18 Lines | public: | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(blockhash); | READWRITE(blockhash); | ||||
uint64_t txn_size = (uint64_t)txn.size(); | uint64_t txn_size = (uint64_t)txn.size(); | ||||
READWRITE(COMPACTSIZE(txn_size)); | READWRITE(COMPACTSIZE(txn_size)); | ||||
if (ser_action.ForRead()) { | if (ser_action.ForRead()) { | ||||
size_t i = 0; | size_t i = 0; | ||||
while (txn.size() < txn_size) { | while (txn.size() < txn_size) { | ||||
txn.resize(std::min((uint64_t)(1000 + txn.size()), txn_size)); | txn.resize(std::min(uint64_t(1000 + txn.size()), txn_size)); | ||||
for (; i < txn.size(); i++) { | for (; i < txn.size(); i++) { | ||||
READWRITE(REF(TransactionCompressor(txn[i]))); | READWRITE(REF(TransactionCompressor(txn[i]))); | ||||
} | } | ||||
} | } | ||||
} else { | } else { | ||||
for (size_t i = 0; i < txn.size(); i++) { | for (size_t i = 0; i < txn.size(); i++) { | ||||
READWRITE(REF(TransactionCompressor(txn[i]))); | READWRITE(REF(TransactionCompressor(txn[i]))); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
// Dumb serialization/storage-helper for CBlockHeaderAndShortTxIDs and | // Dumb serialization/storage-helper for CBlockHeaderAndShortTxIDs and | ||||
// PartiallyDownloadedBlock | // PartiallyDownloadedBlock | ||||
struct PrefilledTransaction { | struct PrefilledTransaction { | ||||
// Used as an offset since last prefilled tx in CBlockHeaderAndShortTxIDs, | // Used as an offset since last prefilled tx in CBlockHeaderAndShortTxIDs, | ||||
// as a proper transaction-in-block-index in PartiallyDownloadedBlock | // as a proper transaction-in-block-index in PartiallyDownloadedBlock | ||||
uint16_t index; | uint32_t index; | ||||
CTransactionRef tx; | CTransactionRef tx; | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
uint64_t idx = index; | uint64_t n = index; | ||||
READWRITE(COMPACTSIZE(idx)); | READWRITE(COMPACTSIZE(n)); | ||||
if (idx > std::numeric_limits<uint16_t>::max()) { | if (n > std::numeric_limits<uint32_t>::max()) { | ||||
throw std::ios_base::failure("index overflowed 16-bits"); | throw std::ios_base::failure("index overflowed 32-bits"); | ||||
} | } | ||||
index = idx; | index = n; | ||||
READWRITE(REF(TransactionCompressor(tx))); | READWRITE(REF(TransactionCompressor(tx))); | ||||
} | } | ||||
}; | }; | ||||
typedef enum ReadStatus_t { | typedef enum ReadStatus_t { | ||||
READ_STATUS_OK, | READ_STATUS_OK, | ||||
// Invalid object, peer is sending bogus crap. | // Invalid object, peer is sending bogus crap. | ||||
// FIXME: differenciate bogus crap from crap that do not fit our policy. | // FIXME: differenciate bogus crap from crap that do not fit our policy. | ||||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |