Skip to content

Commit 9d3f7eb

Browse files
committed
[mempool] sanity check that all unbroadcast txns are in mempool
- before reattempting broadcast for unbroadcast txns, check they are in mempool and remove if not - this protects from memory leaks and network spam just in case unbroadcast set (incorrectly) has extra txns - check that tx is in mempool before adding to unbroadcast set to try to prevent this from happening
1 parent a7ebe48 commit 9d3f7eb

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/net_processing.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,12 @@ void PeerLogicValidation::ReattemptInitialBroadcast(CScheduler& scheduler) const
819819
std::set<uint256> unbroadcast_txids = m_mempool.GetUnbroadcastTxs();
820820

821821
for (const uint256& txid : unbroadcast_txids) {
822-
RelayTransaction(txid, *connman);
822+
// Sanity check: all unbroadcast txns should exist in the mempool
823+
if (m_mempool.exists(txid)) {
824+
RelayTransaction(txid, *connman);
825+
} else {
826+
m_mempool.RemoveUnbroadcastTx(txid, true);
827+
}
823828
}
824829

825830
// schedule next run for 10-15 minutes in the future

src/txmempool.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,10 @@ class CTxMemPool
704704
/** Adds a transaction to the unbroadcast set */
705705
void AddUnbroadcastTx(const uint256& txid) {
706706
LOCK(cs);
707-
m_unbroadcast_txids.insert(txid);
707+
/** Sanity Check: the transaction should also be in the mempool */
708+
if (exists(txid)) {
709+
m_unbroadcast_txids.insert(txid);
710+
}
708711
}
709712

710713
/** Removes a transaction from the unbroadcast set */

0 commit comments

Comments
 (0)