[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
pull/764/head
gzhao408 5 years ago
parent a7ebe48b94
commit 9d3f7eb986

@ -819,7 +819,12 @@ void PeerLogicValidation::ReattemptInitialBroadcast(CScheduler& scheduler) const
std::set<uint256> unbroadcast_txids = m_mempool.GetUnbroadcastTxs();
for (const uint256& txid : unbroadcast_txids) {
RelayTransaction(txid, *connman);
// Sanity check: all unbroadcast txns should exist in the mempool
if (m_mempool.exists(txid)) {
RelayTransaction(txid, *connman);
} else {
m_mempool.RemoveUnbroadcastTx(txid, true);
}
}
// schedule next run for 10-15 minutes in the future

@ -704,7 +704,10 @@ public:
/** Adds a transaction to the unbroadcast set */
void AddUnbroadcastTx(const uint256& txid) {
LOCK(cs);
m_unbroadcast_txids.insert(txid);
/** Sanity Check: the transaction should also be in the mempool */
if (exists(txid)) {
m_unbroadcast_txids.insert(txid);
}
}
/** Removes a transaction from the unbroadcast set */

Loading…
Cancel
Save