Originally posted as a comment here: #15713 (comment)
We should better define the relationship between the wallet and the node, ie answer the question "What services should the node offer to the wallet?" Currently, the node exposes two methods to the wallet for sending a transaction:
submitToMemoryPool(const CTransactionRef& tx, CAmount absurd_fee, CValidationState& state): Add transaction to memory pool if the transaction fee is below the amount specified by absurd_fee. Returns false if the transaction could not be added due to the fee or for another reason. This is only called inCWalletTx::AcceptToMemoryPool()relayTransaction(const uint256& txid): adds the txid to the INV queue for each peer. This is only called inCWalletTx::RelayWalletTransaction()(which also callsCWalletTx::AcceptToMemoryPool())
Note that to relay an INV for the transaction to peers (2), the transaction must already be in the mempool. See:
relayTransaction() is only ever called if InMempool() || AcceptToMemoryPool() is true.
The wallet currently calls CWalletTx::AcceptToMemoryPool() in the following places:
1a. In CWallet::ReacceptWalletTransactions(), called after the wallet has started up to make sure that its transactions are added to the mempool at start.
2a. In CWalletTx::RelayWalletTransaction(), mentioned above.
3a. In CWallet::CommitTransaction(), when a transaction is to be broadcast to the network for the first time.
The wallet currently calls CWalletTx::RelayWalletTransaction() in the following places:
2a. In CWallet::ResendWalletTransactions(), called on a timer to rebroadcast unconfirmed transactions.
2b. In CWallet::CommitTransaction(), but only if the transaction is successfully added to the mempool.
I've been thinking about this in the context of the wallet rebroadcasting transactions (see discussion here: http://www.erisian.com.au/meetbot/bitcoin-core-dev/2019/bitcoin-core-dev.2019-03-29-19.10.log.html#l-9). My view now is that the wallet should not have any access to relay functionality. It should be able to submit transactions to the node's mempool, and it should then be the mempool's responsibility to broadcast/rebroadcast the transaction (see comment here: http://www.erisian.com.au/meetbot/bitcoin-core-dev/2019/bitcoin-core-dev.2019-03-29-19.10.log.html#l-92). That seems like a much cleaner divide of responsibility.