@@ -365,15 +365,17 @@ impl EsploraChainSource {
365365 }
366366
367367 pub ( crate ) async fn process_broadcast_package ( & self , package : Vec < Transaction > ) {
368- for tx in & package {
368+ if package. len ( ) == 1 {
369+ let tx = & package[ 0 ] ;
369370 let txid = tx. compute_txid ( ) ;
370371 let timeout_fut = tokio:: time:: timeout (
371372 Duration :: from_secs ( TX_BROADCAST_TIMEOUT_SECS ) ,
372373 self . esplora_client . broadcast ( tx) ,
373374 ) ;
374375 match timeout_fut. await {
375376 Ok ( res) => match res {
376- Ok ( ( ) ) => {
377+ Ok ( id) => {
378+ debug_assert_eq ! ( id, txid) ;
377379 log_trace ! ( self . logger, "Successfully broadcast transaction {}" , txid) ;
378380 } ,
379381 Err ( e) => match e {
@@ -432,6 +434,78 @@ impl EsploraChainSource {
432434 ) ;
433435 } ,
434436 }
437+ } else if package. len ( ) > 1 {
438+ let txids: Vec < _ > = package. iter ( ) . map ( |tx| tx. compute_txid ( ) ) . collect ( ) ;
439+ let timeout_fut = tokio:: time:: timeout (
440+ Duration :: from_secs ( TX_BROADCAST_TIMEOUT_SECS ) ,
441+ self . esplora_client . submit_package ( & package, None , None ) ,
442+ ) ;
443+ match timeout_fut. await {
444+ Ok ( res) => match res {
445+ Ok ( result) => {
446+ // TODO: sometimes, we get 0 ids back...
447+ let _ids: Vec < _ > =
448+ result. tx_results . values ( ) . map ( |value| value. txid ) . collect ( ) ;
449+ log_trace ! (
450+ self . logger,
451+ "Package broadcast message {}, txids: {:?}" ,
452+ result. package_msg,
453+ txids,
454+ ) ;
455+ } ,
456+ Err ( e) => match e {
457+ esplora_client:: Error :: HttpResponse { status, message } => {
458+ if status == 400 {
459+ // Log 400 at lesser level, as this often just means bitcoind already knows the
460+ // transaction.
461+ // FIXME: We can further differentiate here based on the error
462+ // message which will be available with rust-esplora-client 0.7 and
463+ // later.
464+ log_trace ! (
465+ self . logger,
466+ "Failed to broadcast due to HTTP connection error: {}" ,
467+ message
468+ ) ;
469+ } else {
470+ log_error ! (
471+ self . logger,
472+ "Failed to broadcast due to HTTP connection error: {} - {}" ,
473+ status,
474+ message
475+ ) ;
476+ }
477+ log_trace ! ( self . logger, "Failed broadcast package bytes:" ) ;
478+ for tx in package {
479+ log_trace ! ( self . logger, "{}" , log_bytes!( tx. encode( ) ) ) ;
480+ }
481+ } ,
482+ _ => {
483+ log_error ! (
484+ self . logger,
485+ "Failed to broadcast package {:?}: {}" ,
486+ txids,
487+ e
488+ ) ;
489+ log_trace ! ( self . logger, "Failed broadcast package bytes:" ) ;
490+ for tx in package {
491+ log_trace ! ( self . logger, "{}" , log_bytes!( tx. encode( ) ) ) ;
492+ }
493+ } ,
494+ } ,
495+ } ,
496+ Err ( e) => {
497+ log_error ! (
498+ self . logger,
499+ "Failed to broadcast package due to timeout {:?}: {}" ,
500+ txids,
501+ e
502+ ) ;
503+ log_trace ! ( self . logger, "Failed broadcast transaction bytes:" ) ;
504+ for tx in package {
505+ log_trace ! ( self . logger, "{}" , log_bytes!( tx. encode( ) ) ) ;
506+ }
507+ } ,
508+ }
435509 }
436510 }
437511}
0 commit comments