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