]> git.bitcoin.ninja Git - ldk-sample/commitdiff
Don't panic on tx broadcast failures
authorMatt Corallo <git@bluematt.me>
Thu, 23 Mar 2023 19:14:08 +0000 (19:14 +0000)
committerMatt Corallo <git@bluematt.me>
Sat, 25 Mar 2023 01:39:47 +0000 (01:39 +0000)
In general LDK will often broadcast transactions which aren't
actually able to get into the mempool. That's generally fine,
though could indicate a significant issue. Thus, we previously had
a panic in place for it to ensure developers are notified and we
can investigate.

However, now that people are trying to actually *use* ldk-sample,
we should just remove the panic and print something with more
details.

src/bitcoind_client.rs

index d8315ac159c3e92b8014c52e3f8dd38e11aa473d..e7a3cec4cd441eda4cf9765149d522840f6d24ba 100644 (file)
@@ -254,27 +254,24 @@ impl FeeEstimator for BitcoindClient {
 impl BroadcasterInterface for BitcoindClient {
        fn broadcast_transaction(&self, tx: &Transaction) {
                let bitcoind_rpc_client = self.bitcoind_rpc_client.clone();
-               let tx_serialized = serde_json::json!(encode::serialize_hex(tx));
+               let tx_serialized = encode::serialize_hex(tx);
+               let tx_json = serde_json::json!(tx_serialized);
                let logger = Arc::clone(&self.logger);
                self.handle.spawn(async move {
                        // This may error due to RL calling `broadcast_transaction` with the same transaction
                        // multiple times, but the error is safe to ignore.
                        match bitcoind_rpc_client
-                               .call_method::<Txid>("sendrawtransaction", &vec![tx_serialized])
+                               .call_method::<Txid>("sendrawtransaction", &vec![tx_json])
                                .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("bad-txns-inputs-missingorspent")
-                                               && !err_str.contains("txn-mempool-conflict")
-                                               && !err_str.contains("non-BIP68-final")
-                                               && !err_str.contains("insufficient fee, rejecting replacement ")
-                                       {
-                                               panic!("{}", e);
-                                       }
+                                       log_error!(logger,
+                                               "Warning, failed to broadcast a transaction, this is likely okay but may indicate an error: {}\nTransaction: {}",
+                                               err_str,
+                                               tx_serialized);
+                                       print!("Warning, failed to broadcast a transaction, this is likely okay but may indicate an error: {}\n> ", err_str);
                                }
                        }
                });