Skip to content

Commit ea1a2d8

Browse files
committed
[wallet] Remove ResendWalletTransactionsBefore
This is only called from ResendWalletTransactions(), so bring it inline.
1 parent f516245 commit ea1a2d8

File tree

2 files changed

+21
-39
lines changed

2 files changed

+21
-39
lines changed

src/wallet/wallet.cpp

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,53 +2112,37 @@ bool CWalletTx::IsEquivalentTo(const CWalletTx& _tx) const
21122112
return CTransaction(tx1) == CTransaction(tx2);
21132113
}
21142114

2115-
std::vector<uint256> CWallet::ResendWalletTransactionsBefore(interfaces::Chain::Lock& locked_chain, int64_t nTime)
2116-
{
2117-
std::vector<uint256> result;
2118-
2119-
LOCK(cs_wallet);
2120-
2121-
// Sort them in chronological order
2122-
std::multimap<unsigned int, CWalletTx*> mapSorted;
2123-
for (std::pair<const uint256, CWalletTx>& item : mapWallet)
2124-
{
2125-
CWalletTx& wtx = item.second;
2126-
// Don't rebroadcast if newer than nTime:
2127-
if (wtx.nTimeReceived > nTime)
2128-
continue;
2129-
mapSorted.insert(std::make_pair(wtx.nTimeReceived, &wtx));
2130-
}
2131-
for (const std::pair<const unsigned int, CWalletTx*>& item : mapSorted)
2132-
{
2133-
CWalletTx& wtx = *item.second;
2134-
if (wtx.RelayWalletTransaction(locked_chain)) {
2135-
result.push_back(wtx.GetHash());
2136-
}
2137-
}
2138-
return result;
2139-
}
2140-
21412115
void CWallet::ResendWalletTransactions(interfaces::Chain::Lock& locked_chain, int64_t nBestBlockTime)
21422116
{
21432117
// Do this infrequently and randomly to avoid giving away
21442118
// that these are our transactions.
2145-
if (GetTime() < nNextResend || !fBroadcastTransactions)
2146-
return;
2119+
if (GetTime() < nNextResend || !fBroadcastTransactions) return;
21472120
bool fFirst = (nNextResend == 0);
21482121
nNextResend = GetTime() + GetRand(30 * 60);
2149-
if (fFirst)
2150-
return;
2122+
if (fFirst) return;
21512123

21522124
// Only do it if there's been a new block since last time
2153-
if (nBestBlockTime < nLastResend)
2154-
return;
2125+
if (nBestBlockTime < nLastResend) return;
21552126
nLastResend = GetTime();
21562127

2157-
// Rebroadcast unconfirmed txes older than 5 minutes before the last
2158-
// block was found:
2159-
std::vector<uint256> relayed = ResendWalletTransactionsBefore(locked_chain, nBestBlockTime-5*60);
2160-
if (!relayed.empty())
2161-
WalletLogPrintf("%s: rebroadcast %u unconfirmed transactions\n", __func__, relayed.size());
2128+
int relayed_tx_count = 0;
2129+
2130+
{ // cs_wallet scope
2131+
LOCK(cs_wallet);
2132+
2133+
// Relay transactions
2134+
for (std::pair<const uint256, CWalletTx>& item : mapWallet) {
2135+
CWalletTx& wtx = item.second;
2136+
// only rebroadcast unconfirmed txes older than 5 minutes before the
2137+
// last block was found
2138+
if (wtx.nTimeReceived > nBestBlockTime - 5 * 60) continue;
2139+
relayed_tx_count += wtx.RelayWalletTransaction(locked_chain) ? 1 : 0;
2140+
}
2141+
} // cs_wallet
2142+
2143+
if (relayed_tx_count > 0) {
2144+
WalletLogPrintf("%s: rebroadcast %u unconfirmed transactions\n", __func__, relayed_tx_count);
2145+
}
21622146
}
21632147

21642148
/** @} */ // end of mapWallet

src/wallet/wallet.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,6 @@ class CWallet final : public CCryptoKeyStore, private interfaces::Chain::Notific
947947
void TransactionRemovedFromMempool(const CTransactionRef &ptx) override;
948948
void ReacceptWalletTransactions();
949949
void ResendWalletTransactions(interfaces::Chain::Lock& locked_chain, int64_t nBestBlockTime) override;
950-
// ResendWalletTransactionsBefore may only be called if fBroadcastTransactions!
951-
std::vector<uint256> ResendWalletTransactionsBefore(interfaces::Chain::Lock& locked_chain, int64_t nTime);
952950
CAmount GetBalance(const isminefilter& filter=ISMINE_SPENDABLE, const int min_depth=0) const;
953951
CAmount GetUnconfirmedBalance() const;
954952
CAmount GetImmatureBalance() const;

0 commit comments

Comments
 (0)