13#include <validation.h>
21 if (
auto it =
txInfo.find(tx->GetId()); it !=
txInfo.end()) {
39 std::vector<CTransactionRef> vtx;
41 vtx.reserve(pool.mapTx.
size());
44 vtx.push_back(e->GetSharedTx());
47 txInfo.try_emplace(e->GetTx().GetId(), e->GetTime(),
48 e->GetModifiedFee() - e->GetFee(), e->GetHeight());
82 const std::vector<CTransactionRef> &vtx,
CTxMemPool &pool) {
86 auto it =
queuedTx.find(tx->GetId());
95 std::unordered_set<TxId, SaltedTxIdHasher> parents;
96 for (
const CTxIn &in : tx->vin) {
97 parents.insert(in.prevout.GetTxId());
103 while (parents.size() > 0) {
104 std::unordered_set<TxId, SaltedTxIdHasher> worklist(
108 for (
const TxId &txid : worklist) {
123 for (
const CTxIn &in : ptx->vin) {
124 parents.insert(in.prevout.GetTxId());
141 const std::vector<CTransactionRef> &vtx,
CTxMemPool &pool) {
144 if (pool.mapTx.empty() && pool.mapDeltas.empty()) {
158 if (it != pool.mapTx.end()) {
188 if (tx->IsCoinBase()) {
193 bool hasFeeDelta =
false;
197 pool.mapDeltas[tx->GetId()] = ptxInfo->feeDelta;
202 active_chainstate, tx,
203 ptxInfo ? ptxInfo->time.count() :
GetTime(),
205 ptxInfo ? ptxInfo->height : 0);
206 if (result.m_result_type !=
210 "AcceptToMemoryPool: tx %s rejected after reorg (%s)\n",
211 tx->GetId().ToString(), result.m_state.ToString());
215 pool.mapDeltas.erase(tx->GetId());
219 "AcceptToMemoryPool: tx %s accepted after reorg\n",
220 tx->GetId().ToString());
void TransactionRemovedFromMempool(const CTransactionRef &, MemPoolRemovalReason, uint64_t mempool_sequence)
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs)
void ClearPrioritisation(const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(cs)
std::set< txiter, CompareIteratorById > setEntries
void updateFeeForBlock() EXCLUSIVE_LOCKS_REQUIRED(cs)
Called when a block is connected.
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
void LimitSize(CCoinsViewCache &coins_cache) EXCLUSIVE_LOCKS_REQUIRED(cs
Reduce the size of the mempool by expiring and then trimming the mempool.
CTransactionRef get(const TxId &txid) const
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
uint64_t GetAndIncrementSequence() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Guards this internal counter for external reporting.
void RemoveStaged(const setEntries &stage, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Remove a set of transactions from the mempool.
unsigned long size() const
Chainstate stores and provides an API to update our local knowledge of the current best chain.
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
void removeEntry(indexed_disconnected_transactions::index< insertion_order >::type::iterator entry)
indexed_disconnected_transactions queuedTx
TxInfoMap txInfo
populated by importMempool(); the original tx entry times and feeDeltas
void removeForBlock(const std::vector< CTransactionRef > &vtx)
uint64_t cachedInnerUsage
size_t DynamicMemoryUsage() const
const TxInfo * getTxInfo(const CTransactionRef &tx) const
void addTransaction(const CTransactionRef &tx)
void updateMempoolForReorg(Chainstate &active_chainstate, bool fAddToMempool, CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main
Make mempool consistent after a reorg, by re-adding or recursively erasing disconnected block transac...
void addForBlock(const std::vector< CTransactionRef > &vtx, CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
void importMempool(CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
static const uint64_t DEFAULT_MAX_BLOCK_SIZE
Default setting for maximum allowed size for a block, in bytes.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
static const size_t MAX_DISCONNECTED_TX_POOL_SIZE
Maximum bytes for transactions to store for processing during reorg.
#define LogPrint(category,...)
std::shared_ptr< const CTransaction > CTransactionRef
reverse_range< T > reverse_iterate(T &x)
static constexpr Amount zero() noexcept
@ VALID
Fully validated, valid.
A TxId is the identifier of a transaction.
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
@ BLOCK
Removed for block.
@ REORG
Removed for reorganization.
MempoolAcceptResult AcceptToMemoryPool(Chainstate &active_chainstate, const CTransactionRef &tx, int64_t accept_time, bool bypass_limits, bool test_accept, unsigned int heightOverride)
Try to add a transaction to the mempool.
CMainSignals & GetMainSignals()