diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1089,11 +1089,6 @@ void ReacceptWalletTransactions(); void ResendWalletTransactions(interfaces::Chain::Lock &locked_chain) override; - // ResendWalletTransactionsBefore may only be called if - // fBroadcastTransactions! - std::vector - ResendWalletTransactionsBefore(interfaces::Chain::Lock &locked_chain, - int64_t nTime); Amount GetBalance(const isminefilter &filter = ISMINE_SPENDABLE, const int min_depth = 0) const; Amount GetUnconfirmedBalance() const; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2246,35 +2246,6 @@ return CTransaction(tx1) == CTransaction(tx2); } -std::vector -CWallet::ResendWalletTransactionsBefore(interfaces::Chain::Lock &locked_chain, - int64_t nTime) { - std::vector result; - - LOCK(cs_wallet); - - // Sort them in chronological order - std::multimap mapSorted; - for (std::pair &item : mapWallet) { - CWalletTx &wtx = item.second; - // Don't rebroadcast if newer than nTime: - if (wtx.nTimeReceived > nTime) { - continue; - } - - mapSorted.insert(std::make_pair(wtx.nTimeReceived, &wtx)); - } - - for (const std::pair &item : mapSorted) { - CWalletTx &wtx = *item.second; - if (wtx.RelayWalletTransaction(locked_chain)) { - result.push_back(wtx.GetId()); - } - } - - return result; -} - void CWallet::ResendWalletTransactions(interfaces::Chain::Lock &locked_chain) { // Do this infrequently and randomly to avoid giving away that these are our // transactions. @@ -2295,13 +2266,27 @@ nLastResend = GetTime(); - // Rebroadcast unconfirmed txes older than 5 minutes before the last block - // was found: - std::vector relayed = ResendWalletTransactionsBefore( - locked_chain, m_best_block_time - 5 * 60); - if (!relayed.empty()) { + int relayed_tx_count = 0; + + { // cs_wallet scope + LOCK(cs_wallet); + + // 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 + if (wtx.nTimeReceived > m_best_block_time - 5 * 60) { + continue; + } + relayed_tx_count += + wtx.RelayWalletTransaction(locked_chain) ? 1 : 0; + } + } // cs_wallet + + if (relayed_tx_count > 0) { WalletLogPrintf("%s: rebroadcast %u unconfirmed transactions\n", - __func__, relayed.size()); + __func__, relayed_tx_count); } }