Skip to content

Commit b7b249d

Browse files
committed
Revert "[refactor] rewrite vTxHashes as a vector of CTransactionRef"
This reverts commit a03aef9.
1 parent b9300d8 commit b7b249d

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/blockencodings.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& c
114114
std::vector<bool> have_txn(txn_available.size());
115115
{
116116
LOCK(pool->cs);
117-
for (const auto& tx : pool->txns_randomized) {
118-
uint64_t shortid = cmpctblock.GetShortID(tx->GetWitnessHash());
117+
for (const auto& [wtxid, txit] : pool->txns_randomized) {
118+
uint64_t shortid = cmpctblock.GetShortID(wtxid);
119119
std::unordered_map<uint64_t, uint16_t>::iterator idit = shorttxids.find(shortid);
120120
if (idit != shorttxids.end()) {
121121
if (!have_txn[idit->second]) {
122-
txn_available[idit->second] = tx;
122+
txn_available[idit->second] = txit->GetSharedTx();
123123
have_txn[idit->second] = true;
124124
mempool_count++;
125125
} else {

src/test/blockencodings_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ static CBlock BuildBlockTestCase(FastRandomContext& ctx) {
5656
}
5757

5858
// Number of shared use_counts we expect for a tx we haven't touched
59-
// (block + mempool entry + mempool txns_randomized + our copy from the GetSharedTx call)
60-
constexpr long SHARED_TX_OFFSET{4};
59+
// (block + mempool entry + our copy from the GetSharedTx call)
60+
constexpr long SHARED_TX_OFFSET{3};
6161

6262
BOOST_AUTO_TEST_CASE(SimpleRoundTripTest)
6363
{

src/txmempool.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ void CTxMemPool::addNewTransaction(CTxMemPool::txiter newit, CTxMemPool::setEntr
507507
totalTxSize += entry.GetTxSize();
508508
m_total_fee += entry.GetFee();
509509

510-
txns_randomized.emplace_back(newit->GetSharedTx());
510+
txns_randomized.emplace_back(tx.GetWitnessHash(), newit);
511511
newit->idx_randomized = txns_randomized.size() - 1;
512512

513513
TRACEPOINT(mempool, added,
@@ -544,15 +544,16 @@ void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason)
544544
RemoveUnbroadcastTx(it->GetTx().GetHash(), true /* add logging because unchecked */);
545545

546546
if (txns_randomized.size() > 1) {
547-
// Update idx_randomized of the to-be-moved entry.
548-
Assert(GetEntry(txns_randomized.back()->GetHash()))->idx_randomized = it->idx_randomized;
549547
// Remove entry from txns_randomized by replacing it with the back and deleting the back.
550548
txns_randomized[it->idx_randomized] = std::move(txns_randomized.back());
549+
txns_randomized[it->idx_randomized].second->idx_randomized = it->idx_randomized;
551550
txns_randomized.pop_back();
552-
if (txns_randomized.size() * 2 < txns_randomized.capacity())
551+
if (txns_randomized.size() * 2 < txns_randomized.capacity()) {
553552
txns_randomized.shrink_to_fit();
554-
} else
553+
}
554+
} else {
555555
txns_randomized.clear();
556+
}
556557

557558
totalTxSize -= it->GetTxSize();
558559
m_total_fee -= it->GetFee();

src/txmempool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ class CTxMemPool
368368
indexed_transaction_set mapTx GUARDED_BY(cs);
369369

370370
using txiter = indexed_transaction_set::nth_index<0>::type::const_iterator;
371-
std::vector<CTransactionRef> txns_randomized GUARDED_BY(cs); //!< All transactions in mapTx, in random order
371+
std::vector<std::pair<Wtxid, txiter>> txns_randomized GUARDED_BY(cs); //!< All transactions in mapTx with their wtxids, in arbitrary order
372372

373373
typedef std::set<txiter, CompareIteratorByHash> setEntries;
374374

0 commit comments

Comments
 (0)