Skip to content

Commit c8b53c3

Browse files
committed
[wallet] Restore confirmed/conflicted tx check in SubmitMemoryPoolAndRelay()
Restores the confirmed/conflicted tx check removed in 8753f56. There should be no external behaviour change (these txs would not get accepted to the mempool anyway), but not having the check in the wallet causes log spam. Also adds a comment to ResentWalletTransactions() that confirmed/conflicted tx check is done in SubmitMemoryPoolAndRelay().
1 parent 214c4ec commit c8b53c3

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/wallet/wallet.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,11 +2150,11 @@ void CWallet::ReacceptWalletTransactions(interfaces::Chain::Lock& locked_chain)
21502150
for (const std::pair<const int64_t, CWalletTx*>& item : mapSorted) {
21512151
CWalletTx& wtx = *(item.second);
21522152
std::string unused_err_string;
2153-
wtx.SubmitMemoryPoolAndRelay(unused_err_string, false);
2153+
wtx.SubmitMemoryPoolAndRelay(unused_err_string, false, locked_chain);
21542154
}
21552155
}
21562156

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)
21582158
{
21592159
// Can't relay if wallet is not broadcasting
21602160
if (!pwallet->GetBroadcastTransactions()) return false;
@@ -2163,6 +2163,8 @@ bool CWalletTx::SubmitMemoryPoolAndRelay(std::string& err_string, bool relay)
21632163
// Don't try to submit coinbase transactions. These would fail anyway but would
21642164
// cause log spam.
21652165
if (IsCoinBase()) return false;
2166+
// Don't try to submit conflicted or confirmed transactions.
2167+
if (GetDepthInMainChain(locked_chain) != 0) return false;
21662168

21672169
// Submit transaction to mempool for relay
21682170
pwallet->WalletLogPrintf("Submitting wtx %s to mempool for relay\n", GetHash().ToString());
@@ -2377,11 +2379,12 @@ void CWallet::ResendWalletTransactions()
23772379
// Relay transactions
23782380
for (std::pair<const uint256, CWalletTx>& item : mapWallet) {
23792381
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.
23822385
if (wtx.nTimeReceived > m_best_block_time - 5 * 60) continue;
23832386
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;
23852388
}
23862389
} // locked_chain and cs_wallet
23872390

@@ -3326,7 +3329,7 @@ bool CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::ve
33263329
if (fBroadcastTransactions)
33273330
{
33283331
std::string err_string;
3329-
if (!wtx.SubmitMemoryPoolAndRelay(err_string, true)) {
3332+
if (!wtx.SubmitMemoryPoolAndRelay(err_string, true, *locked_chain)) {
33303333
WalletLogPrintf("CommitTransaction(): Transaction cannot be broadcast immediately, %s\n", err_string);
33313334
// TODO: if we expect the failure to be long term or permanent, instead delete wtx from the wallet and return failure.
33323335
}

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ class CWalletTx
580580
int64_t GetTxTime() const;
581581

582582
// Pass this transaction to node for mempool insertion and relay to peers if flag set to true
583-
bool SubmitMemoryPoolAndRelay(std::string& err_string, bool relay);
583+
bool SubmitMemoryPoolAndRelay(std::string& err_string, bool relay, interfaces::Chain::Lock& locked_chain);
584584

585585
// TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct
586586
// annotation "EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)". The annotation

0 commit comments

Comments
 (0)