Bitcoin Core 30.99.0
P2P Digital Currency
disconnected_transactions.h
Go to the documentation of this file.
1// Copyright (c) 2023-present 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 <cstddef>
12#include <cstdint>
13#include <list>
14#include <unordered_map>
15#include <vector>
16
18static const unsigned int MAX_DISCONNECTED_TX_POOL_BYTES{20'000'000};
40private:
42 uint64_t cachedInnerUsage = 0;
43 const size_t m_max_mem_usage;
44 std::list<CTransactionRef> queuedTx;
45 using TxList = decltype(queuedTx);
46 std::unordered_map<Txid, TxList::iterator, SaltedTxidHasher> iters_by_txid;
47
49 std::vector<CTransactionRef> LimitMemoryUsage();
50
51public:
52 DisconnectedBlockTransactions(size_t max_mem_usage)
53 : m_max_mem_usage{max_mem_usage} {}
54
56
57 size_t DynamicMemoryUsage() const;
58
66 [[nodiscard]] std::vector<CTransactionRef> AddTransactionsFromBlock(const std::vector<CTransactionRef>& vtx);
67
69 void removeForBlock(const std::vector<CTransactionRef>& vtx);
70
71 size_t size() const { return queuedTx.size(); }
72
73 void clear();
74
76 std::list<CTransactionRef> take();
77};
78#endif // BITCOIN_KERNEL_DISCONNECTED_TRANSACTIONS_H
DisconnectedBlockTransactions.
DisconnectedBlockTransactions(size_t max_mem_usage)
std::unordered_map< Txid, TxList::iterator, SaltedTxidHasher > iters_by_txid
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
static const unsigned int MAX_DISCONNECTED_TX_POOL_BYTES
Maximum bytes for transactions to store for processing during reorg.