@@ -18,7 +18,7 @@ use crate::fee_estimator::{
1818} ;
1919use crate :: io:: utils:: write_node_metrics;
2020use crate :: logger:: { log_bytes, log_error, log_info, log_trace, LdkLogger , Logger } ;
21- use crate :: types:: { Broadcaster , ChainMonitor , ChannelManager , DynStore , Sweeper , Wallet } ;
21+ use crate :: types:: { ChainMonitor , ChannelManager , DynStore , Sweeper , Wallet } ;
2222use crate :: { Error , NodeMetrics } ;
2323
2424use lightning:: chain:: { Confirm , Filter , WatchedOutput } ;
@@ -30,7 +30,7 @@ use bdk_esplora::EsploraAsyncExt;
3030
3131use esplora_client:: AsyncClient as EsploraAsyncClient ;
3232
33- use bitcoin:: { FeeRate , Network , Script , Txid } ;
33+ use bitcoin:: { FeeRate , Network , Script , Transaction , Txid } ;
3434
3535use std:: collections:: HashMap ;
3636use std:: sync:: { Arc , Mutex , RwLock } ;
@@ -44,7 +44,6 @@ pub(super) struct EsploraChainSource {
4444 tx_sync : Arc < EsploraSyncClient < Arc < Logger > > > ,
4545 lightning_wallet_sync_status : Mutex < WalletSyncStatus > ,
4646 fee_estimator : Arc < OnchainFeeEstimator > ,
47- tx_broadcaster : Arc < Broadcaster > ,
4847 kv_store : Arc < DynStore > ,
4948 config : Arc < Config > ,
5049 logger : Arc < Logger > ,
@@ -55,8 +54,8 @@ impl EsploraChainSource {
5554 pub ( crate ) fn new (
5655 server_url : String , headers : HashMap < String , String > , sync_config : EsploraSyncConfig ,
5756 onchain_wallet : Arc < Wallet > , fee_estimator : Arc < OnchainFeeEstimator > ,
58- tx_broadcaster : Arc < Broadcaster > , kv_store : Arc < DynStore > , config : Arc < Config > ,
59- logger : Arc < Logger > , node_metrics : Arc < RwLock < NodeMetrics > > ,
57+ kv_store : Arc < DynStore > , config : Arc < Config > , logger : Arc < Logger > ,
58+ node_metrics : Arc < RwLock < NodeMetrics > > ,
6059 ) -> Self {
6160 // FIXME / TODO: We introduced this to make `bdk_esplora` work separately without updating
6261 // `lightning-transaction-sync`. We should revert this as part of of the upgrade to LDK 0.2.
@@ -90,7 +89,6 @@ impl EsploraChainSource {
9089 tx_sync,
9190 lightning_wallet_sync_status,
9291 fee_estimator,
93- tx_broadcaster,
9492 kv_store,
9593 config,
9694 logger,
@@ -372,76 +370,73 @@ impl EsploraChainSource {
372370 Ok ( ( ) )
373371 }
374372
375- pub ( crate ) async fn process_broadcast_queue ( & self ) {
376- let mut receiver = self . tx_broadcaster . get_broadcast_queue ( ) . await ;
377- while let Some ( next_package) = receiver. recv ( ) . await {
378- for tx in & next_package {
379- let txid = tx. compute_txid ( ) ;
380- let timeout_fut = tokio:: time:: timeout (
381- Duration :: from_secs ( TX_BROADCAST_TIMEOUT_SECS ) ,
382- self . esplora_client . broadcast ( tx) ,
383- ) ;
384- match timeout_fut. await {
385- Ok ( res) => match res {
386- Ok ( ( ) ) => {
387- log_trace ! ( self . logger, "Successfully broadcast transaction {}" , txid) ;
388- } ,
389- Err ( e) => match e {
390- esplora_client:: Error :: HttpResponse { status, message } => {
391- if status == 400 {
392- // Log 400 at lesser level, as this often just means bitcoind already knows the
393- // transaction.
394- // FIXME: We can further differentiate here based on the error
395- // message which will be available with rust-esplora-client 0.7 and
396- // later.
397- log_trace ! (
398- self . logger,
399- "Failed to broadcast due to HTTP connection error: {}" ,
400- message
401- ) ;
402- } else {
403- log_error ! (
404- self . logger,
405- "Failed to broadcast due to HTTP connection error: {} - {}" ,
406- status,
407- message
408- ) ;
409- }
373+ pub ( crate ) async fn process_broadcast_package ( & self , package : Vec < Transaction > ) {
374+ for tx in & package {
375+ let txid = tx. compute_txid ( ) ;
376+ let timeout_fut = tokio:: time:: timeout (
377+ Duration :: from_secs ( TX_BROADCAST_TIMEOUT_SECS ) ,
378+ self . esplora_client . broadcast ( tx) ,
379+ ) ;
380+ match timeout_fut. await {
381+ Ok ( res) => match res {
382+ Ok ( ( ) ) => {
383+ log_trace ! ( self . logger, "Successfully broadcast transaction {}" , txid) ;
384+ } ,
385+ Err ( e) => match e {
386+ esplora_client:: Error :: HttpResponse { status, message } => {
387+ if status == 400 {
388+ // Log 400 at lesser level, as this often just means bitcoind already knows the
389+ // transaction.
390+ // FIXME: We can further differentiate here based on the error
391+ // message which will be available with rust-esplora-client 0.7 and
392+ // later.
410393 log_trace ! (
411394 self . logger,
412- "Failed broadcast transaction bytes : {}" ,
413- log_bytes! ( tx . encode ( ) )
395+ "Failed to broadcast due to HTTP connection error : {}" ,
396+ message
414397 ) ;
415- } ,
416- _ => {
398+ } else {
417399 log_error ! (
418400 self . logger,
419- "Failed to broadcast transaction {}: {}" ,
420- txid,
421- e
422- ) ;
423- log_trace ! (
424- self . logger,
425- "Failed broadcast transaction bytes: {}" ,
426- log_bytes!( tx. encode( ) )
401+ "Failed to broadcast due to HTTP connection error: {} - {}" ,
402+ status,
403+ message
427404 ) ;
428- } ,
405+ }
406+ log_trace ! (
407+ self . logger,
408+ "Failed broadcast transaction bytes: {}" ,
409+ log_bytes!( tx. encode( ) )
410+ ) ;
411+ } ,
412+ _ => {
413+ log_error ! (
414+ self . logger,
415+ "Failed to broadcast transaction {}: {}" ,
416+ txid,
417+ e
418+ ) ;
419+ log_trace ! (
420+ self . logger,
421+ "Failed broadcast transaction bytes: {}" ,
422+ log_bytes!( tx. encode( ) )
423+ ) ;
429424 } ,
430425 } ,
431- Err ( e ) => {
432- log_error ! (
433- self . logger ,
434- "Failed to broadcast transaction due to timeout {}: {}" ,
435- txid ,
436- e
437- ) ;
438- log_trace ! (
439- self . logger ,
440- "Failed broadcast transaction bytes: {}" ,
441- log_bytes! ( tx . encode ( ) )
442- ) ;
443- } ,
444- }
426+ } ,
427+ Err ( e ) => {
428+ log_error ! (
429+ self . logger ,
430+ "Failed to broadcast transaction due to timeout {}: {}" ,
431+ txid ,
432+ e
433+ ) ;
434+ log_trace ! (
435+ self . logger ,
436+ "Failed broadcast transaction bytes: {}" ,
437+ log_bytes! ( tx . encode ( ) )
438+ ) ;
439+ } ,
445440 }
446441 }
447442 }
0 commit comments