Bitcoin Core 22.99.0
P2P Digital Currency
txorphanage.h
Go to the documentation of this file.
1// Copyright (c) 2021 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_TXORPHANAGE_H
6#define BITCOIN_TXORPHANAGE_H
7
8#include <net.h>
9#include <primitives/block.h>
11#include <sync.h>
12
15
22public:
25
27 bool HaveTx(const GenTxid& gtxid) const LOCKS_EXCLUDED(::g_cs_orphans);
28
32 std::pair<CTransactionRef, NodeId> GetTx(const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
33
36
39
41 void EraseForBlock(const CBlock& block) LOCKS_EXCLUDED(::g_cs_orphans);
42
44 unsigned int LimitOrphans(unsigned int max_orphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
45
48 void AddChildrenToWorkSet(const CTransaction& tx, std::set<uint256>& orphan_work_set) const EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
49
52 {
54 return m_orphans.size();
55 }
56
57protected:
58 struct OrphanTx {
61 int64_t nTimeExpire;
62 size_t list_pos;
63 };
64
67 std::map<uint256, OrphanTx> m_orphans GUARDED_BY(g_cs_orphans);
68
69 using OrphanMap = decltype(m_orphans);
70
72 {
73 template<typename I>
74 bool operator()(const I& a, const I& b) const
75 {
76 return &(*a) < &(*b);
77 }
78 };
79
82 std::map<COutPoint, std::set<OrphanMap::iterator, IteratorComparator>> m_outpoint_to_orphan_it GUARDED_BY(g_cs_orphans);
83
85 std::vector<OrphanMap::iterator> m_orphan_list GUARDED_BY(g_cs_orphans);
86
89 std::map<uint256, OrphanMap::iterator> m_wtxid_to_orphan_it GUARDED_BY(g_cs_orphans);
90};
91
92#endif // BITCOIN_TXORPHANAGE_H
Definition: block.h:63
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:260
A generic txid reference (txid or wtxid).
Definition: transaction.h:391
A class to track orphan transactions (failed on TX_MISSING_INPUTS) Since we cannot distinguish orphan...
Definition: txorphanage.h:21
std::map< uint256, OrphanTx > m_orphans GUARDED_BY(g_cs_orphans)
Map from txid to orphan transaction record.
std::map< uint256, OrphanMap::iterator > m_wtxid_to_orphan_it GUARDED_BY(g_cs_orphans)
Index from wtxid into the m_orphans to lookup orphan transactions using their witness ids.
decltype(m_orphans) OrphanMap
Definition: txorphanage.h:69
int EraseTx(const uint256 &txid) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Erase an orphan by txid.
Definition: txorphanage.cpp:56
bool HaveTx(const GenTxid &gtxid) const LOCKS_EXCLUDED(std::pair< CTransactionRef, NodeId > GetTx(const uint256 &txid) const EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Check if we already have an orphan transaction (by txid or wtxid)
Definition: txorphanage.h:32
size_t Size() LOCKS_EXCLUDED(
Return how many entries exist in the orphange.
Definition: txorphanage.h:51
void AddChildrenToWorkSet(const CTransaction &tx, std::set< uint256 > &orphan_work_set) const EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Add any orphans that list a particular tx as a parent into a peer's work set (ie orphans that may hav...
std::vector< OrphanMap::iterator > m_orphan_list GUARDED_BY(g_cs_orphans)
Orphan transactions in vector for quick random eviction.
void EraseForPeer(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Erase all orphans announced by a peer (eg, after that peer disconnects)
Definition: txorphanage.cpp:88
bool AddTx(const CTransactionRef &tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Add a new orphan transaction.
Definition: txorphanage.cpp:20
void EraseForBlock(const CBlock &block) LOCKS_EXCLUDED(unsigned int LimitOrphans(unsigned int max_orphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Erase all orphans included in or invalidated by a new block.
Definition: txorphanage.h:44
std::map< COutPoint, std::set< OrphanMap::iterator, IteratorComparator > > m_outpoint_to_orphan_it GUARDED_BY(g_cs_orphans)
Index from the parents' COutPoint into the m_orphans.
256-bit opaque blob.
Definition: uint256.h:124
int64_t NodeId
Definition: net.h:87
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:386
bool operator()(const I &a, const I &b) const
Definition: txorphanage.h:74
CTransactionRef tx
Definition: txorphanage.h:59
#define LOCK(cs)
Definition: sync.h:226
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:48
RecursiveMutex g_cs_orphans
Guards orphan transactions and extra txs for compact blocks.
Definition: txorphanage.cpp:18