Don't panic if broadcast_transaction fails due to duplicate broadcasts
authorValentine Wallace <vwallace@protonmail.com>
Thu, 13 May 2021 17:25:22 +0000 (13:25 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Mon, 17 May 2021 16:37:46 +0000 (12:37 -0400)
or from broadcasting too early.

src/bitcoind_client.rs

index 7dc67c5fdc51451689798646a5e1b270871c444d..ca4a18134423a17f21636fab53cc8d534e749af0 100644 (file)
@@ -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;
                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::<RawTx>("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::<RawTx>("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);
+                                       }
+                               }
+                       }
                });
        }
 }
                });
        }
 }