-
Only add a transaction to the unbroadcast set when it’s added to the mempool
Currently, if BroadcastTransaction() is called to rebroadcast a transaction (e.g. by ResendWalletTransactions()), then we add the transaction to the unbroadcast set. That transaction has already been broadcast in the past, so peers are unlikely to request it again, meaning RemoveUnbroadcastTx() won’t be called and it won’t be removed from m_unbroadcast_txids.
Net processing will therefore continue to attempt rebroadcast for the transaction every 10-15 minutes. This will most likely continue until the node connects to a new peer which hasn’t yet seen the transaction (or perhaps indefinitely).
Fix by only adding the transaction to the broadcast set when it’s added to the mempool.
-
Allow rebroadcast for same-txid-different-wtxid transactions
There is some slightly unexpected behaviour when:
- there is already transaction in the mempool (the “mempool tx”)
- BroadcastTransaction() is called for a transaction with the same txid as the mempool transaction but a different witness (the “new tx”)
Prior to this commit, if BroadcastTransaction() is called with relay=true, then it’ll call RelayTransaction() using the txid/wtxid of the new tx, not the txid/wtxid of the mempool tx. For wtxid relay peers, in SendMessages(), the wtxid of the new tx will be taken from setInventoryTxToSend, but will then be filtered out from the vector of wtxids to announce, since m_mempool.info() won’t find the transaction (the mempool contains the mempool tx, which has a different wtxid from the new tx).
Fix this by calling RelayTransaction() with the wtxid of the mempool transaction in this case.
The third commit is a comment/whitespace only change to tidy up the BroadcastTransaction() function.