Changeset View
Changeset View
Standalone View
Standalone View
src/blockencodings.h
// Copyright (c) 2016 The Bitcoin Core developers | // Copyright (c) 2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_BLOCKENCODINGS_H | #ifndef BITCOIN_BLOCKENCODINGS_H | ||||
#define BITCOIN_BLOCKENCODINGS_H | #define BITCOIN_BLOCKENCODINGS_H | ||||
#include <primitives/block.h> | #include <primitives/block.h> | ||||
#include <serialize.h> | #include <serialize.h> | ||||
#include <shortidprocessor.h> | |||||
#include <cstdint> | |||||
#include <memory> | |||||
#include <vector> | |||||
class Config; | class Config; | ||||
class CTxMemPool; | class CTxMemPool; | ||||
// Transaction compression schemes for compact block relay can be introduced by | // Transaction compression schemes for compact block relay can be introduced by | ||||
// writing an actual formatter here. | // writing an actual formatter here. | ||||
using TransactionCompression = DefaultFormatter; | using TransactionCompression = DefaultFormatter; | ||||
Show All 31 Lines | struct PrefilledTransaction { | ||||
// Used as an offset since last prefilled tx in CBlockHeaderAndShortTxIDs | // Used as an offset since last prefilled tx in CBlockHeaderAndShortTxIDs | ||||
uint32_t index; | uint32_t index; | ||||
CTransactionRef tx; | CTransactionRef tx; | ||||
template <typename Stream> void SerData(Stream &s) { s << tx; } | template <typename Stream> void SerData(Stream &s) { s << tx; } | ||||
template <typename Stream> void UnserData(Stream &s) { s >> tx; } | template <typename Stream> void UnserData(Stream &s) { s >> tx; } | ||||
}; | }; | ||||
struct ShortIdProcessorPrefilledTransactionAdapter { | |||||
uint32_t getIndex(const PrefilledTransaction &pt) const { return pt.index; } | |||||
CTransactionRef getItem(const PrefilledTransaction &pt) const { | |||||
return pt.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. | ||||
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. | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | SERIALIZE_METHODS(CBlockHeaderAndShortTxIDs, obj) { | ||||
} | } | ||||
obj.FillShortTxIDSelector(); | obj.FillShortTxIDSelector(); | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
class PartiallyDownloadedBlock { | class PartiallyDownloadedBlock { | ||||
struct CTransactionRefCompare { | |||||
bool operator()(const CTransactionRef &lhs, | |||||
const CTransactionRef &rhs) const { | |||||
return lhs->GetHash() == rhs->GetHash(); | |||||
} | |||||
}; | |||||
using TransactionShortIdProcessor = | |||||
ShortIdProcessor<PrefilledTransaction, | |||||
ShortIdProcessorPrefilledTransactionAdapter, | |||||
CTransactionRefCompare>; | |||||
// FIXME This better fits a unique_ptr, but the unit tests needs a copy | |||||
// operator for this class. It can be trivially changed when the unit tests | |||||
// are refactored. | |||||
std::shared_ptr<TransactionShortIdProcessor> shortidProcessor; | |||||
protected: | protected: | ||||
std::vector<CTransactionRef> txns_available; | |||||
size_t prefilled_count = 0, mempool_count = 0, extra_count = 0; | size_t prefilled_count = 0, mempool_count = 0, extra_count = 0; | ||||
const CTxMemPool *pool; | const 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) {} | ||||
Show All 12 Lines |