diff --git a/src/miner.h b/src/miner.h --- a/src/miner.h +++ b/src/miner.h @@ -186,6 +186,8 @@ /** Generate a new block, without valid proof-of-work */ class BlockAssembler { private: + typedef std::unordered_set TxIdSet; + // The constructed block template std::unique_ptr pblocktemplate; // A convenience pointer that always refers to the CBlock in pblocktemplate @@ -200,7 +202,7 @@ uint64_t nBlockTx; uint64_t nBlockSigOps; Amount nFees; - CTxMemPool::setEntries inBlock; + TxIdSet inBlock; // Chain context for the block int nHeight; @@ -263,7 +265,7 @@ * or if the transaction's cached data in mapTx is incorrect. */ bool SkipMapTxEntry(CTxMemPool::txiter it, indexed_modified_transaction_set &mapModifiedTx, - CTxMemPool::setEntries &failedTx); + const TxIdSet &failedTx); /** Sort the package in an order that is valid to appear in a block */ void SortForBlock(const CTxMemPool::setEntries &package, CTxMemPool::txiter entry, @@ -273,6 +275,8 @@ * of updated descendants. */ int UpdatePackagesForAdded(const CTxMemPool::setEntries &alreadyAdded, indexed_modified_transaction_set &mapModifiedTx); + int UpdatePackagesForAdded(const TxIdSet &alreadyAdded, + indexed_modified_transaction_set &mapModifiedTx); }; /** Modify the extranonce in a block */ diff --git a/src/miner.cpp b/src/miner.cpp --- a/src/miner.cpp +++ b/src/miner.cpp @@ -253,7 +253,7 @@ bool BlockAssembler::isStillDependent(CTxMemPool::txiter iter) { for (CTxMemPool::txiter parent : mempool->GetMemPoolParents(iter)) { - if (!inBlock.count(parent)) { + if (!inBlock.count(parent->GetTx().GetId())) { return true; } } @@ -264,7 +264,7 @@ for (CTxMemPool::setEntries::iterator iit = testSet.begin(); iit != testSet.end();) { // Only test txs not already in the block. - if (inBlock.count(*iit)) { + if (inBlock.count((*iit)->GetTx().GetId())) { testSet.erase(iit++); } else { iit++; @@ -365,7 +365,7 @@ ++nBlockTx; nBlockSigOps += iter->GetSigOpCount(); nFees += iter->GetFee(); - inBlock.insert(iter); + inBlock.insert(iter->GetTx().GetId()); bool fPrintPriority = gArgs.GetBoolArg("-printpriority", DEFAULT_PRINTPRIORITY); @@ -380,6 +380,17 @@ } } +// TODO: Temporary adapter, delete this eventually. +int BlockAssembler::UpdatePackagesForAdded( + const TxIdSet &alreadyAdded, + indexed_modified_transaction_set &mapModifiedTx) { + CTxMemPool::setEntries entries; + for (const TxId &id : alreadyAdded) { + entries.insert(mempool->mapTx.find(id)); + } + return UpdatePackagesForAdded(entries, mapModifiedTx); +} + int BlockAssembler::UpdatePackagesForAdded( const CTxMemPool::setEntries &alreadyAdded, indexed_modified_transaction_set &mapModifiedTx) { @@ -421,9 +432,11 @@ // be using cached size/sigops/fee values that are not actually correct. bool BlockAssembler::SkipMapTxEntry( CTxMemPool::txiter it, indexed_modified_transaction_set &mapModifiedTx, - CTxMemPool::setEntries &failedTx) { + const TxIdSet &failedTx) { assert(it != mempool->mapTx.end()); - return mapModifiedTx.count(it) || inBlock.count(it) || failedTx.count(it); + const TxId &txId = it->GetTx().GetId(); + return mapModifiedTx.count(it) || inBlock.count(txId) || + failedTx.count(txId); } void BlockAssembler::SortForBlock( @@ -463,7 +476,7 @@ // some of their txs are already in the block. indexed_modified_transaction_set mapModifiedTx; // Keep track of entries that failed inclusion, to avoid duplicate work. - CTxMemPool::setEntries failedTx; + TxIdSet failedTx; // Start by adding all descendants of previously added txs to mapModifiedTx // and modifying them for their already included ancestors. @@ -516,7 +529,7 @@ // We skip mapTx entries that are inBlock, and mapModifiedTx shouldn't // contain anything that is inBlock. - assert(!inBlock.count(iter)); + assert(!inBlock.count(iter->GetTx().GetId())); uint64_t packageSize = iter->GetSizeWithAncestors(); Amount packageFees = iter->GetModFeesWithAncestors(); @@ -538,7 +551,7 @@ // must erase failed entries so that we can consider the next // best entry on the next loop iteration mapModifiedTx.get().erase(modit); - failedTx.insert(iter); + failedTx.insert(iter->GetTx().GetId()); } ++nConsecutiveFailed; @@ -566,7 +579,7 @@ if (!TestPackageTransactions(ancestors)) { if (fUsingModified) { mapModifiedTx.get().erase(modit); - failedTx.insert(iter); + failedTx.insert(iter->GetTx().GetId()); } continue; } @@ -632,7 +645,7 @@ vecPriority.pop_back(); // If tx already in block, skip. - if (inBlock.count(iter)) { + if (inBlock.count(iter->GetTx().GetId())) { // Shouldn't happen for priority txs. assert(false); continue;