|
6 | 6 | #include "txmempool.h"
|
7 | 7 |
|
8 | 8 | #include "clientversion.h"
|
| 9 | +#include "main.h" // for COINBASE_MATURITY |
9 | 10 | #include "streams.h"
|
10 | 11 | #include "util.h"
|
11 | 12 | #include "utilmoneystr.h"
|
@@ -453,6 +454,31 @@ void CTxMemPool::remove(const CTransaction &tx, std::list<CTransaction>& removed
|
453 | 454 | }
|
454 | 455 | }
|
455 | 456 |
|
| 457 | +void CTxMemPool::removeCoinbaseSpends(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight) |
| 458 | +{ |
| 459 | + // Remove transactions spending a coinbase which are now immature |
| 460 | + LOCK(cs); |
| 461 | + list<CTransaction> transactionsToRemove; |
| 462 | + for (std::map<uint256, CTxMemPoolEntry>::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) { |
| 463 | + const CTransaction& tx = it->second.GetTx(); |
| 464 | + BOOST_FOREACH(const CTxIn& txin, tx.vin) { |
| 465 | + std::map<uint256, CTxMemPoolEntry>::const_iterator it2 = mapTx.find(txin.prevout.hash); |
| 466 | + if (it2 != mapTx.end()) |
| 467 | + continue; |
| 468 | + const CCoins *coins = pcoins->AccessCoins(txin.prevout.hash); |
| 469 | + if (fSanityCheck) assert(coins); |
| 470 | + if (!coins || (coins->IsCoinBase() && nMemPoolHeight - coins->nHeight < COINBASE_MATURITY)) { |
| 471 | + transactionsToRemove.push_back(tx); |
| 472 | + break; |
| 473 | + } |
| 474 | + } |
| 475 | + } |
| 476 | + BOOST_FOREACH(const CTransaction& tx, transactionsToRemove) { |
| 477 | + list<CTransaction> removed; |
| 478 | + remove(tx, removed, true); |
| 479 | + } |
| 480 | +} |
| 481 | + |
456 | 482 | void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>& removed)
|
457 | 483 | {
|
458 | 484 | // Remove transactions which depend on inputs of tx, recursively
|
|
0 commit comments