From: Valentine Wallace Date: Thu, 13 May 2021 17:25:22 +0000 (-0400) Subject: Don't panic if broadcast_transaction fails due to duplicate broadcasts X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=198a8397557b7a0df16504c46f685f0e1a0d69d6;p=ldk-sample Don't panic if broadcast_transaction fails due to duplicate broadcasts or from broadcasting too early. --- diff --git a/src/bitcoind_client.rs b/src/bitcoind_client.rs index 7dc67c5..ca4a181 100644 --- a/src/bitcoind_client.rs +++ b/src/bitcoind_client.rs @@ -238,7 +238,20 @@ impl BroadcasterInterface for BitcoindClient { let tx_serialized = serde_json::json!(encode::serialize_hex(tx)); tokio::spawn(async move { let mut rpc = bitcoind_rpc_client.lock().await; - rpc.call_method::("sendrawtransaction", &vec![tx_serialized]).await.unwrap(); + // This may error due to RL calling `broadcast_transaction` with the same transaction + // multiple times, but the error is safe to ignore. + match rpc.call_method::("sendrawtransaction", &vec![tx_serialized]).await { + Ok(_) => {} + Err(e) => { + let err_str = e.get_ref().unwrap().to_string(); + if !err_str.contains("Transaction already in block chain") + && !err_str.contains("Inputs missing or spent") + && !err_str.contains("non-BIP68-final") + { + panic!("{}", e); + } + } + } }); } }