Skip to content

Commit 0657345

Browse files
committed
Submit packages via esplora
1 parent c41f348 commit 0657345

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
@@ -157,3 +157,6 @@ harness = false
157157

158158
#vss-client-ng = { path = "../vss-client" }
159159
#vss-client-ng = { git = "https://github.com/lightningdevkit/vss-client", branch = "main" }
160+
161+
[patch.crates-io]
162+
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
@@ -364,15 +364,17 @@ impl EsploraChainSource {
364364
}
365365

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

0 commit comments

Comments
 (0)