Changeset View
Changeset View
Standalone View
Standalone View
src/blockencodings.cpp
Show All 36 Lines | void CBlockHeaderAndShortTxIDs::FillShortTxIDSelector() const { | ||||
CSHA256 hasher; | CSHA256 hasher; | ||||
hasher.Write((uint8_t *)&(*stream.begin()), stream.end() - stream.begin()); | hasher.Write((uint8_t *)&(*stream.begin()), stream.end() - stream.begin()); | ||||
uint256 shorttxidhash; | uint256 shorttxidhash; | ||||
hasher.Finalize(shorttxidhash.begin()); | hasher.Finalize(shorttxidhash.begin()); | ||||
shorttxidk0 = shorttxidhash.GetUint64(0); | shorttxidk0 = shorttxidhash.GetUint64(0); | ||||
shorttxidk1 = shorttxidhash.GetUint64(1); | shorttxidk1 = shorttxidhash.GetUint64(1); | ||||
} | } | ||||
uint64_t CBlockHeaderAndShortTxIDs::GetShortID(const uint256 &txhash) const { | uint64_t CBlockHeaderAndShortTxIDs::GetShortID(const TxHash &txhash) const { | ||||
static_assert(SHORTTXIDS_LENGTH == 6, | static_assert(SHORTTXIDS_LENGTH == 6, | ||||
"shorttxids calculation assumes 6-byte shorttxids"); | "shorttxids calculation assumes 6-byte shorttxids"); | ||||
return SipHashUint256(shorttxidk0, shorttxidk1, txhash) & 0xffffffffffffL; | return SipHashUint256(shorttxidk0, shorttxidk1, txhash) & 0xffffffffffffL; | ||||
} | } | ||||
ReadStatus PartiallyDownloadedBlock::InitData( | ReadStatus PartiallyDownloadedBlock::InitData( | ||||
const CBlockHeaderAndShortTxIDs &cmpctblock, | const CBlockHeaderAndShortTxIDs &cmpctblock, | ||||
const std::vector<std::pair<uint256, CTransactionRef>> &extra_txns) { | const std::vector<std::pair<TxHash, CTransactionRef>> &extra_txns) { | ||||
if (cmpctblock.header.IsNull() || | if (cmpctblock.header.IsNull() || | ||||
(cmpctblock.shorttxids.empty() && cmpctblock.prefilledtxn.empty())) { | (cmpctblock.shorttxids.empty() && cmpctblock.prefilledtxn.empty())) { | ||||
return READ_STATUS_INVALID; | return READ_STATUS_INVALID; | ||||
} | } | ||||
if (cmpctblock.shorttxids.size() + cmpctblock.prefilledtxn.size() > | if (cmpctblock.shorttxids.size() + cmpctblock.prefilledtxn.size() > | ||||
config->GetMaxBlockSize() / MIN_TRANSACTION_SIZE) { | config->GetMaxBlockSize() / MIN_TRANSACTION_SIZE) { | ||||
return READ_STATUS_INVALID; | return READ_STATUS_INVALID; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | ReadStatus PartiallyDownloadedBlock::InitData( | ||||
if (shorttxids.size() != cmpctblock.shorttxids.size()) { | if (shorttxids.size() != cmpctblock.shorttxids.size()) { | ||||
// Short ID collision | // Short ID collision | ||||
return READ_STATUS_FAILED; | return READ_STATUS_FAILED; | ||||
} | } | ||||
std::vector<bool> have_txn(txns_available.size()); | std::vector<bool> have_txn(txns_available.size()); | ||||
{ | { | ||||
LOCK(pool->cs); | LOCK(pool->cs); | ||||
const std::vector<std::pair<uint256, CTxMemPool::txiter>> &vTxHashes = | const std::vector<std::pair<TxHash, CTxMemPool::txiter>> &vTxHashes = | ||||
pool->vTxHashes; | pool->vTxHashes; | ||||
for (auto txHash : vTxHashes) { | for (auto txHash : vTxHashes) { | ||||
uint64_t shortid = cmpctblock.GetShortID(txHash.first); | uint64_t shortid = cmpctblock.GetShortID(txHash.first); | ||||
std::unordered_map<uint64_t, uint32_t>::iterator idit = | std::unordered_map<uint64_t, uint32_t>::iterator idit = | ||||
shorttxids.find(shortid); | shorttxids.find(shortid); | ||||
if (idit != shorttxids.end()) { | if (idit != shorttxids.end()) { | ||||
if (!have_txn[idit->second]) { | if (!have_txn[idit->second]) { | ||||
txns_available[idit->second] = txHash.second->GetSharedTx(); | txns_available[idit->second] = txHash.second->GetSharedTx(); | ||||
▲ Show 20 Lines • Show All 130 Lines • Show Last 20 Lines |