mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-04 13:55:23 -05:00
[refactor] put finality and maturity checking into a lambda
No behavior change.
This commit is contained in:
parent
bedf246f1e
commit
bb9078ed51
1 changed files with 15 additions and 4 deletions
|
@ -638,8 +638,13 @@ void CTxMemPool::removeForReorg(CChainState& active_chainstate, int flags)
|
||||||
{
|
{
|
||||||
// Remove transactions spending a coinbase which are now immature and no-longer-final transactions
|
// Remove transactions spending a coinbase which are now immature and no-longer-final transactions
|
||||||
AssertLockHeld(cs);
|
AssertLockHeld(cs);
|
||||||
setEntries txToRemove;
|
AssertLockHeld(::cs_main);
|
||||||
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
|
|
||||||
|
const auto check_final_and_mature = [this, &active_chainstate, flags](txiter it)
|
||||||
|
EXCLUSIVE_LOCKS_REQUIRED(cs, ::cs_main) {
|
||||||
|
bool should_remove = false;
|
||||||
|
AssertLockHeld(cs);
|
||||||
|
AssertLockHeld(::cs_main);
|
||||||
const CTransaction& tx = it->GetTx();
|
const CTransaction& tx = it->GetTx();
|
||||||
LockPoints lp = it->GetLockPoints();
|
LockPoints lp = it->GetLockPoints();
|
||||||
const bool validLP = TestLockPointValidity(active_chainstate.m_chain, &lp);
|
const bool validLP = TestLockPointValidity(active_chainstate.m_chain, &lp);
|
||||||
|
@ -648,7 +653,7 @@ void CTxMemPool::removeForReorg(CChainState& active_chainstate, int flags)
|
||||||
|| !CheckSequenceLocks(active_chainstate.m_chain.Tip(), view_mempool, tx, flags, &lp, validLP)) {
|
|| !CheckSequenceLocks(active_chainstate.m_chain.Tip(), view_mempool, tx, flags, &lp, validLP)) {
|
||||||
// Note if CheckSequenceLocks fails the LockPoints may still be invalid
|
// Note if CheckSequenceLocks fails the LockPoints may still be invalid
|
||||||
// So it's critical that we remove the tx and not depend on the LockPoints.
|
// So it's critical that we remove the tx and not depend on the LockPoints.
|
||||||
txToRemove.insert(it);
|
should_remove = true;
|
||||||
} else if (it->GetSpendsCoinbase()) {
|
} else if (it->GetSpendsCoinbase()) {
|
||||||
for (const CTxIn& txin : tx.vin) {
|
for (const CTxIn& txin : tx.vin) {
|
||||||
indexed_transaction_set::const_iterator it2 = mapTx.find(txin.prevout.hash);
|
indexed_transaction_set::const_iterator it2 = mapTx.find(txin.prevout.hash);
|
||||||
|
@ -658,11 +663,17 @@ void CTxMemPool::removeForReorg(CChainState& active_chainstate, int flags)
|
||||||
if (m_check_ratio != 0) assert(!coin.IsSpent());
|
if (m_check_ratio != 0) assert(!coin.IsSpent());
|
||||||
unsigned int nMemPoolHeight = active_chainstate.m_chain.Tip()->nHeight + 1;
|
unsigned int nMemPoolHeight = active_chainstate.m_chain.Tip()->nHeight + 1;
|
||||||
if (coin.IsSpent() || (coin.IsCoinBase() && ((signed long)nMemPoolHeight) - coin.nHeight < COINBASE_MATURITY)) {
|
if (coin.IsSpent() || (coin.IsCoinBase() && ((signed long)nMemPoolHeight) - coin.nHeight < COINBASE_MATURITY)) {
|
||||||
txToRemove.insert(it);
|
should_remove = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return should_remove;
|
||||||
|
};
|
||||||
|
|
||||||
|
setEntries txToRemove;
|
||||||
|
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
|
||||||
|
if (check_final_and_mature(it)) txToRemove.insert(it);
|
||||||
}
|
}
|
||||||
setEntries setAllRemoves;
|
setEntries setAllRemoves;
|
||||||
for (txiter it : txToRemove) {
|
for (txiter it : txToRemove) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue