Changeset View
Changeset View
Standalone View
Standalone View
src/blockencodings.h
Show First 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
} | } | ||||
} 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 CBlockHeaderAndShortTxHashes 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 | ||||
// CBlockHeaderAndShortTxHashes, | |||||
// as a proper transaction-in-block-index in PartiallyDownloadedBlock | // as a proper transaction-in-block-index in PartiallyDownloadedBlock | ||||
uint16_t index; | uint16_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) { | ||||
Show All 12 Lines | typedef enum ReadStatus_t { | ||||
// FIXME: differenciate bogus crap from crap that do not fit our policy. | // FIXME: differenciate bogus crap from crap that do not fit our policy. | ||||
READ_STATUS_INVALID, | READ_STATUS_INVALID, | ||||
// Failed to process object. | // Failed to process object. | ||||
READ_STATUS_FAILED, | READ_STATUS_FAILED, | ||||
// Used only by FillBlock to indicate a failure in CheckBlock. | // Used only by FillBlock to indicate a failure in CheckBlock. | ||||
READ_STATUS_CHECKBLOCK_FAILED, | READ_STATUS_CHECKBLOCK_FAILED, | ||||
} ReadStatus; | } ReadStatus; | ||||
class CBlockHeaderAndShortTxIDs { | class CBlockHeaderAndShortTxHashes { | ||||
private: | private: | ||||
mutable uint64_t shorttxidk0, shorttxidk1; | mutable uint64_t shorttxhashk0, shorttxhashk1; | ||||
uint64_t nonce; | uint64_t nonce; | ||||
void FillShortTxIDSelector() const; | void FillShortTxHashSelector() const; | ||||
friend class PartiallyDownloadedBlock; | friend class PartiallyDownloadedBlock; | ||||
static const int SHORTTXIDS_LENGTH = 6; | static const int SHORTTXHASHES_LENGTH = 6; | ||||
protected: | protected: | ||||
std::vector<uint64_t> shorttxids; | std::vector<uint64_t> shortTxHashes; | ||||
std::vector<PrefilledTransaction> prefilledtxn; | std::vector<PrefilledTransaction> prefilledtxn; | ||||
public: | public: | ||||
CBlockHeader header; | CBlockHeader header; | ||||
// Dummy for deserialization | // Dummy for deserialization | ||||
CBlockHeaderAndShortTxIDs() {} | CBlockHeaderAndShortTxHashes() {} | ||||
CBlockHeaderAndShortTxIDs(const CBlock &block); | CBlockHeaderAndShortTxHashes(const CBlock &block); | ||||
uint64_t GetShortID(const uint256 &txhash) const; | uint64_t GetShortID(const uint256 &txhash) const; | ||||
size_t BlockTxCount() const { | size_t BlockTxCount() const { | ||||
return shorttxids.size() + prefilledtxn.size(); | return shortTxHashes.size() + prefilledtxn.size(); | ||||
} | } | ||||
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(header); | READWRITE(header); | ||||
READWRITE(nonce); | READWRITE(nonce); | ||||
uint64_t shorttxids_size = (uint64_t)shorttxids.size(); | uint64_t shortTxHashes_size = (uint64_t)shortTxHashes.size(); | ||||
READWRITE(COMPACTSIZE(shorttxids_size)); | READWRITE(COMPACTSIZE(shortTxHashes_size)); | ||||
if (ser_action.ForRead()) { | if (ser_action.ForRead()) { | ||||
size_t i = 0; | size_t i = 0; | ||||
while (shorttxids.size() < shorttxids_size) { | while (shortTxHashes.size() < shortTxHashes_size) { | ||||
shorttxids.resize(std::min((uint64_t)(1000 + shorttxids.size()), | shortTxHashes.resize( | ||||
shorttxids_size)); | std::min((uint64_t)(1000 + shortTxHashes.size()), | ||||
for (; i < shorttxids.size(); i++) { | shortTxHashes_size)); | ||||
for (; i < shortTxHashes.size(); i++) { | |||||
uint32_t lsb = 0; | uint32_t lsb = 0; | ||||
uint16_t msb = 0; | uint16_t msb = 0; | ||||
READWRITE(lsb); | READWRITE(lsb); | ||||
READWRITE(msb); | READWRITE(msb); | ||||
shorttxids[i] = (uint64_t(msb) << 32) | uint64_t(lsb); | shortTxHashes[i] = (uint64_t(msb) << 32) | uint64_t(lsb); | ||||
static_assert( | static_assert(SHORTTXHASHES_LENGTH == 6, | ||||
SHORTTXIDS_LENGTH == 6, | "shortTxHashes serialization assumes 6-byte " | ||||
"shorttxids serialization assumes 6-byte shorttxids"); | "shortTxHashes"); | ||||
} | } | ||||
} | } | ||||
} else { | } else { | ||||
for (size_t i = 0; i < shorttxids.size(); i++) { | for (size_t i = 0; i < shortTxHashes.size(); i++) { | ||||
uint32_t lsb = shorttxids[i] & 0xffffffff; | uint32_t lsb = shortTxHashes[i] & 0xffffffff; | ||||
uint16_t msb = (shorttxids[i] >> 32) & 0xffff; | uint16_t msb = (shortTxHashes[i] >> 32) & 0xffff; | ||||
READWRITE(lsb); | READWRITE(lsb); | ||||
READWRITE(msb); | READWRITE(msb); | ||||
} | } | ||||
} | } | ||||
READWRITE(prefilledtxn); | READWRITE(prefilledtxn); | ||||
if (ser_action.ForRead()) FillShortTxIDSelector(); | if (ser_action.ForRead()) FillShortTxHashSelector(); | ||||
} | } | ||||
}; | }; | ||||
class PartiallyDownloadedBlock { | class PartiallyDownloadedBlock { | ||||
protected: | protected: | ||||
std::vector<CTransactionRef> txn_available; | std::vector<CTransactionRef> txn_available; | ||||
size_t prefilled_count = 0, mempool_count = 0, extra_count = 0; | size_t prefilled_count = 0, mempool_count = 0, extra_count = 0; | ||||
CTxMemPool *pool; | CTxMemPool *pool; | ||||
const Config *config; | const Config *config; | ||||
public: | public: | ||||
CBlockHeader header; | CBlockHeader header; | ||||
PartiallyDownloadedBlock(const Config &configIn, CTxMemPool *poolIn) | PartiallyDownloadedBlock(const Config &configIn, CTxMemPool *poolIn) | ||||
: pool(poolIn), config(&configIn) {} | : pool(poolIn), config(&configIn) {} | ||||
// extra_txn is a list of extra transactions to look at, in <txhash, | // extra_txn is a list of extra transactions to look at, in <txhash, | ||||
// reference> form. | // reference> form. | ||||
ReadStatus | ReadStatus | ||||
InitData(const CBlockHeaderAndShortTxIDs &cmpctblock, | InitData(const CBlockHeaderAndShortTxHashes &cmpctblock, | ||||
const std::vector<std::pair<uint256, CTransactionRef>> &extra_txn); | const std::vector<std::pair<uint256, CTransactionRef>> &extra_txn); | ||||
bool IsTxAvailable(size_t index) const; | bool IsTxAvailable(size_t index) const; | ||||
ReadStatus FillBlock(CBlock &block, | ReadStatus FillBlock(CBlock &block, | ||||
const std::vector<CTransactionRef> &vtx_missing); | const std::vector<CTransactionRef> &vtx_missing); | ||||
}; | }; | ||||
#endif | #endif |