Changeset View
Changeset View
Standalone View
Standalone View
src/txmempool.cpp
| Show First 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | void CTxMemPool::UpdateForRemoveFromMempool(const setEntries &entriesToRemove) { | ||||
| // each transaction being removed and any mempool children (ie, update | // each transaction being removed and any mempool children (ie, update | ||||
| // CTxMemPoolEntry::m_parents for each direct child of a transaction being | // CTxMemPoolEntry::m_parents for each direct child of a transaction being | ||||
| // removed). | // removed). | ||||
| for (txiter removeIt : entriesToRemove) { | for (txiter removeIt : entriesToRemove) { | ||||
| UpdateChildrenForRemoval(removeIt); | UpdateChildrenForRemoval(removeIt); | ||||
| } | } | ||||
| } | } | ||||
| CTxMemPool::CTxMemPool(const Config &config, const Options &opts) | CTxMemPool::CTxMemPool(const Config &config, Options opts) | ||||
| : m_check_ratio(opts.check_ratio), | : m_finalizedTxsFitter(node::BlockFitter(config)), | ||||
| m_finalizedTxsFitter(node::BlockFitter(config)), | |||||
| m_orphanage(std::make_unique<TxOrphanage>()), | m_orphanage(std::make_unique<TxOrphanage>()), | ||||
| m_conflicting(std::make_unique<TxConflicting>()), | m_conflicting(std::make_unique<TxConflicting>()), | ||||
| m_max_size_bytes{opts.max_size_bytes}, m_expiry{opts.expiry}, | m_opts{std::move(opts)} { | ||||
| m_min_relay_feerate{opts.min_relay_feerate}, | |||||
| m_dust_relay_feerate{opts.dust_relay_feerate}, | |||||
| m_permit_bare_multisig{opts.permit_bare_multisig}, | |||||
| m_max_datacarrier_bytes{opts.max_datacarrier_bytes}, | |||||
| m_require_standard{opts.require_standard}, m_signals{opts.signals} { | |||||
| // lock free clear | // lock free clear | ||||
| _clear(); | _clear(); | ||||
| } | } | ||||
| CTxMemPool::~CTxMemPool() {} | CTxMemPool::~CTxMemPool() {} | ||||
| bool CTxMemPool::isSpent(const COutPoint &outpoint) const { | bool CTxMemPool::isSpent(const COutPoint &outpoint) const { | ||||
| LOCK(cs); | LOCK(cs); | ||||
| ▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | |||||
| void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason) { | void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason) { | ||||
| // We increment mempool sequence value no matter removal reason | // We increment mempool sequence value no matter removal reason | ||||
| // even if not directly reported below. | // even if not directly reported below. | ||||
| uint64_t mempool_sequence = GetAndIncrementSequence(); | uint64_t mempool_sequence = GetAndIncrementSequence(); | ||||
| const TxId &txid = (*it)->GetTx().GetId(); | const TxId &txid = (*it)->GetTx().GetId(); | ||||
| if (reason != MemPoolRemovalReason::BLOCK) { | if (reason != MemPoolRemovalReason::BLOCK) { | ||||
| if (m_signals) { | if (m_opts.signals) { | ||||
| // Notify clients that a transaction has been removed from the | // Notify clients that a transaction has been removed from the | ||||
| // mempool for any reason except being included in a block. Clients | // mempool for any reason except being included in a block. Clients | ||||
| // interested in transactions included in blocks can subscribe to | // interested in transactions included in blocks can subscribe to | ||||
| // the BlockConnected notification. | // the BlockConnected notification. | ||||
| m_signals->TransactionRemovedFromMempool((*it)->GetSharedTx(), | m_opts.signals->TransactionRemovedFromMempool( | ||||
| reason, mempool_sequence); | (*it)->GetSharedTx(), reason, mempool_sequence); | ||||
| } | } | ||||
| if (auto removed_tx = finalizedTxs.remove(txid)) { | if (auto removed_tx = finalizedTxs.remove(txid)) { | ||||
| m_finalizedTxsFitter.removeTxUnchecked(removed_tx->GetTxSize(), | m_finalizedTxsFitter.removeTxUnchecked(removed_tx->GetTxSize(), | ||||
| removed_tx->GetSigChecks(), | removed_tx->GetSigChecks(), | ||||
| removed_tx->GetFee()); | removed_tx->GetFee()); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | if (include_finalized_txs) { | ||||
| RadixTree<CTxMemPoolEntry, MemPoolEntryRadixTreeAdapter> empty; | RadixTree<CTxMemPoolEntry, MemPoolEntryRadixTreeAdapter> empty; | ||||
| std::swap(finalizedTxs, empty); | std::swap(finalizedTxs, empty); | ||||
| m_finalizedTxsFitter.resetBlock(); | m_finalizedTxsFitter.resetBlock(); | ||||
| } | } | ||||
| } | } | ||||
| void CTxMemPool::check(const CCoinsViewCache &active_coins_tip, | void CTxMemPool::check(const CCoinsViewCache &active_coins_tip, | ||||
| int64_t spendheight) const { | int64_t spendheight) const { | ||||
| if (m_check_ratio == 0) { | if (m_opts.check_ratio == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (FastRandomContext().randrange(m_check_ratio) >= 1) { | if (FastRandomContext().randrange(m_opts.check_ratio) >= 1) { | ||||
| return; | return; | ||||
| } | } | ||||
| AssertLockHeld(::cs_main); | AssertLockHeld(::cs_main); | ||||
| LOCK(cs); | LOCK(cs); | ||||
| LogPrint(BCLog::MEMPOOL, | LogPrint(BCLog::MEMPOOL, | ||||
| "Checking mempool with %u transactions and %u inputs\n", | "Checking mempool with %u transactions and %u inputs\n", | ||||
| (unsigned int)mapTx.size(), (unsigned int)mapNextTx.size()); | (unsigned int)mapTx.size(), (unsigned int)mapNextTx.size()); | ||||
| ▲ Show 20 Lines • Show All 230 Lines • ▼ Show 20 Lines | bool CTxMemPool::setAvalancheFinalized(const CTxMemPoolEntryRef &tx, | ||||
| for (txiter ancestor_it : setAncestors) { | for (txiter ancestor_it : setAncestors) { | ||||
| if (finalizedTxs.insert(*ancestor_it)) { | if (finalizedTxs.insert(*ancestor_it)) { | ||||
| m_finalizedTxsFitter.addTx((*ancestor_it)->GetTxSize(), | m_finalizedTxsFitter.addTx((*ancestor_it)->GetTxSize(), | ||||
| (*ancestor_it)->GetSigChecks(), | (*ancestor_it)->GetSigChecks(), | ||||
| (*ancestor_it)->GetFee()); | (*ancestor_it)->GetFee()); | ||||
| finalizedTxIds.push_back((*ancestor_it)->GetTx().GetId()); | finalizedTxIds.push_back((*ancestor_it)->GetTx().GetId()); | ||||
| if (m_signals) { | if (m_opts.signals) { | ||||
| m_signals->TransactionFinalized((*ancestor_it)->GetSharedTx()); | m_opts.signals->TransactionFinalized( | ||||
| (*ancestor_it)->GetSharedTx()); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| nTransactionsUpdated++; | nTransactionsUpdated++; | ||||
| return true; | return true; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
| CFeeRate CTxMemPool::estimateFee() const { | CFeeRate CTxMemPool::estimateFee() const { | ||||
| LOCK(cs); | LOCK(cs); | ||||
| // minerPolicy uses recent blocks to figure out a reasonable fee. This | // minerPolicy uses recent blocks to figure out a reasonable fee. This | ||||
| // may disagree with the rollingMinimumFeerate under certain scenarios | // may disagree with the rollingMinimumFeerate under certain scenarios | ||||
| // where the mempool increases rapidly, or blocks are being mined which | // where the mempool increases rapidly, or blocks are being mined which | ||||
| // do not contain propagated transactions. | // do not contain propagated transactions. | ||||
| return std::max(m_min_relay_feerate, GetMinFee()); | return std::max(m_opts.min_relay_feerate, GetMinFee()); | ||||
| } | } | ||||
| void CTxMemPool::PrioritiseTransaction(const TxId &txid, | void CTxMemPool::PrioritiseTransaction(const TxId &txid, | ||||
| const Amount nFeeDelta) { | const Amount nFeeDelta) { | ||||
| { | { | ||||
| LOCK(cs); | LOCK(cs); | ||||
| Amount &delta = mapDeltas[txid]; | Amount &delta = mapDeltas[txid]; | ||||
| delta.SaturatingAdd(nFeeDelta); | delta.SaturatingAdd(nFeeDelta); | ||||
| ▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Lines | int CTxMemPool::Expire(std::chrono::seconds time) { | ||||
| RemoveStaged(stage, MemPoolRemovalReason::EXPIRY); | RemoveStaged(stage, MemPoolRemovalReason::EXPIRY); | ||||
| return stage.size(); | return stage.size(); | ||||
| } | } | ||||
| void CTxMemPool::LimitSize(CCoinsViewCache &coins_cache) { | void CTxMemPool::LimitSize(CCoinsViewCache &coins_cache) { | ||||
| AssertLockHeld(::cs_main); | AssertLockHeld(::cs_main); | ||||
| AssertLockHeld(cs); | AssertLockHeld(cs); | ||||
| int expired = Expire(GetTime<std::chrono::seconds>() - m_expiry); | int expired = Expire(GetTime<std::chrono::seconds>() - m_opts.expiry); | ||||
| if (expired != 0) { | if (expired != 0) { | ||||
| LogPrint(BCLog::MEMPOOL, | LogPrint(BCLog::MEMPOOL, | ||||
| "Expired %i transactions from the memory pool\n", expired); | "Expired %i transactions from the memory pool\n", expired); | ||||
| } | } | ||||
| std::vector<COutPoint> vNoSpendsRemaining; | std::vector<COutPoint> vNoSpendsRemaining; | ||||
| TrimToSize(m_max_size_bytes, &vNoSpendsRemaining); | TrimToSize(m_opts.max_size_bytes, &vNoSpendsRemaining); | ||||
| for (const COutPoint &removed : vNoSpendsRemaining) { | for (const COutPoint &removed : vNoSpendsRemaining) { | ||||
| coins_cache.Uncache(removed); | coins_cache.Uncache(removed); | ||||
| } | } | ||||
| } | } | ||||
| void CTxMemPool::UpdateChild(txiter entry, txiter child, bool add) { | void CTxMemPool::UpdateChild(txiter entry, txiter child, bool add) { | ||||
| AssertLockHeld(cs); | AssertLockHeld(cs); | ||||
| CTxMemPoolEntry::Children s; | CTxMemPoolEntry::Children s; | ||||
| ▲ Show 20 Lines • Show All 152 Lines • Show Last 20 Lines | |||||