Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
txorphanage.h
Go to the documentation of this file.
1// Copyright (c) 2021-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_NODE_TXORPHANAGE_H
6#define BITCOIN_NODE_TXORPHANAGE_H
7
9#include <net.h>
10#include <primitives/block.h>
12#include <sync.h>
13#include <util/time.h>
14
15#include <map>
16#include <set>
17
18namespace node {
20inline constexpr int64_t DEFAULT_RESERVED_ORPHAN_WEIGHT_PER_PEER{404'000};
23inline constexpr unsigned int DEFAULT_MAX_ORPHANAGE_LATENCY_SCORE{3'000};
24
25// Keep the connection caps below the default global latency limit to avoid a zero per-peer share.
27
42public:
43 using Usage = int64_t;
44 using Count = unsigned int;
45
47 struct OrphanInfo {
50 std::set<NodeId> announcers;
51
52 // Constructor with moved announcers
53 OrphanInfo(CTransactionRef tx, std::set<NodeId>&& announcers) :
54 tx(std::move(tx)),
56 {}
57 };
58
59 virtual ~TxOrphanage() = default;
60
62 virtual bool AddTx(const CTransactionRef& tx, NodeId peer) = 0;
63
65 virtual bool AddAnnouncer(const Wtxid& wtxid, NodeId peer) = 0;
66
68 virtual CTransactionRef GetTx(const Wtxid& wtxid) const = 0;
69
71 virtual bool HaveTx(const Wtxid& wtxid) const = 0;
72
74 virtual bool HaveTxFromPeer(const Wtxid& wtxid, NodeId peer) const = 0;
75
82
85 virtual bool EraseTx(const Wtxid& wtxid) = 0;
86
89 virtual void EraseForPeer(NodeId peer) = 0;
90
92 virtual void EraseForBlock(const CBlock& block) = 0;
93
95 virtual std::vector<std::pair<Wtxid, NodeId>> AddChildrenToWorkSet(const CTransaction& tx, FastRandomContext& rng) = 0;
96
98 virtual bool HaveTxToReconsider(NodeId peer) = 0;
99
102 virtual std::vector<CTransactionRef> GetChildrenFromSamePeer(const CTransactionRef& parent, NodeId nodeid) const = 0;
103
105 virtual std::vector<OrphanInfo> GetOrphanTransactions() const = 0;
106
109 virtual Usage TotalOrphanUsage() const = 0;
110
115 virtual Usage UsageByPeer(NodeId peer) const = 0;
116
119 virtual void SanityCheck() const = 0;
120
123 virtual Count CountAnnouncements() const = 0;
124
126 virtual Count CountUniqueOrphans() const = 0;
127
129 virtual Count AnnouncementsFromPeer(NodeId peer) const = 0;
130
132 virtual Count LatencyScoreFromPeer(NodeId peer) const = 0;
133
135 virtual Count MaxGlobalLatencyScore() const = 0;
136
138 virtual Count TotalLatencyScore() const = 0;
139
141 virtual Usage ReservedPeerUsage() const = 0;
142
144 virtual Count MaxPeerLatencyScore() const = 0;
145
147 virtual Usage MaxGlobalUsage() const = 0;
148};
149
151std::unique_ptr<TxOrphanage> MakeTxOrphanage() noexcept;
152std::unique_ptr<TxOrphanage> MakeTxOrphanage(TxOrphanage::Count max_global_latency_score, TxOrphanage::Usage reserved_peer_usage) noexcept;
153} // namespace node
154#endif // BITCOIN_NODE_TXORPHANAGE_H
Definition block.h:74
The basic transaction that is broadcasted on the network and contained in blocks.
Fast randomness source.
Definition random.h:386
A class to track orphan transactions (failed on TX_MISSING_INPUTS) Since we cannot distinguish orphan...
Definition txorphanage.h:41
virtual void SanityCheck() const =0
Check consistency between PeerOrphanInfo and m_orphans.
virtual Count CountAnnouncements() const =0
Number of announcements, i.e.
virtual std::vector< CTransactionRef > GetChildrenFromSamePeer(const CTransactionRef &parent, NodeId nodeid) const =0
Get all children that spend from this tx and were received from nodeid.
virtual bool HaveTxToReconsider(NodeId peer)=0
Does this peer have any work to do?
virtual bool AddTx(const CTransactionRef &tx, NodeId peer)=0
Add a new orphan transaction.
virtual Usage MaxGlobalUsage() const =0
Get the maximum global usage allowed.
virtual Count AnnouncementsFromPeer(NodeId peer) const =0
Number of orphans stored from this peer.
virtual Count CountUniqueOrphans() const =0
Number of unique orphans (by wtxid).
virtual std::vector< OrphanInfo > GetOrphanTransactions() const =0
Get all orphan transactions.
virtual Usage TotalOrphanUsage() const =0
Get the total usage (weight) of all orphans.
virtual void EraseForBlock(const CBlock &block)=0
Erase all orphans included in or invalidated by a new block.
virtual Count TotalLatencyScore() const =0
Get the total latency score of all orphans.
virtual ~TxOrphanage()=default
virtual std::vector< std::pair< Wtxid, NodeId > > AddChildrenToWorkSet(const CTransaction &tx, FastRandomContext &rng)=0
Add any orphans that list a particular tx as a parent into the from peer's work set.
virtual Usage UsageByPeer(NodeId peer) const =0
Total usage (weight) of orphans for which this peer is an announcer.
unsigned int Count
Definition txorphanage.h:44
virtual bool AddAnnouncer(const Wtxid &wtxid, NodeId peer)=0
Add an additional announcer to an orphan if it exists.
virtual Count MaxGlobalLatencyScore() const =0
Get the maximum global latency score allowed.
virtual CTransactionRef GetTx(const Wtxid &wtxid) const =0
Get a transaction by its witness txid.
virtual Count MaxPeerLatencyScore() const =0
Get the maximum latency score allowed per peer.
virtual bool HaveTxFromPeer(const Wtxid &wtxid, NodeId peer) const =0
Check if a {tx, peer} exists in the orphanage.
virtual void EraseForPeer(NodeId peer)=0
Maybe erase all orphans announced by a peer (eg, after that peer disconnects).
virtual CTransactionRef GetTxToReconsider(NodeId peer)=0
Extract a transaction from a peer's work set, and flip it back to non-reconsiderable.
virtual Usage ReservedPeerUsage() const =0
Get the reserved usage per peer.
virtual bool HaveTx(const Wtxid &wtxid) const =0
Check if we already have an orphan transaction (by wtxid only).
virtual Count LatencyScoreFromPeer(NodeId peer) const =0
Latency score of transactions announced by this peer.
virtual bool EraseTx(const Wtxid &wtxid)=0
Erase an orphan by wtxid, including all announcements if there are multiple.
std::unique_ptr< TxOrphanage > MakeTxOrphanage() noexcept
Create a new TxOrphanage instance.
constexpr unsigned int DEFAULT_MAX_ORPHANAGE_LATENCY_SCORE
Default value for TxOrphanage::m_max_global_latency_score.
Definition txorphanage.h:23
constexpr int64_t DEFAULT_RESERVED_ORPHAN_WEIGHT_PER_PEER
Default value for TxOrphanage::m_reserved_usage_per_peer.
Definition txorphanage.h:20
constexpr int MAX_ADDNODE_CONNECTIONS
Maximum number of addnode outgoing nodes.
Definition net.h:71
constexpr size_t MAX_PRIVATE_BROADCAST_CONNECTIONS
Maximum number of private broadcast connections.
Definition net.h:77
int64_t NodeId
Definition net.h:107
constexpr int MAX_PEER_CONNECTIONS
Maximum value of -maxconnections.
Definition net.h:83
std::shared_ptr< const CTransaction > CTransactionRef
std::set< NodeId > announcers
Peers added with AddTx or AddAnnouncer.
Definition txorphanage.h:50
OrphanInfo(CTransactionRef tx, std::set< NodeId > &&announcers)
Definition txorphanage.h:53
FastRandomContext rng
transaction_identifier< true > Wtxid
Wtxid commits to all transaction fields including the witness.