aboutsummaryrefslogtreecommitdiff
path: root/src/txorphanage.h
diff options
context:
space:
mode:
authorAnthony Towns <aj@erisian.com.au>2021-01-31 00:55:54 +1000
committerAnthony Towns <aj@erisian.com.au>2021-02-26 23:55:03 +1000
commit9d5313df7eedad8562c822f5477747e924929fd3 (patch)
tree536a9a73902a59cf14a69c3528d938587573d905 /src/txorphanage.h
parent56f06a986385b24818a53fde24c6f3a0b01f1a93 (diff)
move-only: Add txorphanage module
This module captures orphan tracking code for tx relay. Can be reviewed with --color-moved=dimmed-zebra
Diffstat (limited to 'src/txorphanage.h')
-rw-r--r--src/txorphanage.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/txorphanage.h b/src/txorphanage.h
new file mode 100644
index 0000000000..d97b4b1f43
--- /dev/null
+++ b/src/txorphanage.h
@@ -0,0 +1,54 @@
+// Copyright (c) 2021 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#ifndef BITCOIN_TXORPHANAGE_H
+#define BITCOIN_TXORPHANAGE_H
+
+#include <net.h>
+#include <primitives/transaction.h>
+#include <sync.h>
+
+/** Expiration time for orphan transactions in seconds */
+static constexpr int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60;
+
+/** Guards orphan transactions and extra txs for compact blocks */
+extern RecursiveMutex g_cs_orphans;
+
+struct COrphanTx {
+ // When modifying, adapt the copy of this definition in tests/DoS_tests.
+ CTransactionRef tx;
+ NodeId fromPeer;
+ int64_t nTimeExpire;
+ size_t list_pos;
+};
+
+int EraseOrphanTx(uint256 hash) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
+void EraseOrphansFor(NodeId peer);
+unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans);
+
+/** Map from txid to orphan transaction record. Limited by
+ * -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */
+extern std::map<uint256, COrphanTx> mapOrphanTransactions GUARDED_BY(g_cs_orphans);
+
+/** Index from wtxid into the mapOrphanTransactions to lookup orphan
+ * transactions using their witness ids. */
+extern std::map<uint256, std::map<uint256, COrphanTx>::iterator> g_orphans_by_wtxid GUARDED_BY(g_cs_orphans);
+
+ struct IteratorComparator
+ {
+ template<typename I>
+ bool operator()(const I& a, const I& b) const
+ {
+ return &(*a) < &(*b);
+ }
+ };
+
+ /** Index from the parents' COutPoint into the mapOrphanTransactions. Used
+ * to remove orphan transactions from the mapOrphanTransactions */
+ extern std::map<COutPoint, std::set<std::map<uint256, COrphanTx>::iterator, IteratorComparator>> mapOrphanTransactionsByPrev GUARDED_BY(g_cs_orphans);
+
+ /** Orphan transactions in vector for quick random eviction */
+ extern std::vector<std::map<uint256, COrphanTx>::iterator> g_orphan_list GUARDED_BY(g_cs_orphans);
+
+#endif // BITCOIN_TXORPHANAGE_H