aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Newbery <john@johnnewbery.com>2019-03-26 14:56:40 -0400
committerJohn Newbery <john@johnnewbery.com>2019-04-10 09:19:55 -0400
commit7a9046e48d0aac35e8e6a3dd315aa98a207bebfe (patch)
tree8dd5821637fc793f43216f772c226eb3746ce45b /src
parent8c022e8ac401f98c73e6ca62b502b40fc83c3e1f (diff)
[wallet] Refactor CWalletTx::RelayWalletTransaction()
This refactors the CWalletTx::RelayWalletTransaction() function to be clearer and adds comments. It 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).
Diffstat (limited to 'src')
-rw-r--r--src/wallet/wallet.cpp33
-rw-r--r--src/wallet/wallet.h2
2 files changed, 20 insertions, 15 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 9f89cbefa0..642678b4a7 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -1896,20 +1896,25 @@ 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)) {
- pwallet->WalletLogPrintf("Relaying wtx %s\n", GetHash().ToString());
- if (pwallet->chain().p2pEnabled()) {
- pwallet->chain().relayTransaction(GetHash());
- return true;
- }
- }
- }
- return false;
+ // 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());
+ pwallet->chain().relayTransaction(GetHash());
+
+ return true;
}
std::set<uint256> CWalletTx::GetConflicts() const
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index 587b2814c0..ee34c8bfe7 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -535,7 +535,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. */