|
|
@ -147,11 +147,11 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashes |
|
|
|
if (it == mapTx.end()) { |
|
|
|
if (it == mapTx.end()) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
std::map<COutPoint, CInPoint>::iterator iter = mapNextTx.lower_bound(COutPoint(hash, 0)); |
|
|
|
auto iter = mapNextTx.lower_bound(COutPoint(hash, 0)); |
|
|
|
// First calculate the children, and update setMemPoolChildren to
|
|
|
|
// First calculate the children, and update setMemPoolChildren to
|
|
|
|
// include them, and update their setMemPoolParents to include this tx.
|
|
|
|
// include them, and update their setMemPoolParents to include this tx.
|
|
|
|
for (; iter != mapNextTx.end() && iter->first.hash == hash; ++iter) { |
|
|
|
for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) { |
|
|
|
const uint256 &childHash = iter->second.ptx->GetHash(); |
|
|
|
const uint256 &childHash = iter->second->GetHash(); |
|
|
|
txiter childIter = mapTx.find(childHash); |
|
|
|
txiter childIter = mapTx.find(childHash); |
|
|
|
assert(childIter != mapTx.end()); |
|
|
|
assert(childIter != mapTx.end()); |
|
|
|
// We can skip updating entries we've encountered before or that
|
|
|
|
// We can skip updating entries we've encountered before or that
|
|
|
@ -365,11 +365,11 @@ void CTxMemPool::pruneSpent(const uint256 &hashTx, CCoins &coins) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs); |
|
|
|
LOCK(cs); |
|
|
|
|
|
|
|
|
|
|
|
std::map<COutPoint, CInPoint>::iterator it = mapNextTx.lower_bound(COutPoint(hashTx, 0)); |
|
|
|
auto it = mapNextTx.lower_bound(COutPoint(hashTx, 0)); |
|
|
|
|
|
|
|
|
|
|
|
// iterate over all COutPoints in mapNextTx whose hash equals the provided hashTx
|
|
|
|
// iterate over all COutPoints in mapNextTx whose hash equals the provided hashTx
|
|
|
|
while (it != mapNextTx.end() && it->first.hash == hashTx) { |
|
|
|
while (it != mapNextTx.end() && it->first->hash == hashTx) { |
|
|
|
coins.Spend(it->first.n); // and remove those outputs from coins
|
|
|
|
coins.Spend(it->first->n); // and remove those outputs from coins
|
|
|
|
it++; |
|
|
|
it++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -414,7 +414,7 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, |
|
|
|
const CTransaction& tx = newit->GetTx(); |
|
|
|
const CTransaction& tx = newit->GetTx(); |
|
|
|
std::set<uint256> setParentTransactions; |
|
|
|
std::set<uint256> setParentTransactions; |
|
|
|
for (unsigned int i = 0; i < tx.vin.size(); i++) { |
|
|
|
for (unsigned int i = 0; i < tx.vin.size(); i++) { |
|
|
|
mapNextTx[tx.vin[i].prevout] = CInPoint(&tx, i); |
|
|
|
mapNextTx.insert(std::make_pair(&tx.vin[i].prevout, &tx)); |
|
|
|
setParentTransactions.insert(tx.vin[i].prevout.hash); |
|
|
|
setParentTransactions.insert(tx.vin[i].prevout.hash); |
|
|
|
} |
|
|
|
} |
|
|
|
// Don't bother worrying about child transactions of this one.
|
|
|
|
// Don't bother worrying about child transactions of this one.
|
|
|
@ -500,10 +500,10 @@ void CTxMemPool::removeRecursive(const CTransaction &origTx, std::list<CTransact |
|
|
|
// happen during chain re-orgs if origTx isn't re-accepted into
|
|
|
|
// happen during chain re-orgs if origTx isn't re-accepted into
|
|
|
|
// the mempool for any reason.
|
|
|
|
// the mempool for any reason.
|
|
|
|
for (unsigned int i = 0; i < origTx.vout.size(); i++) { |
|
|
|
for (unsigned int i = 0; i < origTx.vout.size(); i++) { |
|
|
|
std::map<COutPoint, CInPoint>::iterator it = mapNextTx.find(COutPoint(origTx.GetHash(), i)); |
|
|
|
auto it = mapNextTx.find(COutPoint(origTx.GetHash(), i)); |
|
|
|
if (it == mapNextTx.end()) |
|
|
|
if (it == mapNextTx.end()) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
txiter nextit = mapTx.find(it->second.ptx->GetHash()); |
|
|
|
txiter nextit = mapTx.find(it->second->GetHash()); |
|
|
|
assert(nextit != mapTx.end()); |
|
|
|
assert(nextit != mapTx.end()); |
|
|
|
txToRemove.insert(nextit); |
|
|
|
txToRemove.insert(nextit); |
|
|
|
} |
|
|
|
} |
|
|
@ -561,9 +561,9 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction> |
|
|
|
list<CTransaction> result; |
|
|
|
list<CTransaction> result; |
|
|
|
LOCK(cs); |
|
|
|
LOCK(cs); |
|
|
|
BOOST_FOREACH(const CTxIn &txin, tx.vin) { |
|
|
|
BOOST_FOREACH(const CTxIn &txin, tx.vin) { |
|
|
|
std::map<COutPoint, CInPoint>::iterator it = mapNextTx.find(txin.prevout); |
|
|
|
auto it = mapNextTx.find(txin.prevout); |
|
|
|
if (it != mapNextTx.end()) { |
|
|
|
if (it != mapNextTx.end()) { |
|
|
|
const CTransaction &txConflict = *it->second.ptx; |
|
|
|
const CTransaction &txConflict = *it->second; |
|
|
|
if (txConflict != tx) |
|
|
|
if (txConflict != tx) |
|
|
|
{ |
|
|
|
{ |
|
|
|
removeRecursive(txConflict, removed); |
|
|
|
removeRecursive(txConflict, removed); |
|
|
@ -671,10 +671,10 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const |
|
|
|
assert(coins && coins->IsAvailable(txin.prevout.n)); |
|
|
|
assert(coins && coins->IsAvailable(txin.prevout.n)); |
|
|
|
} |
|
|
|
} |
|
|
|
// Check whether its inputs are marked in mapNextTx.
|
|
|
|
// Check whether its inputs are marked in mapNextTx.
|
|
|
|
std::map<COutPoint, CInPoint>::const_iterator it3 = mapNextTx.find(txin.prevout); |
|
|
|
auto it3 = mapNextTx.find(txin.prevout); |
|
|
|
assert(it3 != mapNextTx.end()); |
|
|
|
assert(it3 != mapNextTx.end()); |
|
|
|
assert(it3->second.ptx == &tx); |
|
|
|
assert(it3->first == &txin.prevout); |
|
|
|
assert(it3->second.n == i); |
|
|
|
assert(it3->second == &tx); |
|
|
|
i++; |
|
|
|
i++; |
|
|
|
} |
|
|
|
} |
|
|
|
assert(setParentCheck == GetMemPoolParents(it)); |
|
|
|
assert(setParentCheck == GetMemPoolParents(it)); |
|
|
@ -701,10 +701,10 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const |
|
|
|
|
|
|
|
|
|
|
|
// Check children against mapNextTx
|
|
|
|
// Check children against mapNextTx
|
|
|
|
CTxMemPool::setEntries setChildrenCheck; |
|
|
|
CTxMemPool::setEntries setChildrenCheck; |
|
|
|
std::map<COutPoint, CInPoint>::const_iterator iter = mapNextTx.lower_bound(COutPoint(it->GetTx().GetHash(), 0)); |
|
|
|
auto iter = mapNextTx.lower_bound(COutPoint(it->GetTx().GetHash(), 0)); |
|
|
|
int64_t childSizes = 0; |
|
|
|
int64_t childSizes = 0; |
|
|
|
for (; iter != mapNextTx.end() && iter->first.hash == it->GetTx().GetHash(); ++iter) { |
|
|
|
for (; iter != mapNextTx.end() && iter->first->hash == it->GetTx().GetHash(); ++iter) { |
|
|
|
txiter childit = mapTx.find(iter->second.ptx->GetHash()); |
|
|
|
txiter childit = mapTx.find(iter->second->GetHash()); |
|
|
|
assert(childit != mapTx.end()); // mapNextTx points to in-mempool transactions
|
|
|
|
assert(childit != mapTx.end()); // mapNextTx points to in-mempool transactions
|
|
|
|
if (setChildrenCheck.insert(childit).second) { |
|
|
|
if (setChildrenCheck.insert(childit).second) { |
|
|
|
childSizes += childit->GetTxSize(); |
|
|
|
childSizes += childit->GetTxSize(); |
|
|
@ -738,14 +738,12 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const |
|
|
|
stepsSinceLastRemove = 0; |
|
|
|
stepsSinceLastRemove = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
for (std::map<COutPoint, CInPoint>::const_iterator it = mapNextTx.begin(); it != mapNextTx.end(); it++) { |
|
|
|
for (auto it = mapNextTx.cbegin(); it != mapNextTx.cend(); it++) { |
|
|
|
uint256 hash = it->second.ptx->GetHash(); |
|
|
|
uint256 hash = it->second->GetHash(); |
|
|
|
indexed_transaction_set::const_iterator it2 = mapTx.find(hash); |
|
|
|
indexed_transaction_set::const_iterator it2 = mapTx.find(hash); |
|
|
|
const CTransaction& tx = it2->GetTx(); |
|
|
|
const CTransaction& tx = it2->GetTx(); |
|
|
|
assert(it2 != mapTx.end()); |
|
|
|
assert(it2 != mapTx.end()); |
|
|
|
assert(&tx == it->second.ptx); |
|
|
|
assert(&tx == it->second); |
|
|
|
assert(tx.vin.size() > it->second.n); |
|
|
|
|
|
|
|
assert(it->first == it->second.ptx->vin[it->second.n].prevout); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assert(totalTxSize == checkTotal); |
|
|
|
assert(totalTxSize == checkTotal); |
|
|
@ -1079,8 +1077,8 @@ void CTxMemPool::TrimToSize(size_t sizelimit, std::vector<uint256>* pvNoSpendsRe |
|
|
|
BOOST_FOREACH(const CTxIn& txin, tx.vin) { |
|
|
|
BOOST_FOREACH(const CTxIn& txin, tx.vin) { |
|
|
|
if (exists(txin.prevout.hash)) |
|
|
|
if (exists(txin.prevout.hash)) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
std::map<COutPoint, CInPoint>::iterator it = mapNextTx.lower_bound(COutPoint(txin.prevout.hash, 0)); |
|
|
|
auto it = mapNextTx.lower_bound(COutPoint(txin.prevout.hash, 0)); |
|
|
|
if (it == mapNextTx.end() || it->first.hash != txin.prevout.hash) |
|
|
|
if (it == mapNextTx.end() || it->first->hash != txin.prevout.hash) |
|
|
|
pvNoSpendsRemaining->push_back(txin.prevout.hash); |
|
|
|
pvNoSpendsRemaining->push_back(txin.prevout.hash); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|