Bitcoin Core
31.0.0
P2P Digital Currency
src
node
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
8
#include <
consensus/validation.h
>
9
#include <net.h>
10
#include <
primitives/block.h
>
11
#include <
primitives/transaction.h
>
12
#include <
sync.h
>
13
#include <util/time.h>
14
15
#include <map>
16
#include <set>
17
18
namespace
node
{
20
static
constexpr int64_t
DEFAULT_RESERVED_ORPHAN_WEIGHT_PER_PEER
{404
'000};
23
static constexpr unsigned int DEFAULT_MAX_ORPHANAGE_LATENCY_SCORE{3000};
24
38
class TxOrphanage {
39
public:
40
using Usage = int64_t;
41
using Count = unsigned int;
42
44
struct OrphanInfo {
45
CTransactionRef tx;
47
std::set<NodeId> announcers;
48
49
// Constructor with moved announcers
50
OrphanInfo(CTransactionRef tx, std::set<NodeId>&& announcers) :
51
tx(std::move(tx)),
52
announcers(std::move(announcers))
53
{}
54
};
55
56
virtual ~TxOrphanage() = default;
57
59
virtual bool AddTx(const CTransactionRef& tx, NodeId peer) = 0;
60
62
virtual bool AddAnnouncer(const Wtxid& wtxid, NodeId peer) = 0;
63
65
virtual CTransactionRef GetTx(const Wtxid& wtxid) const = 0;
66
68
virtual bool HaveTx(const Wtxid& wtxid) const = 0;
69
71
virtual bool HaveTxFromPeer(const Wtxid& wtxid, NodeId peer) const = 0;
72
78
virtual CTransactionRef GetTxToReconsider(NodeId peer) = 0;
79
82
virtual bool EraseTx(const Wtxid& wtxid) = 0;
83
86
virtual void EraseForPeer(NodeId peer) = 0;
87
89
virtual void EraseForBlock(const CBlock& block) = 0;
90
92
virtual std::vector<std::pair<Wtxid, NodeId>> AddChildrenToWorkSet(const CTransaction& tx, FastRandomContext& rng) = 0;
93
95
virtual bool HaveTxToReconsider(NodeId peer) = 0;
96
99
virtual std::vector<CTransactionRef> GetChildrenFromSamePeer(const CTransactionRef& parent, NodeId nodeid) const = 0;
100
102
virtual std::vector<OrphanInfo> GetOrphanTransactions() const = 0;
103
106
virtual Usage TotalOrphanUsage() const = 0;
107
112
virtual Usage UsageByPeer(NodeId peer) const = 0;
113
116
virtual void SanityCheck() const = 0;
117
120
virtual Count CountAnnouncements() const = 0;
121
123
virtual Count CountUniqueOrphans() const = 0;
124
126
virtual Count AnnouncementsFromPeer(NodeId peer) const = 0;
127
129
virtual Count LatencyScoreFromPeer(NodeId peer) const = 0;
130
132
virtual Count MaxGlobalLatencyScore() const = 0;
133
135
virtual Count TotalLatencyScore() const = 0;
136
138
virtual Usage ReservedPeerUsage() const = 0;
139
141
virtual Count MaxPeerLatencyScore() const = 0;
142
144
virtual Usage MaxGlobalUsage() const = 0;
145
};
146
148
std::unique_ptr<TxOrphanage> MakeTxOrphanage() noexcept;
149
std::unique_ptr<TxOrphanage> MakeTxOrphanage(TxOrphanage::Count max_global_latency_score, TxOrphanage::Usage reserved_peer_usage) noexcept;
150
} // namespace node
151
#endif // BITCOIN_NODE_TXORPHANAGE_H
transaction.h
validation.h
node
Definition:
messages.h:21
node::DEFAULT_RESERVED_ORPHAN_WEIGHT_PER_PEER
static constexpr int64_t DEFAULT_RESERVED_ORPHAN_WEIGHT_PER_PEER
Default value for TxOrphanage::m_reserved_usage_per_peer.
Definition:
txorphanage.h:20
sync.h
block.h
Generated on Thu Apr 16 2026 12:00:00 for Bitcoin Core by
1.8.14