[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
This commit is contained in:
gzhao408
2020-05-01 15:48:23 -07:00
parent a7ebe48b94
commit 9d3f7eb986
2 changed files with 10 additions and 2 deletions

View File

@@ -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