@@ -2150,11 +2150,11 @@ void CWallet::ReacceptWalletTransactions(interfaces::Chain::Lock& locked_chain)
2150
2150
for (const std::pair<const int64_t , CWalletTx*>& item : mapSorted) {
2151
2151
CWalletTx& wtx = *(item.second );
2152
2152
std::string unused_err_string;
2153
- wtx.SubmitMemoryPoolAndRelay (unused_err_string, false );
2153
+ wtx.SubmitMemoryPoolAndRelay (unused_err_string, false , locked_chain );
2154
2154
}
2155
2155
}
2156
2156
2157
- bool CWalletTx::SubmitMemoryPoolAndRelay (std::string& err_string, bool relay)
2157
+ bool CWalletTx::SubmitMemoryPoolAndRelay (std::string& err_string, bool relay, interfaces::Chain::Lock& locked_chain )
2158
2158
{
2159
2159
// Can't relay if wallet is not broadcasting
2160
2160
if (!pwallet->GetBroadcastTransactions ()) return false ;
@@ -2163,6 +2163,8 @@ bool CWalletTx::SubmitMemoryPoolAndRelay(std::string& err_string, bool relay)
2163
2163
// Don't try to submit coinbase transactions. These would fail anyway but would
2164
2164
// cause log spam.
2165
2165
if (IsCoinBase ()) return false ;
2166
+ // Don't try to submit conflicted or confirmed transactions.
2167
+ if (GetDepthInMainChain (locked_chain) != 0 ) return false ;
2166
2168
2167
2169
// Submit transaction to mempool for relay
2168
2170
pwallet->WalletLogPrintf (" Submitting wtx %s to mempool for relay\n " , GetHash ().ToString ());
@@ -2377,11 +2379,12 @@ void CWallet::ResendWalletTransactions()
2377
2379
// Relay transactions
2378
2380
for (std::pair<const uint256, CWalletTx>& item : mapWallet) {
2379
2381
CWalletTx& wtx = item.second ;
2380
- // only rebroadcast unconfirmed txes older than 5 minutes before the
2381
- // last block was found
2382
+ // Attempt to rebroadcast all txes more than 5 minutes older than
2383
+ // the last block. SubmitMemoryPoolAndRelay() will not rebroadcast
2384
+ // any confirmed or conflicting txs.
2382
2385
if (wtx.nTimeReceived > m_best_block_time - 5 * 60 ) continue ;
2383
2386
std::string unused_err_string;
2384
- if (wtx.SubmitMemoryPoolAndRelay (unused_err_string, true )) ++submitted_tx_count;
2387
+ if (wtx.SubmitMemoryPoolAndRelay (unused_err_string, true , *locked_chain )) ++submitted_tx_count;
2385
2388
}
2386
2389
} // locked_chain and cs_wallet
2387
2390
@@ -3326,7 +3329,7 @@ bool CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::ve
3326
3329
if (fBroadcastTransactions )
3327
3330
{
3328
3331
std::string err_string;
3329
- if (!wtx.SubmitMemoryPoolAndRelay (err_string, true )) {
3332
+ if (!wtx.SubmitMemoryPoolAndRelay (err_string, true , *locked_chain )) {
3330
3333
WalletLogPrintf (" CommitTransaction(): Transaction cannot be broadcast immediately, %s\n " , err_string);
3331
3334
// TODO: if we expect the failure to be long term or permanent, instead delete wtx from the wallet and return failure.
3332
3335
}
0 commit comments