@@ -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,76 @@ 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: We'd like to debug assert here the txids, but we sometimes
447+ // get 0 txids back
448+ log_trace ! (
449+ self . logger,
450+ "Package broadcast result {:?}" ,
451+ result,
452+ ) ;
453+ } ,
454+ Err ( e) => match e {
455+ esplora_client:: Error :: HttpResponse { status, message } => {
456+ if status == 400 {
457+ // Log 400 at lesser level, as this often just means bitcoind already knows the
458+ // transaction.
459+ // FIXME: We can further differentiate here based on the error
460+ // message which will be available with rust-esplora-client 0.7 and
461+ // later.
462+ log_trace ! (
463+ self . logger,
464+ "Failed to broadcast due to HTTP connection error: {}" ,
465+ message
466+ ) ;
467+ } else {
468+ log_error ! (
469+ self . logger,
470+ "Failed to broadcast due to HTTP connection error: {} - {}" ,
471+ status,
472+ message
473+ ) ;
474+ }
475+ log_trace ! ( self . logger, "Failed broadcast package bytes:" ) ;
476+ for tx in package {
477+ log_trace ! ( self . logger, "{}" , log_bytes!( tx. encode( ) ) ) ;
478+ }
479+ } ,
480+ _ => {
481+ log_error ! (
482+ self . logger,
483+ "Failed to broadcast package {:?}: {}" ,
484+ txids,
485+ e
486+ ) ;
487+ log_trace ! ( self . logger, "Failed broadcast package bytes:" ) ;
488+ for tx in package {
489+ log_trace ! ( self . logger, "{}" , log_bytes!( tx. encode( ) ) ) ;
490+ }
491+ } ,
492+ } ,
493+ } ,
494+ Err ( e) => {
495+ log_error ! (
496+ self . logger,
497+ "Failed to broadcast package due to timeout {:?}: {}" ,
498+ txids,
499+ e
500+ ) ;
501+ log_trace ! ( self . logger, "Failed broadcast transaction bytes:" ) ;
502+ for tx in package {
503+ log_trace ! ( self . logger, "{}" , log_bytes!( tx. encode( ) ) ) ;
504+ }
505+ } ,
506+ }
435507 }
436508 }
437509}
0 commit comments