mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
Revert "[refactor] rewrite vTxHashes as a vector of CTransactionRef"
This reverts commit a03aef9cec.
This commit is contained in:
@@ -114,12 +114,12 @@ ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& c
|
|||||||
std::vector<bool> have_txn(txn_available.size());
|
std::vector<bool> have_txn(txn_available.size());
|
||||||
{
|
{
|
||||||
LOCK(pool->cs);
|
LOCK(pool->cs);
|
||||||
for (const auto& tx : pool->txns_randomized) {
|
for (const auto& [wtxid, txit] : pool->txns_randomized) {
|
||||||
uint64_t shortid = cmpctblock.GetShortID(tx->GetWitnessHash());
|
uint64_t shortid = cmpctblock.GetShortID(wtxid);
|
||||||
std::unordered_map<uint64_t, uint16_t>::iterator idit = shorttxids.find(shortid);
|
std::unordered_map<uint64_t, uint16_t>::iterator idit = shorttxids.find(shortid);
|
||||||
if (idit != shorttxids.end()) {
|
if (idit != shorttxids.end()) {
|
||||||
if (!have_txn[idit->second]) {
|
if (!have_txn[idit->second]) {
|
||||||
txn_available[idit->second] = tx;
|
txn_available[idit->second] = txit->GetSharedTx();
|
||||||
have_txn[idit->second] = true;
|
have_txn[idit->second] = true;
|
||||||
mempool_count++;
|
mempool_count++;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -56,8 +56,8 @@ static CBlock BuildBlockTestCase(FastRandomContext& ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Number of shared use_counts we expect for a tx we haven't touched
|
// Number of shared use_counts we expect for a tx we haven't touched
|
||||||
// (block + mempool entry + mempool txns_randomized + our copy from the GetSharedTx call)
|
// (block + mempool entry + our copy from the GetSharedTx call)
|
||||||
constexpr long SHARED_TX_OFFSET{4};
|
constexpr long SHARED_TX_OFFSET{3};
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(SimpleRoundTripTest)
|
BOOST_AUTO_TEST_CASE(SimpleRoundTripTest)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -507,7 +507,7 @@ void CTxMemPool::addNewTransaction(CTxMemPool::txiter newit, CTxMemPool::setEntr
|
|||||||
totalTxSize += entry.GetTxSize();
|
totalTxSize += entry.GetTxSize();
|
||||||
m_total_fee += entry.GetFee();
|
m_total_fee += entry.GetFee();
|
||||||
|
|
||||||
txns_randomized.emplace_back(newit->GetSharedTx());
|
txns_randomized.emplace_back(tx.GetWitnessHash(), newit);
|
||||||
newit->idx_randomized = txns_randomized.size() - 1;
|
newit->idx_randomized = txns_randomized.size() - 1;
|
||||||
|
|
||||||
TRACEPOINT(mempool, added,
|
TRACEPOINT(mempool, added,
|
||||||
@@ -544,15 +544,16 @@ void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason)
|
|||||||
RemoveUnbroadcastTx(it->GetTx().GetHash(), true /* add logging because unchecked */);
|
RemoveUnbroadcastTx(it->GetTx().GetHash(), true /* add logging because unchecked */);
|
||||||
|
|
||||||
if (txns_randomized.size() > 1) {
|
if (txns_randomized.size() > 1) {
|
||||||
// Update idx_randomized of the to-be-moved entry.
|
|
||||||
Assert(GetEntry(txns_randomized.back()->GetHash()))->idx_randomized = it->idx_randomized;
|
|
||||||
// Remove entry from txns_randomized by replacing it with the back and deleting the back.
|
// Remove entry from txns_randomized by replacing it with the back and deleting the back.
|
||||||
txns_randomized[it->idx_randomized] = std::move(txns_randomized.back());
|
txns_randomized[it->idx_randomized] = std::move(txns_randomized.back());
|
||||||
|
txns_randomized[it->idx_randomized].second->idx_randomized = it->idx_randomized;
|
||||||
txns_randomized.pop_back();
|
txns_randomized.pop_back();
|
||||||
if (txns_randomized.size() * 2 < txns_randomized.capacity())
|
if (txns_randomized.size() * 2 < txns_randomized.capacity()) {
|
||||||
txns_randomized.shrink_to_fit();
|
txns_randomized.shrink_to_fit();
|
||||||
} else
|
}
|
||||||
|
} else {
|
||||||
txns_randomized.clear();
|
txns_randomized.clear();
|
||||||
|
}
|
||||||
|
|
||||||
totalTxSize -= it->GetTxSize();
|
totalTxSize -= it->GetTxSize();
|
||||||
m_total_fee -= it->GetFee();
|
m_total_fee -= it->GetFee();
|
||||||
|
|||||||
@@ -368,7 +368,7 @@ public:
|
|||||||
indexed_transaction_set mapTx GUARDED_BY(cs);
|
indexed_transaction_set mapTx GUARDED_BY(cs);
|
||||||
|
|
||||||
using txiter = indexed_transaction_set::nth_index<0>::type::const_iterator;
|
using txiter = indexed_transaction_set::nth_index<0>::type::const_iterator;
|
||||||
std::vector<CTransactionRef> txns_randomized GUARDED_BY(cs); //!< All transactions in mapTx, in random order
|
std::vector<std::pair<Wtxid, txiter>> txns_randomized GUARDED_BY(cs); //!< All transactions in mapTx with their wtxids, in arbitrary order
|
||||||
|
|
||||||
typedef std::set<txiter, CompareIteratorByHash> setEntries;
|
typedef std::set<txiter, CompareIteratorByHash> setEntries;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user