mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
Make CBlock::vtx a vector of shared_ptr<CTransaction>
This commit is contained in:
@@ -24,7 +24,7 @@ CBlockHeaderAndShortTxIDs::CBlockHeaderAndShortTxIDs(const CBlock& block, bool f
|
||||
//TODO: Use our mempool prior to block acceptance to predictively fill more than just the coinbase
|
||||
prefilledtxn[0] = {0, block.vtx[0]};
|
||||
for (size_t i = 1; i < block.vtx.size(); i++) {
|
||||
const CTransaction& tx = block.vtx[i];
|
||||
const CTransaction& tx = *block.vtx[i];
|
||||
shorttxids[i - 1] = GetShortID(fUseWTXID ? tx.GetWitnessHash() : tx.GetHash());
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& c
|
||||
|
||||
int32_t lastprefilledindex = -1;
|
||||
for (size_t i = 0; i < cmpctblock.prefilledtxn.size(); i++) {
|
||||
if (cmpctblock.prefilledtxn[i].tx.IsNull())
|
||||
if (cmpctblock.prefilledtxn[i].tx->IsNull())
|
||||
return READ_STATUS_INVALID;
|
||||
|
||||
lastprefilledindex += cmpctblock.prefilledtxn[i].index + 1; //index is a uint16_t, so cant overflow here
|
||||
@@ -71,7 +71,7 @@ ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& c
|
||||
// have neither a prefilled txn or a shorttxid!
|
||||
return READ_STATUS_INVALID;
|
||||
}
|
||||
txn_available[lastprefilledindex] = std::make_shared<CTransaction>(cmpctblock.prefilledtxn[i].tx);
|
||||
txn_available[lastprefilledindex] = cmpctblock.prefilledtxn[i].tx;
|
||||
}
|
||||
prefilled_count = cmpctblock.prefilledtxn.size();
|
||||
|
||||
@@ -142,7 +142,7 @@ bool PartiallyDownloadedBlock::IsTxAvailable(size_t index) const {
|
||||
return txn_available[index] ? true : false;
|
||||
}
|
||||
|
||||
ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<CTransaction>& vtx_missing) const {
|
||||
ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<std::shared_ptr<const CTransaction>>& vtx_missing) const {
|
||||
assert(!header.IsNull());
|
||||
block = header;
|
||||
block.vtx.resize(txn_available.size());
|
||||
@@ -154,7 +154,7 @@ ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<
|
||||
return READ_STATUS_INVALID;
|
||||
block.vtx[i] = vtx_missing[tx_missing_offset++];
|
||||
} else
|
||||
block.vtx[i] = *txn_available[i];
|
||||
block.vtx[i] = txn_available[i];
|
||||
}
|
||||
if (vtx_missing.size() != tx_missing_offset)
|
||||
return READ_STATUS_INVALID;
|
||||
@@ -172,8 +172,8 @@ ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<
|
||||
|
||||
LogPrint("cmpctblock", "Successfully reconstructed block %s with %lu txn prefilled, %lu txn from mempool and %lu txn requested\n", header.GetHash().ToString(), prefilled_count, mempool_count, vtx_missing.size());
|
||||
if (vtx_missing.size() < 5) {
|
||||
for(const CTransaction& tx : vtx_missing)
|
||||
LogPrint("cmpctblock", "Reconstructed block %s required tx %s\n", header.GetHash().ToString(), tx.GetHash().ToString());
|
||||
for (const auto& tx : vtx_missing)
|
||||
LogPrint("cmpctblock", "Reconstructed block %s required tx %s\n", header.GetHash().ToString(), tx->GetHash().ToString());
|
||||
}
|
||||
|
||||
return READ_STATUS_OK;
|
||||
|
||||
Reference in New Issue
Block a user