Skip to content

Commit f15f97f

Browse files
committed
Submit packages via esplora
1 parent 0dab102 commit f15f97f

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,6 @@ harness = false
151151
#lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "21e9a9c0ef80021d0669f2a366f55d08ba8d9b03" }
152152
#lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "21e9a9c0ef80021d0669f2a366f55d08ba8d9b03" }
153153
#lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "21e9a9c0ef80021d0669f2a366f55d08ba8d9b03" }
154+
155+
[patch.crates-io]
156+
esplora-client = { git = 'https://github.com/acidbunny21/rust-esplora-client.git', branch = 'submit-tx-pkg-clients' }

src/chain/esplora.rs

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,15 +365,17 @@ impl EsploraChainSource {
365365
}
366366

367367
pub(crate) async fn process_broadcast_package(&self, package: Vec<Transaction>) {
368-
for tx in &package {
368+
if package.len() == 1 {
369+
let tx = &package[0];
369370
let txid = tx.compute_txid();
370371
let timeout_fut = tokio::time::timeout(
371372
Duration::from_secs(TX_BROADCAST_TIMEOUT_SECS),
372373
self.esplora_client.broadcast(tx),
373374
);
374375
match timeout_fut.await {
375376
Ok(res) => match res {
376-
Ok(()) => {
377+
Ok(id) => {
378+
debug_assert_eq!(id, txid);
377379
log_trace!(self.logger, "Successfully broadcast transaction {}", txid);
378380
},
379381
Err(e) => match e {
@@ -432,6 +434,73 @@ impl EsploraChainSource {
432434
);
433435
},
434436
}
437+
} else if package.len() > 1 {
438+
let txids: Vec<_> = package.iter().map(|tx| tx.compute_txid()).collect();
439+
let timeout_fut = tokio::time::timeout(
440+
Duration::from_secs(TX_BROADCAST_TIMEOUT_SECS),
441+
self.esplora_client.submit_package(&package, None, None),
442+
);
443+
match timeout_fut.await {
444+
Ok(res) => match res {
445+
Ok(result) => {
446+
// TODO: We'd like to debug assert here the txids, but we sometimes
447+
// get 0 txids back
448+
log_trace!(self.logger, "Package broadcast result {:?}", result);
449+
},
450+
Err(e) => match e {
451+
esplora_client::Error::HttpResponse { status, message } => {
452+
if status == 400 {
453+
// Log 400 at lesser level, as this often just means bitcoind already knows the
454+
// transaction.
455+
// FIXME: We can further differentiate here based on the error
456+
// message which will be available with rust-esplora-client 0.7 and
457+
// later.
458+
log_trace!(
459+
self.logger,
460+
"Failed to broadcast due to HTTP connection error: {}",
461+
message
462+
);
463+
} else {
464+
log_error!(
465+
self.logger,
466+
"Failed to broadcast due to HTTP connection error: {} - {}",
467+
status,
468+
message
469+
);
470+
}
471+
log_error!(self.logger, "Failed to broadcast package {:?}", txids);
472+
log_trace!(self.logger, "Failed broadcast package bytes:");
473+
for tx in package {
474+
log_trace!(self.logger, "{}", log_bytes!(tx.encode()));
475+
}
476+
},
477+
_ => {
478+
log_error!(
479+
self.logger,
480+
"Failed to broadcast package {:?}: {}",
481+
txids,
482+
e
483+
);
484+
log_trace!(self.logger, "Failed broadcast package bytes:");
485+
for tx in package {
486+
log_trace!(self.logger, "{}", log_bytes!(tx.encode()));
487+
}
488+
},
489+
},
490+
},
491+
Err(e) => {
492+
log_error!(
493+
self.logger,
494+
"Failed to broadcast package due to timeout {:?}: {}",
495+
txids,
496+
e
497+
);
498+
log_trace!(self.logger, "Failed broadcast transaction bytes:");
499+
for tx in package {
500+
log_trace!(self.logger, "{}", log_bytes!(tx.encode()));
501+
}
502+
},
503+
}
435504
}
436505
}
437506
}

0 commit comments

Comments
 (0)