Merge #15728: [wallet] Refactor relay transactions
7a9046e48
[wallet] Refactor CWalletTx::RelayWalletTransaction() (John Newbery) Pull request description: Refactor `CWalletTx::RelayWalletTransaction()` function. This was a suggestion from the wallet-node separation PR: https://github.com/bitcoin/bitcoin/pull/15288#discussion_r256036330, 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: utACK7a9046e48d
. MeshCollider: utACK7a9046e48d
ryanofsky: utACK7a9046e48d
. No changes at all, just rebase after base PR #15632 was merged Tree-SHA512: 2ae6214cfadd917a1b3a892c4277e5e57c3eb791e17f67511470e6fbc634d19356554b9f9c55af6b779fdef821914aad59b7cc9e6c13ece145df003bf507d486
This commit is contained in:
commit
f6120d40d5
2 changed files with 20 additions and 15 deletions
|
@ -1900,21 +1900,26 @@ void CWallet::ReacceptWalletTransactions(interfaces::Chain::Lock& locked_chain)
|
|||
|
||||
bool CWalletTx::RelayWalletTransaction(interfaces::Chain::Lock& locked_chain)
|
||||
{
|
||||
assert(pwallet->GetBroadcastTransactions());
|
||||
if (!IsCoinBase() && !isAbandoned() && GetDepthInMainChain(locked_chain) == 0)
|
||||
{
|
||||
CValidationState state;
|
||||
/* GetDepthInMainChain already catches known conflicts. */
|
||||
if (InMempool() || AcceptToMemoryPool(locked_chain, state)) {
|
||||
// Can't relay if wallet is not broadcasting
|
||||
if (!pwallet->GetBroadcastTransactions()) return false;
|
||||
// Don't relay coinbase transactions outside blocks
|
||||
if (IsCoinBase()) return false;
|
||||
// Don't relay abandoned transactions
|
||||
if (isAbandoned()) return false;
|
||||
// Don't relay conflicted or already confirmed transactions
|
||||
if (GetDepthInMainChain(locked_chain) != 0) return false;
|
||||
// Don't relay transactions that aren't accepted to the mempool
|
||||
CValidationState unused_state;
|
||||
if (!InMempool() && !AcceptToMemoryPool(locked_chain, unused_state)) return false;
|
||||
// Don't try to relay if the node is not connected to the p2p network
|
||||
if (!pwallet->chain().p2pEnabled()) return false;
|
||||
|
||||
// Try to relay the transaction
|
||||
pwallet->WalletLogPrintf("Relaying wtx %s\n", GetHash().ToString());
|
||||
if (pwallet->chain().p2pEnabled()) {
|
||||
pwallet->chain().relayTransaction(GetHash());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::set<uint256> CWalletTx::GetConflicts() const
|
||||
{
|
||||
|
|
|
@ -515,7 +515,7 @@ public:
|
|||
|
||||
int64_t GetTxTime() const;
|
||||
|
||||
// RelayWalletTransaction may only be called if fBroadcastTransactions!
|
||||
// Pass this transaction to the node to relay to its peers
|
||||
bool RelayWalletTransaction(interfaces::Chain::Lock& locked_chain);
|
||||
|
||||
/** Pass this transaction to the mempool. Fails if absolute fee exceeds absurd fee. */
|
||||
|
|
Loading…
Reference in a new issue