Skip to content

Commit b499d85

Browse files
author
MarcoFalke
committed
Merge #16557: [wallet] restore coinbase and confirmed/conflicted checks in SubmitMemoryPoolAndRelay()
c8b53c3 [wallet] Restore confirmed/conflicted tx check in SubmitMemoryPoolAndRelay() (John Newbery) 214c4ec [wallet] restore coinbase check in SubmitMemoryPoolAndRelay() (John Newbery) Pull request description: These checks don't change mempool acceptance/relay behaviour, but reduce log spam. ACKs for top commit: MarcoFalke: ACK c8b53c3 (non-doc changes are mostly a git revert 8753f56) ariard: utACK c8b53c3 Tree-SHA512: f928573ad68d2f70ac69a84b57f352d255dccd1942097cc664f130fcbdcdd7364bc52c43b9157e65ebbaaebbe93586c6e8386f24361b27478e0a23a445677672
2 parents 00dad5e + c8b53c3 commit b499d85

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/wallet/wallet.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,16 +2150,21 @@ 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;
21612161
// Don't relay abandoned transactions
21622162
if (isAbandoned()) return false;
2163+
// Don't try to submit coinbase transactions. These would fail anyway but would
2164+
// cause log spam.
2165+
if (IsCoinBase()) return false;
2166+
// Don't try to submit conflicted or confirmed transactions.
2167+
if (GetDepthInMainChain(locked_chain) != 0) return false;
21632168

21642169
// Submit transaction to mempool for relay
21652170
pwallet->WalletLogPrintf("Submitting wtx %s to mempool for relay\n", GetHash().ToString());
@@ -2374,11 +2379,12 @@ void CWallet::ResendWalletTransactions()
23742379
// Relay transactions
23752380
for (std::pair<const uint256, CWalletTx>& item : mapWallet) {
23762381
CWalletTx& wtx = item.second;
2377-
// only rebroadcast unconfirmed txes older than 5 minutes before the
2378-
// 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.
23792385
if (wtx.nTimeReceived > m_best_block_time - 5 * 60) continue;
23802386
std::string unused_err_string;
2381-
if (wtx.SubmitMemoryPoolAndRelay(unused_err_string, true)) ++submitted_tx_count;
2387+
if (wtx.SubmitMemoryPoolAndRelay(unused_err_string, true, *locked_chain)) ++submitted_tx_count;
23822388
}
23832389
} // locked_chain and cs_wallet
23842390

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

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)