Skip to content

Commit 82ab9ac

Browse files
committed
Drop immediate-retry logic in tx_broadcaster
.. as we're not sure it actually increases reliability. We now only log failures, ignoring HTTP 400 as this is bitcoind's error code for "transaction already in mempool".
1 parent fd4b33f commit 82ab9ac

File tree

1 file changed

+20
-32
lines changed

1 file changed

+20
-32
lines changed

src/tx_broadcaster.rs

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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

33
use lightning::chain::chaininterface::BroadcasterInterface;
44
use lightning::util::ser::Writeable;
@@ -7,11 +7,11 @@ use esplora_client::AsyncClient as EsploraClient;
77

88
use bitcoin::Transaction;
99

10+
use reqwest::StatusCode;
1011
use tokio::sync::mpsc;
1112
use tokio::sync::Mutex;
1213

1314
use std::ops::Deref;
14-
use std::time::Duration;
1515

1616
const 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

Comments
 (0)