Bitcoin Core 28.99.0
P2P Digital Currency
txdownloadman_impl.h
Go to the documentation of this file.
1// Copyright (c) 2024
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4#ifndef BITCOIN_NODE_TXDOWNLOADMAN_IMPL_H
5#define BITCOIN_NODE_TXDOWNLOADMAN_IMPL_H
6
8
9#include <common/bloom.h>
11#include <kernel/chain.h>
12#include <net.h>
14#include <policy/packages.h>
15#include <txorphanage.h>
16#include <txrequest.h>
17
18class CTxMemPool;
19namespace node {
21public:
23
28
63 std::unique_ptr<CRollingBloomFilter> m_lazy_recent_rejects{nullptr};
64
66 {
68 m_lazy_recent_rejects = std::make_unique<CRollingBloomFilter>(120'000, 0.000'001);
69 }
70
72 }
73
94 std::unique_ptr<CRollingBloomFilter> m_lazy_recent_rejects_reconsiderable{nullptr};
95
97 {
99 m_lazy_recent_rejects_reconsiderable = std::make_unique<CRollingBloomFilter>(120'000, 0.000'001);
100 }
101
103 }
104
105 /*
106 * Filter for transactions that have been recently confirmed.
107 * We use this to avoid requesting transactions that have already been
108 * confirmed.
109 *
110 * Blocks don't typically have more than 4000 transactions, so this should
111 * be at least six blocks (~1 hr) worth of transactions that we can store,
112 * inserting both a txid and wtxid for every observed transaction.
113 * If the number of transactions appearing in a block goes up, or if we are
114 * seeing getdata requests more than an hour after initial announcement, we
115 * can increase this number.
116 * The false positive rate of 1/1M should come out to less than 1
117 * transaction per day that would be inadvertently ignored (which is the
118 * same probability that we have in the reject filter).
119 */
120 std::unique_ptr<CRollingBloomFilter> m_lazy_recent_confirmed_transactions{nullptr};
121
123 {
125 m_lazy_recent_confirmed_transactions = std::make_unique<CRollingBloomFilter>(48'000, 0.000'001);
126 }
127
129 }
130
131 TxDownloadManagerImpl(const TxDownloadOptions& options) : m_opts{options}, m_txrequest{options.m_deterministic_txrequest} {}
132
133 struct PeerInfo {
136
138 };
139
142 std::map<NodeId, PeerInfo> m_peer_info;
143
145 uint32_t m_num_wtxid_peers{0};
146
147 void ActiveTipChange();
148 void BlockConnected(const std::shared_ptr<const CBlock>& pblock);
149 void BlockDisconnected();
150
158 bool AlreadyHaveTx(const GenTxid& gtxid, bool include_reconsiderable);
159
160 void ConnectedPeer(NodeId nodeid, const TxDownloadConnectionInfo& info);
161 void DisconnectedPeer(NodeId nodeid);
162
166 bool AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now, bool p2p_inv);
167
169 std::vector<GenTxid> GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time);
170
172 void ReceivedNotFound(NodeId nodeid, const std::vector<uint256>& txhashes);
173
177 std::optional<PackageToValidate> Find1P1CPackage(const CTransactionRef& ptx, NodeId nodeid);
178
179 void MempoolAcceptedTx(const CTransactionRef& tx);
180 RejectedTxTodo MempoolRejectedTx(const CTransactionRef& ptx, const TxValidationState& state, NodeId nodeid, bool first_time_failure);
181 void MempoolRejectedPackage(const Package& package);
182
183 std::pair<bool, std::optional<PackageToValidate>> ReceivedTx(NodeId nodeid, const CTransactionRef& ptx);
184
185 bool HaveMoreWork(NodeId nodeid);
187
188 void CheckIsEmpty();
189 void CheckIsEmpty(NodeId nodeid);
190
191 std::vector<TxOrphanage::OrphanTxBase> GetOrphanTransactions() const;
192};
193} // namespace node
194#endif // BITCOIN_NODE_TXDOWNLOADMAN_IMPL_H
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set.
Definition: bloom.h:109
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:304
A generic txid reference (txid or wtxid).
Definition: transaction.h:428
A class to track orphan transactions (failed on TX_MISSING_INPUTS) Since we cannot distinguish orphan...
Definition: txorphanage.h:28
Data structure to keep track of, and schedule, transaction downloads from peers.
Definition: txrequest.h:96
std::unique_ptr< CRollingBloomFilter > m_lazy_recent_confirmed_transactions
std::optional< PackageToValidate > Find1P1CPackage(const CTransactionRef &ptx, NodeId nodeid)
Look for a child of this transaction in the orphanage to form a 1-parent-1-child package,...
CRollingBloomFilter & RecentConfirmedTransactionsFilter()
bool AddTxAnnouncement(NodeId peer, const GenTxid &gtxid, std::chrono::microseconds now, bool p2p_inv)
Consider adding this tx hash to txrequest.
std::unique_ptr< CRollingBloomFilter > m_lazy_recent_rejects
Filter for transactions that were recently rejected by the mempool.
void ReceivedNotFound(NodeId nodeid, const std::vector< uint256 > &txhashes)
Marks a tx as ReceivedResponse in txrequest.
void DisconnectedPeer(NodeId nodeid)
std::unique_ptr< CRollingBloomFilter > m_lazy_recent_rejects_reconsiderable
Filter for: (1) wtxids of transactions that were recently rejected by the mempool but are eligible fo...
TxRequestTracker m_txrequest
Tracks candidates for requesting and downloading transaction data.
std::pair< bool, std::optional< PackageToValidate > > ReceivedTx(NodeId nodeid, const CTransactionRef &ptx)
void MempoolAcceptedTx(const CTransactionRef &tx)
CRollingBloomFilter & RecentRejectsReconsiderableFilter()
RejectedTxTodo MempoolRejectedTx(const CTransactionRef &ptx, const TxValidationState &state, NodeId nodeid, bool first_time_failure)
std::vector< TxOrphanage::OrphanTxBase > GetOrphanTransactions() const
uint32_t m_num_wtxid_peers
Number of wtxid relay peers we have in m_peer_info.
void ConnectedPeer(NodeId nodeid, const TxDownloadConnectionInfo &info)
bool AlreadyHaveTx(const GenTxid &gtxid, bool include_reconsiderable)
Check whether we already have this gtxid in:
std::map< NodeId, PeerInfo > m_peer_info
Information for all of the peers we may download transactions from.
TxOrphanage m_orphanage
Manages unvalidated tx data (orphan transactions for which we are downloading ancestors).
TxDownloadManagerImpl(const TxDownloadOptions &options)
std::vector< GenTxid > GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time)
Get getdata requests to send.
void BlockConnected(const std::shared_ptr< const CBlock > &pblock)
CTransactionRef GetTxToReconsider(NodeId nodeid)
CRollingBloomFilter & RecentRejectsFilter()
void MempoolRejectedPackage(const Package &package)
Definition: messages.h:20
int64_t NodeId
Definition: net.h:97
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
Definition: packages.h:50
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:423
PeerInfo(const TxDownloadConnectionInfo &info)
const TxDownloadConnectionInfo m_connection_info
Information relevant to scheduling tx requests.