@@ -314,32 +314,29 @@ impl FeeEstimator for BitcoindClient {
314314
315315impl BroadcasterInterface for BitcoindClient {
316316 fn broadcast_transactions ( & self , txs : & [ & Transaction ] ) {
317- // TODO: Rather than calling `sendrawtransaction` in a a loop, we should probably use
318- // `submitpackage` once it becomes available.
319- for tx in txs {
320- let bitcoind_rpc_client = Arc :: clone ( & self . bitcoind_rpc_client ) ;
321- let tx_serialized = encode:: serialize_hex ( tx) ;
322- let tx_json = serde_json:: json!( tx_serialized) ;
323- let logger = Arc :: clone ( & self . logger ) ;
324- self . handle . spawn ( async move {
325- // This may error due to RL calling `broadcast_transactions` with the same transaction
326- // multiple times, but the error is safe to ignore.
327- match bitcoind_rpc_client
328- . call_method :: < Txid > ( "sendrawtransaction" , & vec ! [ tx_json] )
329- . await
330- {
331- Ok ( _) => { }
332- Err ( e) => {
333- let err_str = e. get_ref ( ) . unwrap ( ) . to_string ( ) ;
334- log_error ! ( logger,
335- "Warning, failed to broadcast a transaction, this is likely okay but may indicate an error: {}\n Transaction: {}" ,
336- err_str,
337- tx_serialized) ;
338- print ! ( "Warning, failed to broadcast a transaction, this is likely okay but may indicate an error: {}\n > " , err_str) ;
339- }
317+ // We assume `submitpackage` is available (Bitcoin Core 25, at least).
318+ let txn = txs. iter ( ) . map ( |tx| encode:: serialize_hex ( tx) ) . collect :: < Vec < _ > > ( ) ;
319+ let bitcoind_rpc_client = Arc :: clone ( & self . bitcoind_rpc_client ) ;
320+ let tx_json = serde_json:: json!( txn) ;
321+ let logger = Arc :: clone ( & self . logger ) ;
322+ self . handle . spawn ( async move {
323+ // This may error due to RL calling `broadcast_transactions` with the same transaction
324+ // multiple times, but the error is safe to ignore.
325+ match bitcoind_rpc_client
326+ . call_method :: < Txid > ( "submitpackage" , & vec ! [ tx_json] )
327+ . await
328+ {
329+ Ok ( _) => { }
330+ Err ( e) => {
331+ let err_str = e. get_ref ( ) . unwrap ( ) . to_string ( ) ;
332+ log_error ! ( logger,
333+ "Warning, failed to broadcast a transaction, this is likely okay but may indicate an error: {}\n Transactions: {:?}" ,
334+ err_str,
335+ txn) ;
336+ print ! ( "Warning, failed to broadcast a transaction, this is likely okay but may indicate an error: {}\n > " , err_str) ;
340337 }
341- } ) ;
342- }
338+ }
339+ } ) ;
343340 }
344341}
345342
0 commit comments