Skip to content

Commit f6120d4

Browse files
committed
Merge #15728: [wallet] Refactor relay transactions
7a9046e [wallet] Refactor CWalletTx::RelayWalletTransaction() (John Newbery) Pull request description: Refactor `CWalletTx::RelayWalletTransaction()` function. This was a suggestion from the wallet-node separation PR: bitcoin/bitcoin#15288 (comment), which we deferred until after the main PR was merged. There are also makes two minor behavior changes: - no longer assert if fBroadcastTransactions is false. Just return false from the function. - no longer print the relay message if p2pEnabled is set to false (since the transaction is not actually relayed). ACKs for commit 7a9046: promag: utACK 7a9046e. MeshCollider: utACK bitcoin/bitcoin@7a9046e ryanofsky: utACK 7a9046e. No changes at all, just rebase after base PR #15632 was merged Tree-SHA512: 2ae6214cfadd917a1b3a892c4277e5e57c3eb791e17f67511470e6fbc634d19356554b9f9c55af6b779fdef821914aad59b7cc9e6c13ece145df003bf507d486
2 parents 6a135fb + 7a9046e commit f6120d4

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

src/wallet/wallet.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,20 +1900,25 @@ void CWallet::ReacceptWalletTransactions(interfaces::Chain::Lock& locked_chain)
19001900

19011901
bool CWalletTx::RelayWalletTransaction(interfaces::Chain::Lock& locked_chain)
19021902
{
1903-
assert(pwallet->GetBroadcastTransactions());
1904-
if (!IsCoinBase() && !isAbandoned() && GetDepthInMainChain(locked_chain) == 0)
1905-
{
1906-
CValidationState state;
1907-
/* GetDepthInMainChain already catches known conflicts. */
1908-
if (InMempool() || AcceptToMemoryPool(locked_chain, state)) {
1909-
pwallet->WalletLogPrintf("Relaying wtx %s\n", GetHash().ToString());
1910-
if (pwallet->chain().p2pEnabled()) {
1911-
pwallet->chain().relayTransaction(GetHash());
1912-
return true;
1913-
}
1914-
}
1915-
}
1916-
return false;
1903+
// Can't relay if wallet is not broadcasting
1904+
if (!pwallet->GetBroadcastTransactions()) return false;
1905+
// Don't relay coinbase transactions outside blocks
1906+
if (IsCoinBase()) return false;
1907+
// Don't relay abandoned transactions
1908+
if (isAbandoned()) return false;
1909+
// Don't relay conflicted or already confirmed transactions
1910+
if (GetDepthInMainChain(locked_chain) != 0) return false;
1911+
// Don't relay transactions that aren't accepted to the mempool
1912+
CValidationState unused_state;
1913+
if (!InMempool() && !AcceptToMemoryPool(locked_chain, unused_state)) return false;
1914+
// Don't try to relay if the node is not connected to the p2p network
1915+
if (!pwallet->chain().p2pEnabled()) return false;
1916+
1917+
// Try to relay the transaction
1918+
pwallet->WalletLogPrintf("Relaying wtx %s\n", GetHash().ToString());
1919+
pwallet->chain().relayTransaction(GetHash());
1920+
1921+
return true;
19171922
}
19181923

19191924
std::set<uint256> CWalletTx::GetConflicts() const

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ class CWalletTx : public CMerkleTx
515515

516516
int64_t GetTxTime() const;
517517

518-
// RelayWalletTransaction may only be called if fBroadcastTransactions!
518+
// Pass this transaction to the node to relay to its peers
519519
bool RelayWalletTransaction(interfaces::Chain::Lock& locked_chain);
520520

521521
/** Pass this transaction to the mempool. Fails if absolute fee exceeds absurd fee. */

0 commit comments

Comments
 (0)