From 198a8397557b7a0df16504c46f685f0e1a0d69d6 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Thu, 13 May 2021 13:25:22 -0400 Subject: [PATCH] Don't panic if broadcast_transaction fails due to duplicate broadcasts or from broadcasting too early. --- src/bitcoind_client.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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); + } + } + } }); } } -- 2.30.2