mirror of https://github.com/bitcoin/bitcoin
refactor: Simplify `extra_txn` to be a vec of CTransactionRef instead of a vec of pair<Wtxid, CTransactionRef>
All `CTransactionRef` have `.GetWitnessHash()` that returns a cached `const Wtxid` (since fac1223a56
),
so we don't need to pass transaction refs around with their IDs as they're easy to get from a ref.
This commit is contained in:
parent
c3c18433ae
commit
a8203e9412
|
@ -47,7 +47,7 @@ uint64_t CBlockHeaderAndShortTxIDs::GetShortID(const Wtxid& wtxid) const {
|
|||
|
||||
|
||||
|
||||
ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<std::pair<Wtxid, CTransactionRef>>& extra_txn) {
|
||||
ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<CTransactionRef>& extra_txn) {
|
||||
if (cmpctblock.header.IsNull() || (cmpctblock.shorttxids.empty() && cmpctblock.prefilledtxn.empty()))
|
||||
return READ_STATUS_INVALID;
|
||||
if (cmpctblock.shorttxids.size() + cmpctblock.prefilledtxn.size() > MAX_BLOCK_WEIGHT / MIN_SERIALIZABLE_TRANSACTION_WEIGHT)
|
||||
|
@ -134,11 +134,14 @@ ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& c
|
|||
}
|
||||
|
||||
for (size_t i = 0; i < extra_txn.size(); i++) {
|
||||
uint64_t shortid = cmpctblock.GetShortID(extra_txn[i].first);
|
||||
if (extra_txn[i] == nullptr) {
|
||||
continue;
|
||||
}
|
||||
uint64_t shortid = cmpctblock.GetShortID(extra_txn[i]->GetWitnessHash());
|
||||
std::unordered_map<uint64_t, uint16_t>::iterator idit = shorttxids.find(shortid);
|
||||
if (idit != shorttxids.end()) {
|
||||
if (!have_txn[idit->second]) {
|
||||
txn_available[idit->second] = extra_txn[i].second;
|
||||
txn_available[idit->second] = extra_txn[i];
|
||||
have_txn[idit->second] = true;
|
||||
mempool_count++;
|
||||
extra_count++;
|
||||
|
@ -150,7 +153,7 @@ ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& c
|
|||
// Note that we don't want duplication between extra_txn and mempool to
|
||||
// trigger this case, so we compare witness hashes first
|
||||
if (txn_available[idit->second] &&
|
||||
txn_available[idit->second]->GetWitnessHash() != extra_txn[i].second->GetWitnessHash()) {
|
||||
txn_available[idit->second]->GetWitnessHash() != extra_txn[i]->GetWitnessHash()) {
|
||||
txn_available[idit->second].reset();
|
||||
mempool_count--;
|
||||
extra_count--;
|
||||
|
|
|
@ -142,7 +142,7 @@ public:
|
|||
explicit PartiallyDownloadedBlock(CTxMemPool* poolIn) : pool(poolIn) {}
|
||||
|
||||
// extra_txn is a list of extra transactions to look at, in <witness hash, reference> form
|
||||
ReadStatus InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<std::pair<Wtxid, CTransactionRef>>& extra_txn);
|
||||
ReadStatus InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<CTransactionRef>& extra_txn);
|
||||
bool IsTxAvailable(size_t index) const;
|
||||
ReadStatus FillBlock(CBlock& block, const std::vector<CTransactionRef>& vtx_missing);
|
||||
};
|
||||
|
|
|
@ -1006,7 +1006,7 @@ private:
|
|||
/** Orphan/conflicted/etc transactions that are kept for compact block reconstruction.
|
||||
* The last -blockreconstructionextratxn/DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN of
|
||||
* these are kept in a ring buffer */
|
||||
std::vector<std::pair<Wtxid, CTransactionRef>> vExtraTxnForCompact GUARDED_BY(g_msgproc_mutex);
|
||||
std::vector<CTransactionRef> vExtraTxnForCompact GUARDED_BY(g_msgproc_mutex);
|
||||
/** Offset into vExtraTxnForCompact to insert the next tx */
|
||||
size_t vExtraTxnForCompactIt GUARDED_BY(g_msgproc_mutex) = 0;
|
||||
|
||||
|
@ -1802,7 +1802,7 @@ void PeerManagerImpl::AddToCompactExtraTransactions(const CTransactionRef& tx)
|
|||
return;
|
||||
if (!vExtraTxnForCompact.size())
|
||||
vExtraTxnForCompact.resize(m_opts.max_extra_txs);
|
||||
vExtraTxnForCompact[vExtraTxnForCompactIt] = std::make_pair(tx->GetWitnessHash(), tx);
|
||||
vExtraTxnForCompact[vExtraTxnForCompactIt] = tx;
|
||||
vExtraTxnForCompactIt = (vExtraTxnForCompactIt + 1) % m_opts.max_extra_txs;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
std::vector<std::pair<Wtxid, CTransactionRef>> extra_txn;
|
||||
std::vector<CTransactionRef> extra_txn;
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(blockencodings_tests, RegTestingSetup)
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ FUZZ_TARGET(partially_downloaded_block, .init = initialize_pdb)
|
|||
// The coinbase is always available
|
||||
available.insert(0);
|
||||
|
||||
std::vector<std::pair<Wtxid, CTransactionRef>> extra_txn;
|
||||
std::vector<CTransactionRef> extra_txn;
|
||||
for (size_t i = 1; i < block->vtx.size(); ++i) {
|
||||
auto tx{block->vtx[i]};
|
||||
|
||||
|
@ -68,7 +68,7 @@ FUZZ_TARGET(partially_downloaded_block, .init = initialize_pdb)
|
|||
bool add_to_mempool{fuzzed_data_provider.ConsumeBool()};
|
||||
|
||||
if (add_to_extra_txn) {
|
||||
extra_txn.emplace_back(tx->GetWitnessHash(), tx);
|
||||
extra_txn.emplace_back(tx);
|
||||
available.insert(i);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue