Skip to content

Commit d0cd2e8

Browse files
glozowTheCharlatan
authored andcommitted
[refactor] rewrite BlockAssembler inBlock and failedTx as sets of txids
1 parent 55b0939 commit d0cd2e8

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/node/miner.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
188188
{
189189
for (CTxMemPool::setEntries::iterator iit = testSet.begin(); iit != testSet.end(); ) {
190190
// Only test txs not already in the block
191-
if (inBlock.count(*iit)) {
191+
if (inBlock.count((*iit)->GetSharedTx()->GetHash())) {
192192
testSet.erase(iit++);
193193
} else {
194194
iit++;
@@ -229,7 +229,7 @@ void BlockAssembler::AddToBlock(CTxMemPool::txiter iter)
229229
++nBlockTx;
230230
nBlockSigOpsCost += iter->GetSigOpCost();
231231
nFees += iter->GetFee();
232-
inBlock.insert(iter);
232+
inBlock.insert(iter->GetSharedTx()->GetHash());
233233

234234
bool fPrintPriority = gArgs.GetBoolArg("-printpriority", DEFAULT_PRINTPRIORITY);
235235
if (fPrintPriority) {
@@ -298,7 +298,7 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele
298298
// because some of their txs are already in the block
299299
indexed_modified_transaction_set mapModifiedTx;
300300
// Keep track of entries that failed inclusion, to avoid duplicate work
301-
CTxMemPool::setEntries failedTx;
301+
std::set<Txid> failedTx;
302302

303303
CTxMemPool::indexed_transaction_set::index<ancestor_score>::type::iterator mi = mempool.mapTx.get<ancestor_score>().begin();
304304
CTxMemPool::txiter iter;
@@ -326,7 +326,7 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele
326326
if (mi != mempool.mapTx.get<ancestor_score>().end()) {
327327
auto it = mempool.mapTx.project<0>(mi);
328328
assert(it != mempool.mapTx.end());
329-
if (mapModifiedTx.count(it) || inBlock.count(it) || failedTx.count(it)) {
329+
if (mapModifiedTx.count(it) || inBlock.count(it->GetSharedTx()->GetHash()) || failedTx.count(it->GetSharedTx()->GetHash())) {
330330
++mi;
331331
continue;
332332
}
@@ -360,7 +360,7 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele
360360

361361
// We skip mapTx entries that are inBlock, and mapModifiedTx shouldn't
362362
// contain anything that is inBlock.
363-
assert(!inBlock.count(iter));
363+
assert(!inBlock.count(iter->GetSharedTx()->GetHash()));
364364

365365
uint64_t packageSize = iter->GetSizeWithAncestors();
366366
CAmount packageFees = iter->GetModFeesWithAncestors();
@@ -382,7 +382,7 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele
382382
// we must erase failed entries so that we can consider the
383383
// next best entry on the next loop iteration
384384
mapModifiedTx.get<ancestor_score>().erase(modit);
385-
failedTx.insert(iter);
385+
failedTx.insert(iter->GetSharedTx()->GetHash());
386386
}
387387

388388
++nConsecutiveFailed;
@@ -404,7 +404,7 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele
404404
if (!TestPackageTransactions(ancestors)) {
405405
if (fUsingModified) {
406406
mapModifiedTx.get<ancestor_score>().erase(modit);
407-
failedTx.insert(iter);
407+
failedTx.insert(iter->GetSharedTx()->GetHash());
408408
}
409409
continue;
410410
}

src/node/miner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class BlockAssembler
142142
uint64_t nBlockTx;
143143
uint64_t nBlockSigOpsCost;
144144
CAmount nFees;
145-
CTxMemPool::setEntries inBlock;
145+
std::unordered_set<Txid, SaltedTxidHasher> inBlock;
146146

147147
// Chain context for the block
148148
int nHeight;

0 commit comments

Comments
 (0)