Skip to content

Commit 8753f56

Browse files
author
Antoine Riard
committed
Remove duplicate checks in SubmitMemoryPoolAndRelay
IsCoinBase check is already performed early by AcceptToMemoryPoolWorker GetDepthInMainChain check is already perfomed by BroadcastTransaction To avoid deadlock we MUST keep lock order in ResendWalletTransactions and CommitTransaction, even if we lock cs_main again further. in BroadcastTransaction. Lock order will need to be clean at once in a future refactoring
1 parent 611291c commit 8753f56

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/wallet/wallet.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,20 +2150,16 @@ 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, locked_chain);
2153+
wtx.SubmitMemoryPoolAndRelay(unused_err_string, false);
21542154
}
21552155
}
21562156

2157-
bool CWalletTx::SubmitMemoryPoolAndRelay(std::string& err_string, bool relay, interfaces::Chain::Lock& locked_chain)
2157+
bool CWalletTx::SubmitMemoryPoolAndRelay(std::string& err_string, bool relay)
21582158
{
21592159
// Can't relay if wallet is not broadcasting
21602160
if (!pwallet->GetBroadcastTransactions()) return false;
2161-
// Don't relay coinbase transactions outside blocks
2162-
if (IsCoinBase()) return false;
21632161
// Don't relay abandoned transactions
21642162
if (isAbandoned()) return false;
2165-
// Don't relay conflicted or already confirmed transactions
2166-
if (GetDepthInMainChain(locked_chain) != 0) return false;
21672163

21682164
// Submit transaction to mempool for relay
21692165
pwallet->WalletLogPrintf("Submitting wtx %s to mempool for relay\n", GetHash().ToString());
@@ -2382,7 +2378,7 @@ void CWallet::ResendWalletTransactions()
23822378
// last block was found
23832379
if (wtx.nTimeReceived > m_best_block_time - 5 * 60) continue;
23842380
std::string unused_err_string;
2385-
if (wtx.SubmitMemoryPoolAndRelay(unused_err_string, true, *locked_chain)) ++submitted_tx_count;
2381+
if (wtx.SubmitMemoryPoolAndRelay(unused_err_string, true)) ++submitted_tx_count;
23862382
}
23872383
} // locked_chain and cs_wallet
23882384

@@ -3327,7 +3323,7 @@ bool CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::ve
33273323
if (fBroadcastTransactions)
33283324
{
33293325
std::string err_string;
3330-
if (!wtx.SubmitMemoryPoolAndRelay(err_string, true, *locked_chain)) {
3326+
if (!wtx.SubmitMemoryPoolAndRelay(err_string, true)) {
33313327
WalletLogPrintf("CommitTransaction(): Transaction cannot be broadcast immediately, %s\n", err_string);
33323328
// TODO: if we expect the failure to be long term or permanent, instead delete wtx from the wallet and return failure.
33333329
}

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, interfaces::Chain::Lock& locked_chain);
583+
bool SubmitMemoryPoolAndRelay(std::string& err_string, bool relay);
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)