mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 23:07:59 +01:00
[refactor] rewrite BlockAssembler inBlock and failedTx as sets of txids
This commit is contained in:
parent
55b0939cab
commit
d0cd2e804e
2 changed files with 8 additions and 8 deletions
|
@ -188,7 +188,7 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
|
||||||
{
|
{
|
||||||
for (CTxMemPool::setEntries::iterator iit = testSet.begin(); iit != testSet.end(); ) {
|
for (CTxMemPool::setEntries::iterator iit = testSet.begin(); iit != testSet.end(); ) {
|
||||||
// Only test txs not already in the block
|
// Only test txs not already in the block
|
||||||
if (inBlock.count(*iit)) {
|
if (inBlock.count((*iit)->GetSharedTx()->GetHash())) {
|
||||||
testSet.erase(iit++);
|
testSet.erase(iit++);
|
||||||
} else {
|
} else {
|
||||||
iit++;
|
iit++;
|
||||||
|
@ -229,7 +229,7 @@ void BlockAssembler::AddToBlock(CTxMemPool::txiter iter)
|
||||||
++nBlockTx;
|
++nBlockTx;
|
||||||
nBlockSigOpsCost += iter->GetSigOpCost();
|
nBlockSigOpsCost += iter->GetSigOpCost();
|
||||||
nFees += iter->GetFee();
|
nFees += iter->GetFee();
|
||||||
inBlock.insert(iter);
|
inBlock.insert(iter->GetSharedTx()->GetHash());
|
||||||
|
|
||||||
bool fPrintPriority = gArgs.GetBoolArg("-printpriority", DEFAULT_PRINTPRIORITY);
|
bool fPrintPriority = gArgs.GetBoolArg("-printpriority", DEFAULT_PRINTPRIORITY);
|
||||||
if (fPrintPriority) {
|
if (fPrintPriority) {
|
||||||
|
@ -298,7 +298,7 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele
|
||||||
// because some of their txs are already in the block
|
// because some of their txs are already in the block
|
||||||
indexed_modified_transaction_set mapModifiedTx;
|
indexed_modified_transaction_set mapModifiedTx;
|
||||||
// Keep track of entries that failed inclusion, to avoid duplicate work
|
// Keep track of entries that failed inclusion, to avoid duplicate work
|
||||||
CTxMemPool::setEntries failedTx;
|
std::set<Txid> failedTx;
|
||||||
|
|
||||||
CTxMemPool::indexed_transaction_set::index<ancestor_score>::type::iterator mi = mempool.mapTx.get<ancestor_score>().begin();
|
CTxMemPool::indexed_transaction_set::index<ancestor_score>::type::iterator mi = mempool.mapTx.get<ancestor_score>().begin();
|
||||||
CTxMemPool::txiter iter;
|
CTxMemPool::txiter iter;
|
||||||
|
@ -326,7 +326,7 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele
|
||||||
if (mi != mempool.mapTx.get<ancestor_score>().end()) {
|
if (mi != mempool.mapTx.get<ancestor_score>().end()) {
|
||||||
auto it = mempool.mapTx.project<0>(mi);
|
auto it = mempool.mapTx.project<0>(mi);
|
||||||
assert(it != mempool.mapTx.end());
|
assert(it != mempool.mapTx.end());
|
||||||
if (mapModifiedTx.count(it) || inBlock.count(it) || failedTx.count(it)) {
|
if (mapModifiedTx.count(it) || inBlock.count(it->GetSharedTx()->GetHash()) || failedTx.count(it->GetSharedTx()->GetHash())) {
|
||||||
++mi;
|
++mi;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -360,7 +360,7 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele
|
||||||
|
|
||||||
// We skip mapTx entries that are inBlock, and mapModifiedTx shouldn't
|
// We skip mapTx entries that are inBlock, and mapModifiedTx shouldn't
|
||||||
// contain anything that is inBlock.
|
// contain anything that is inBlock.
|
||||||
assert(!inBlock.count(iter));
|
assert(!inBlock.count(iter->GetSharedTx()->GetHash()));
|
||||||
|
|
||||||
uint64_t packageSize = iter->GetSizeWithAncestors();
|
uint64_t packageSize = iter->GetSizeWithAncestors();
|
||||||
CAmount packageFees = iter->GetModFeesWithAncestors();
|
CAmount packageFees = iter->GetModFeesWithAncestors();
|
||||||
|
@ -382,7 +382,7 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele
|
||||||
// we must erase failed entries so that we can consider the
|
// we must erase failed entries so that we can consider the
|
||||||
// next best entry on the next loop iteration
|
// next best entry on the next loop iteration
|
||||||
mapModifiedTx.get<ancestor_score>().erase(modit);
|
mapModifiedTx.get<ancestor_score>().erase(modit);
|
||||||
failedTx.insert(iter);
|
failedTx.insert(iter->GetSharedTx()->GetHash());
|
||||||
}
|
}
|
||||||
|
|
||||||
++nConsecutiveFailed;
|
++nConsecutiveFailed;
|
||||||
|
@ -404,7 +404,7 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele
|
||||||
if (!TestPackageTransactions(ancestors)) {
|
if (!TestPackageTransactions(ancestors)) {
|
||||||
if (fUsingModified) {
|
if (fUsingModified) {
|
||||||
mapModifiedTx.get<ancestor_score>().erase(modit);
|
mapModifiedTx.get<ancestor_score>().erase(modit);
|
||||||
failedTx.insert(iter);
|
failedTx.insert(iter->GetSharedTx()->GetHash());
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ private:
|
||||||
uint64_t nBlockTx;
|
uint64_t nBlockTx;
|
||||||
uint64_t nBlockSigOpsCost;
|
uint64_t nBlockSigOpsCost;
|
||||||
CAmount nFees;
|
CAmount nFees;
|
||||||
CTxMemPool::setEntries inBlock;
|
std::unordered_set<Txid, SaltedTxidHasher> inBlock;
|
||||||
|
|
||||||
// Chain context for the block
|
// Chain context for the block
|
||||||
int nHeight;
|
int nHeight;
|
||||||
|
|
Loading…
Add table
Reference in a new issue