@@ -1959,7 +1959,9 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
19591959 return result;
19601960}
19611961
1962- bool CWallet::SubmitTxMemoryPoolAndRelay (CWalletTx& wtx, std::string& err_string, bool relay) const
1962+ bool CWallet::SubmitTxMemoryPoolAndRelay (CWalletTx& wtx,
1963+ std::string& err_string,
1964+ node::TxBroadcast broadcast_method) const
19631965{
19641966 AssertLockHeld (cs_wallet);
19651967
@@ -1973,8 +1975,16 @@ bool CWallet::SubmitTxMemoryPoolAndRelay(CWalletTx& wtx, std::string& err_string
19731975 // Don't try to submit conflicted or confirmed transactions.
19741976 if (GetTxDepthInMainChain (wtx) != 0 ) return false ;
19751977
1976- // Submit transaction to mempool for relay
1977- WalletLogPrintf (" Submitting wtx %s to mempool for relay\n " , wtx.GetHash ().ToString ());
1978+ const char * what{" " };
1979+ switch (broadcast_method) {
1980+ case node::TxBroadcast::MEMPOOL_AND_BROADCAST_TO_ALL:
1981+ what = " to mempool and for broadcast to peers" ;
1982+ break ;
1983+ case node::TxBroadcast::MEMPOOL_NO_BROADCAST:
1984+ what = " to mempool without broadcast" ;
1985+ break ;
1986+ }
1987+ WalletLogPrintf (" Submitting wtx %s %s\n " , wtx.GetHash ().ToString (), what);
19781988 // We must set TxStateInMempool here. Even though it will also be set later by the
19791989 // entered-mempool callback, if we did not there would be a race where a
19801990 // user could call sendmoney in a loop and hit spurious out of funds errors
@@ -1984,7 +1994,7 @@ bool CWallet::SubmitTxMemoryPoolAndRelay(CWalletTx& wtx, std::string& err_string
19841994 // If broadcast fails for any reason, trying to set wtx.m_state here would be incorrect.
19851995 // If transaction was previously in the mempool, it should be updated when
19861996 // TransactionRemovedFromMempool fires.
1987- bool ret = chain ().broadcastTransaction (wtx.tx , m_default_max_tx_fee, relay , err_string);
1997+ bool ret = chain ().broadcastTransaction (wtx.tx , m_default_max_tx_fee, broadcast_method , err_string);
19881998 if (ret) wtx.m_state = TxStateInMempool{};
19891999 return ret;
19902000}
@@ -2039,10 +2049,11 @@ NodeClock::time_point CWallet::GetDefaultNextResend() { return FastRandomContext
20392049//
20402050// The `force` option results in all unconfirmed transactions being submitted to
20412051// the mempool. This does not necessarily result in those transactions being relayed,
2042- // that depends on the `relay` option. Periodic rebroadcast uses the pattern
2043- // relay=true force=false, while loading into the mempool
2044- // (on start, or after import) uses relay=false force=true.
2045- void CWallet::ResubmitWalletTransactions (bool relay, bool force)
2052+ // that depends on the `broadcast_method` option. Periodic rebroadcast uses the pattern
2053+ // broadcast_method=TxBroadcast::MEMPOOL_AND_BROADCAST_TO_ALL force=false, while loading into
2054+ // the mempool (on start, or after import) uses
2055+ // broadcast_method=TxBroadcast::MEMPOOL_NO_BROADCAST force=true.
2056+ void CWallet::ResubmitWalletTransactions (node::TxBroadcast broadcast_method, bool force)
20462057{
20472058 // Don't attempt to resubmit if the wallet is configured to not broadcast,
20482059 // even if forcing.
@@ -2068,7 +2079,7 @@ void CWallet::ResubmitWalletTransactions(bool relay, bool force)
20682079 // Now try submitting the transactions to the memory pool and (optionally) relay them.
20692080 for (auto wtx : to_submit) {
20702081 std::string unused_err_string;
2071- if (SubmitTxMemoryPoolAndRelay (*wtx, unused_err_string, relay )) ++submitted_tx_count;
2082+ if (SubmitTxMemoryPoolAndRelay (*wtx, unused_err_string, broadcast_method )) ++submitted_tx_count;
20722083 }
20732084 } // cs_wallet
20742085
@@ -2083,7 +2094,7 @@ void MaybeResendWalletTxs(WalletContext& context)
20832094{
20842095 for (const std::shared_ptr<CWallet>& pwallet : GetWallets (context)) {
20852096 if (!pwallet->ShouldResend ()) continue ;
2086- pwallet->ResubmitWalletTransactions (/* relay= */ true , /* force=*/ false );
2097+ pwallet->ResubmitWalletTransactions (node::TxBroadcast::MEMPOOL_AND_BROADCAST_TO_ALL , /* force=*/ false );
20872098 pwallet->SetNextResend ();
20882099 }
20892100}
@@ -2284,7 +2295,7 @@ void CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::ve
22842295 }
22852296
22862297 std::string err_string;
2287- if (!SubmitTxMemoryPoolAndRelay (*wtx, err_string, true )) {
2298+ if (!SubmitTxMemoryPoolAndRelay (*wtx, err_string, node::TxBroadcast::MEMPOOL_AND_BROADCAST_TO_ALL )) {
22882299 WalletLogPrintf (" CommitTransaction(): Transaction cannot be broadcast immediately, %s\n " , err_string);
22892300 // TODO: if we expect the failure to be long term or permanent, instead delete wtx from the wallet and return failure.
22902301 }
@@ -3233,7 +3244,7 @@ void CWallet::postInitProcess()
32333244{
32343245 // Add wallet transactions that aren't already in a block to mempool
32353246 // Do this here as mempool requires genesis block to be loaded
3236- ResubmitWalletTransactions (/* relay= */ false , /* force=*/ true );
3247+ ResubmitWalletTransactions (node::TxBroadcast::MEMPOOL_NO_BROADCAST , /* force=*/ true );
32373248
32383249 // Update wallet transactions with current mempool transactions.
32393250 WITH_LOCK (cs_wallet, chain ().requestMempoolTransactions (*this ));
0 commit comments