Bitcoin Core  27.99.0
P2P Digital Currency
disconnected_transactions.h
Go to the documentation of this file.
1 // Copyright (c) 2023 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_KERNEL_DISCONNECTED_TRANSACTIONS_H
6 #define BITCOIN_KERNEL_DISCONNECTED_TRANSACTIONS_H
7 
9 #include <util/hasher.h>
10 
11 #include <list>
12 #include <unordered_map>
13 #include <vector>
14 
16 static const unsigned int MAX_DISCONNECTED_TX_POOL_BYTES{20'000'000};
38 private:
40  uint64_t cachedInnerUsage = 0;
41  const size_t m_max_mem_usage;
42  std::list<CTransactionRef> queuedTx;
43  using TxList = decltype(queuedTx);
44  std::unordered_map<uint256, TxList::iterator, SaltedTxidHasher> iters_by_txid;
45 
47  std::vector<CTransactionRef> LimitMemoryUsage();
48 
49 public:
50  DisconnectedBlockTransactions(size_t max_mem_usage)
51  : m_max_mem_usage{max_mem_usage} {}
52 
54 
55  size_t DynamicMemoryUsage() const;
56 
64  [[nodiscard]] std::vector<CTransactionRef> AddTransactionsFromBlock(const std::vector<CTransactionRef>& vtx);
65 
67  void removeForBlock(const std::vector<CTransactionRef>& vtx);
68 
69  size_t size() const { return queuedTx.size(); }
70 
71  void clear();
72 
74  std::list<CTransactionRef> take();
75 };
76 #endif // BITCOIN_KERNEL_DISCONNECTED_TRANSACTIONS_H
DisconnectedBlockTransactions.
DisconnectedBlockTransactions(size_t max_mem_usage)
std::list< CTransactionRef > take()
Clear all data structures and return the list of transactions.
void removeForBlock(const std::vector< CTransactionRef > &vtx)
Remove any entries that are in this block.
uint64_t cachedInnerUsage
Cached dynamic memory usage for the CTransactionRefs.
std::vector< CTransactionRef > LimitMemoryUsage()
Trim the earliest-added entries until we are within memory bounds.
std::vector< CTransactionRef > AddTransactionsFromBlock(const std::vector< CTransactionRef > &vtx)
Add transactions from the block, iterating through vtx in reverse order.
std::list< CTransactionRef > queuedTx
std::unordered_map< uint256, TxList::iterator, SaltedTxidHasher > iters_by_txid
static const unsigned int MAX_DISCONNECTED_TX_POOL_BYTES
Maximum bytes for transactions to store for processing during reorg.