1
- use crate :: logger:: { log_bytes, log_debug , log_error, log_trace, Logger } ;
1
+ use crate :: logger:: { log_bytes, log_error, log_trace, Logger } ;
2
2
3
3
use lightning:: chain:: chaininterface:: BroadcasterInterface ;
4
4
use lightning:: util:: ser:: Writeable ;
@@ -7,11 +7,11 @@ use esplora_client::AsyncClient as EsploraClient;
7
7
8
8
use bitcoin:: Transaction ;
9
9
10
+ use reqwest:: StatusCode ;
10
11
use tokio:: sync:: mpsc;
11
12
use tokio:: sync:: Mutex ;
12
13
13
14
use std:: ops:: Deref ;
14
- use std:: time:: Duration ;
15
15
16
16
const BCAST_PACKAGE_QUEUE_SIZE : usize = 50 ;
17
17
@@ -43,36 +43,24 @@ where
43
43
log_trace ! ( self . logger, "Successfully broadcast transaction {}" , tx. txid( ) ) ;
44
44
} ,
45
45
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
+ ) ;
76
64
}
77
65
} ,
78
66
_ => {
0 commit comments