1- use crate :: logger:: { log_bytes, log_debug , log_error, log_trace, Logger } ;
1+ use crate :: logger:: { log_bytes, log_error, log_trace, Logger } ;
22
33use lightning:: chain:: chaininterface:: BroadcasterInterface ;
44use lightning:: util:: ser:: Writeable ;
@@ -7,11 +7,11 @@ use esplora_client::AsyncClient as EsploraClient;
77
88use bitcoin:: Transaction ;
99
10+ use reqwest:: StatusCode ;
1011use tokio:: sync:: mpsc;
1112use tokio:: sync:: Mutex ;
1213
1314use std:: ops:: Deref ;
14- use std:: time:: Duration ;
1515
1616const BCAST_PACKAGE_QUEUE_SIZE : usize = 50 ;
1717
@@ -43,36 +43,24 @@ where
4343 log_trace ! ( self . logger, "Successfully broadcast transaction {}" , tx. txid( ) ) ;
4444 } ,
4545 Err ( e) => match e {
46- esplora_client:: Error :: Reqwest ( _) => {
47- // Wait 500 ms and retry in case we get a `Reqwest` error (typically
48- // 429)
49- tokio:: time:: sleep ( Duration :: from_millis ( 500 ) ) . await ;
50- log_error ! (
51- self . logger,
52- "Sync failed due to HTTP connection error, retrying: {}" ,
53- e
54- ) ;
55- match self . esplora_client . broadcast ( tx) . await {
56- Ok ( ( ) ) => {
57- log_debug ! (
58- self . logger,
59- "Successfully broadcast transaction {}" ,
60- tx. txid( )
61- ) ;
62- } ,
63- Err ( e) => {
64- log_error ! (
65- self . logger,
66- "Failed to broadcast transaction {}: {}" ,
67- tx. txid( ) ,
68- e
69- ) ;
70- log_trace ! (
71- self . logger,
72- "Failed broadcast transaction bytes: {}" ,
73- log_bytes!( tx. encode( ) )
74- ) ;
75- } ,
46+ esplora_client:: Error :: Reqwest ( err) => {
47+ if err. status ( ) == StatusCode :: from_u16 ( 400 ) . ok ( ) {
48+ // Ignore 400, as this just means bitcoind already knows the
49+ // transaction.
50+ // FIXME: We can further differentiate here based on the error
51+ // message which will be available with rust-esplora-client 0.7 and
52+ // later.
53+ } else {
54+ log_error ! (
55+ self . logger,
56+ "Failed to broadcast due to HTTP connection error: {}" ,
57+ err
58+ ) ;
59+ log_trace ! (
60+ self . logger,
61+ "Failed broadcast transaction bytes: {}" ,
62+ log_bytes!( tx. encode( ) )
63+ ) ;
7664 }
7765 } ,
7866 _ => {
0 commit comments