merge bitcoin#15728: Refactor relay transactions

This commit is contained in:
Kittywhiskers Van Gogh 2021-12-12 19:08:12 +05:30
parent 11fc0f5667
commit ee4f2fc8b4
2 changed files with 20 additions and 15 deletions

View File

@ -2284,20 +2284,25 @@ void CWallet::ReacceptWalletTransactions()
bool CWalletTx::RelayWalletTransaction(interfaces::Chain::Lock& locked_chain) bool CWalletTx::RelayWalletTransaction(interfaces::Chain::Lock& locked_chain)
{ {
assert(pwallet->GetBroadcastTransactions()); // Can't relay if wallet is not broadcasting
if (!IsCoinBase() && !isAbandoned() && GetDepthInMainChain(locked_chain) == 0) if (!pwallet->GetBroadcastTransactions()) return false;
{ // Don't relay coinbase transactions outside blocks
CValidationState state; if (IsCoinBase()) return false;
/* GetDepthInMainChain already catches known conflicts. */ // Don't relay abandoned transactions
if (InMempool() || AcceptToMemoryPool(locked_chain, state)) { if (isAbandoned()) return false;
pwallet->WalletLogPrintf("Relaying wtx %s\n", GetHash().ToString()); // Don't relay conflicted or already confirmed transactions
if (pwallet->chain().p2pEnabled()) { if (GetDepthInMainChain(locked_chain) != 0) return false;
pwallet->chain().relayTransaction(GetHash()); // Don't relay transactions that aren't accepted to the mempool
return true; 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;
return false;
// Try to relay the transaction
pwallet->WalletLogPrintf("Relaying wtx %s\n", GetHash().ToString());
pwallet->chain().relayTransaction(GetHash());
return true;
} }
std::set<uint256> CWalletTx::GetConflicts() const std::set<uint256> CWalletTx::GetConflicts() const

View File

@ -520,7 +520,7 @@ public:
int64_t GetTxTime() const; 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); bool RelayWalletTransaction(interfaces::Chain::Lock& locked_chain);
/** Pass this transaction to the mempool. Fails if absolute fee exceeds absurd fee. */ /** Pass this transaction to the mempool. Fails if absolute fee exceeds absurd fee. */