diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -604,7 +604,8 @@ // Pass this transaction to node for mempool insertion and relay to peers if // flag set to true - bool SubmitMemoryPoolAndRelay(std::string &err_string, bool relay); + bool SubmitMemoryPoolAndRelay(std::string &err_string, bool relay, + interfaces::Chain::Lock &locked_chain); // TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct // annotation "EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)". The annotation diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2317,11 +2317,13 @@ for (const std::pair &item : mapSorted) { CWalletTx &wtx = *(item.second); std::string unused_err_string; - wtx.SubmitMemoryPoolAndRelay(unused_err_string, false); + wtx.SubmitMemoryPoolAndRelay(unused_err_string, false, locked_chain); } } -bool CWalletTx::SubmitMemoryPoolAndRelay(std::string &err_string, bool relay) { +bool CWalletTx::SubmitMemoryPoolAndRelay( + std::string &err_string, bool relay, + interfaces::Chain::Lock &locked_chain) { // Can't relay if wallet is not broadcasting if (!pwallet->GetBroadcastTransactions()) { return false; @@ -2330,6 +2332,15 @@ if (isAbandoned()) { return false; } + // Don't try to submit coinbase transactions. These would fail anyway but + // would cause log spam. + if (IsCoinBase()) { + return false; + } + // Don't try to submit conflicted or confirmed transactions. + if (GetDepthInMainChain(locked_chain) != 0) { + return false; + } // Submit transaction to mempool for relay pwallet->WalletLogPrintf("Submitting wtx %s to mempool for relay\n", @@ -2591,13 +2602,15 @@ // Relay transactions for (std::pair &item : mapWallet) { CWalletTx &wtx = item.second; - // only rebroadcast unconfirmed txes older than 5 minutes before the - // last block was found + // Attempt to rebroadcast all txes more than 5 minutes older than + // the last block. SubmitMemoryPoolAndRelay() will not rebroadcast + // any confirmed or conflicting txs. if (wtx.nTimeReceived > m_best_block_time - 5 * 60) { continue; } std::string unused_err_string; - if (wtx.SubmitMemoryPoolAndRelay(unused_err_string, true)) { + if (wtx.SubmitMemoryPoolAndRelay(unused_err_string, true, + *locked_chain)) { ++submitted_tx_count; } } @@ -3670,7 +3683,7 @@ if (fBroadcastTransactions) { std::string err_string; - if (!wtx.SubmitMemoryPoolAndRelay(err_string, true)) { + if (!wtx.SubmitMemoryPoolAndRelay(err_string, true, *locked_chain)) { WalletLogPrintf("CommitTransaction(): Transaction cannot be " "broadcast immediately, %s\n", err_string);