Bitcoin ABC 0.34.5
P2P Digital Currency
Loading...
Searching...
No Matches
txdownloadman.h
Go to the documentation of this file.
1// Copyright (c) 2024 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_NODE_TXDOWNLOADMAN_H
6#define BITCOIN_NODE_TXDOWNLOADMAN_H
7
8#include <invrequest.h>
9#include <net.h>
10#include <net_permissions.h>
11#include <policy/packages.h>
12#include <txorphanage.h>
13#include <util/check.h>
14
15#include <chrono>
16#include <cstdint>
17#include <memory>
18#include <optional>
19#include <string>
20#include <vector>
21
22class CBlock;
24class CTxMemPool;
26struct TxId;
27
28namespace node {
29class TxDownloadManagerImpl;
30
34 .max_peer_announcements = 5000,
35 .nonpref_peer_delay = std::chrono::seconds{2},
36 .overloaded_peer_delay = std::chrono::seconds{2},
37 .getdata_interval = std::chrono::seconds{60},
38 .bypass_request_limits_permissions = NetPermissionFlags::Relay,
39};
40
57 std::vector<NodeId> m_senders;
59 explicit PackageToValidate(const CTransactionRef &parent,
60 const CTransactionRef &child,
61 NodeId parent_sender, NodeId child_sender)
62 : m_txns{parent, child}, m_senders{parent_sender, child_sender} {}
63
64 // Move ctor
66 : m_txns{std::move(other.m_txns)},
67 m_senders{std::move(other.m_senders)} {}
68 // Copy ctor
69 PackageToValidate(const PackageToValidate &other) = default;
70
71 // Move assignment
73 this->m_txns = std::move(other.m_txns);
74 this->m_senders = std::move(other.m_senders);
75 return *this;
76 }
77
78 std::string ToString() const {
79 Assume(m_txns.size() == 2);
80 return strprintf("parent %s (sender=%d) + child %s (sender=%d)",
81 m_txns.front()->GetId().ToString(), m_senders.front(),
82 m_txns.back()->GetId().ToString(), m_senders.back());
83 }
84};
87 std::vector<TxId> m_unique_parents;
88 std::optional<PackageToValidate> m_package_to_validate;
89};
90
111 const std::unique_ptr<TxDownloadManagerImpl> m_impl;
112
113public:
114 explicit TxDownloadManager(const TxDownloadOptions &options);
116
117 // Get references to internal data structures. These are only used by the
118 // avalanche logic in PeerManager.
122
123 // Responses to chain events. TxDownloadManager is not an actual client of
124 // ValidationInterface, these are called through PeerManager.
125 void ActiveTipChange();
126 void BlockConnected(const std::shared_ptr<const CBlock> &pblock);
127 void BlockDisconnected();
128
133 void ConnectedPeer(NodeId nodeid, const TxDownloadConnectionInfo &info);
134
136 void DisconnectedPeer(NodeId nodeid);
137
145 bool AddTxAnnouncement(NodeId peer, const TxId &txid,
146 std::chrono::microseconds now);
147
149 std::vector<TxId> GetRequestsToSend(NodeId nodeid,
150 std::chrono::microseconds current_time);
151
153 void ReceivedNotFound(NodeId nodeid, const std::vector<TxId> &txids);
154
156 void MempoolAcceptedTx(const CTransactionRef &tx);
157
160 const TxValidationState &state,
161 NodeId nodeid, bool first_time_failure);
162
164 void MempoolRejectedPackage(const Package &package);
165
171 std::pair<bool, std::optional<PackageToValidate>>
172 ReceivedTx(NodeId nodeid, const CTransactionRef &ptx);
173
175 bool HaveMoreWork(NodeId nodeid) const;
176
179
181 void CheckIsEmpty() const;
182
187 void CheckIsEmpty(NodeId nodeid) const;
188
190 std::vector<TxOrphanage::PoolTx> GetOrphanTransactions() const;
191};
192} // namespace node
193#endif // BITCOIN_NODE_TXDOWNLOADMAN_H
#define Assume(val)
Assume is the identity function.
Definition check.h:100
Definition block.h:60
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set.
Definition bloom.h:115
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition txmempool.h:222
Class responsible for deciding what transactions to request and, once downloaded, whether and how to ...
const std::unique_ptr< TxDownloadManagerImpl > m_impl
std::vector< TxId > GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time)
Get getdata requests to send.
InvRequestTracker< TxId > & GetTxRequestRef()
std::pair< bool, std::optional< PackageToValidate > > ReceivedTx(NodeId nodeid, const CTransactionRef &ptx)
Marks a tx as ReceivedResponse in txrequest and checks whether AlreadyHaveTx.
std::vector< TxOrphanage::PoolTx > GetOrphanTransactions() const
Wrapper for TxOrphanage::GetOrphanTransactions.
void BlockConnected(const std::shared_ptr< const CBlock > &pblock)
CTransactionRef GetTxToReconsider(NodeId nodeid)
Returns next orphan tx to consider, or nullptr if none exist.
void CheckIsEmpty() const
Check that all data structures are empty.
void MempoolAcceptedTx(const CTransactionRef &tx)
Respond to successful transaction submission to mempool.
void ConnectedPeer(NodeId nodeid, const TxDownloadConnectionInfo &info)
Creates a new PeerInfo.
bool AddTxAnnouncement(NodeId peer, const TxId &txid, std::chrono::microseconds now)
Consider adding this tx hash to txrequest.
void MempoolRejectedPackage(const Package &package)
Respond to package rejected from mempool.
void DisconnectedPeer(NodeId nodeid)
Deletes all txrequest announcements and orphans for a given peer.
CRollingBloomFilter & RecentRejectsFilter()
RejectedTxTodo MempoolRejectedTx(const CTransactionRef &ptx, const TxValidationState &state, NodeId nodeid, bool first_time_failure)
Respond to transaction rejected from mempool.
CRollingBloomFilter & RecentConfirmedTransactionsFilter()
void ReceivedNotFound(NodeId nodeid, const std::vector< TxId > &txids)
Should be called when a notfound for a tx has been received.
bool HaveMoreWork(NodeId nodeid) const
Whether there are any orphans to reconsider for this peer.
int64_t NodeId
Definition eviction.h:16
static constexpr DataRequestParameters TX_REQUEST_PARAMS
Parameters for the tx requests, see DataRequestParameters.
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition rcu.h:259
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
Definition packages.h:40
std::shared_ptr< const CTransaction > CTransactionRef
const size_t max_peer_request_in_flight
Maximum number of in-flight data requests from a peer.
Definition invrequest.h:356
A TxId is the identifier of a transaction.
Definition txid.h:14
std::vector< NodeId > m_senders
PackageToValidate(const CTransactionRef &parent, const CTransactionRef &child, NodeId parent_sender, NodeId child_sender)
Construct a 1-parent-1-child package.
std::string ToString() const
PackageToValidate(PackageToValidate &&other)
PackageToValidate & operator=(PackageToValidate &&other)
PackageToValidate(const PackageToValidate &other)=default
std::optional< PackageToValidate > m_package_to_validate
std::vector< TxId > m_unique_parents
const bool m_preferred
Whether this peer is preferred for transaction download.
const bool m_relay_permissions
Whether this peer has Relay permissions.
bool m_deterministic_txrequest
Instantiate TxRequestTracker as deterministic (used for tests).
const uint32_t m_max_orphan_txs
Maximum number of transactions allowed in orphanage.
const CTxMemPool & m_mempool
Read-only reference to mempool.
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...