Skip to content

Commit 2837a9f

Browse files
committed
[mempool] 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.
1 parent 8ab0c77 commit 2837a9f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/node/transaction.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
7171

7272
// Transaction was accepted to the mempool.
7373

74+
if (relay) {
75+
// the mempool tracks locally submitted transactions to make a
76+
// best-effort of initial broadcast
77+
node.mempool->AddUnbroadcastTx(hashTx);
78+
}
79+
7480
if (wait_callback) {
7581
// For transactions broadcast from outside the wallet, make sure
7682
// that the wallet has been notified of the transaction before
@@ -96,9 +102,6 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
96102
}
97103

98104
if (relay) {
99-
// the mempool tracks locally submitted transactions to make a
100-
// best-effort of initial broadcast
101-
node.mempool->AddUnbroadcastTx(hashTx);
102105
node.peerman->RelayTransaction(hashTx, tx->GetWitnessHash());
103106
}
104107

0 commit comments

Comments
 (0)