@@ -18,7 +18,7 @@ use crate::fee_estimator::{
18
18
} ;
19
19
use crate :: io:: utils:: write_node_metrics;
20
20
use 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 } ;
22
22
use crate :: { Error , NodeMetrics } ;
23
23
24
24
use lightning:: chain:: { Confirm , Filter , WatchedOutput } ;
@@ -30,7 +30,7 @@ use bdk_esplora::EsploraAsyncExt;
30
30
31
31
use esplora_client:: AsyncClient as EsploraAsyncClient ;
32
32
33
- use bitcoin:: { FeeRate , Network , Script , Txid } ;
33
+ use bitcoin:: { FeeRate , Network , Script , Transaction , Txid } ;
34
34
35
35
use std:: collections:: HashMap ;
36
36
use std:: sync:: { Arc , Mutex , RwLock } ;
@@ -44,7 +44,6 @@ pub(super) struct EsploraChainSource {
44
44
tx_sync : Arc < EsploraSyncClient < Arc < Logger > > > ,
45
45
lightning_wallet_sync_status : Mutex < WalletSyncStatus > ,
46
46
fee_estimator : Arc < OnchainFeeEstimator > ,
47
- tx_broadcaster : Arc < Broadcaster > ,
48
47
kv_store : Arc < DynStore > ,
49
48
config : Arc < Config > ,
50
49
logger : Arc < Logger > ,
@@ -55,8 +54,8 @@ impl EsploraChainSource {
55
54
pub ( crate ) fn new (
56
55
server_url : String , headers : HashMap < String , String > , sync_config : EsploraSyncConfig ,
57
56
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 > > ,
60
59
) -> Self {
61
60
// FIXME / TODO: We introduced this to make `bdk_esplora` work separately without updating
62
61
// `lightning-transaction-sync`. We should revert this as part of of the upgrade to LDK 0.2.
@@ -90,7 +89,6 @@ impl EsploraChainSource {
90
89
tx_sync,
91
90
lightning_wallet_sync_status,
92
91
fee_estimator,
93
- tx_broadcaster,
94
92
kv_store,
95
93
config,
96
94
logger,
@@ -372,76 +370,73 @@ impl EsploraChainSource {
372
370
Ok ( ( ) )
373
371
}
374
372
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.
410
393
log_trace ! (
411
394
self . logger,
412
- "Failed broadcast transaction bytes : {}" ,
413
- log_bytes! ( tx . encode ( ) )
395
+ "Failed to broadcast due to HTTP connection error : {}" ,
396
+ message
414
397
) ;
415
- } ,
416
- _ => {
398
+ } else {
417
399
log_error ! (
418
400
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
427
404
) ;
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
+ ) ;
429
424
} ,
430
425
} ,
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
+ } ,
445
440
}
446
441
}
447
442
}
0 commit comments