Introduce a Channel-specific Err type and return it in a few places
[rust-lightning] / src / ln / channelmonitor.rs
index f3c5c89f6e67cbc1c0e175b75439729385212d33..8d6d23ad00a160b6342eade2dce0fffbf33ca06c 100644 (file)
@@ -759,7 +759,7 @@ impl ChannelMonitor {
                                        ignore_error!(chan_utils::derive_public_key(&self.secp_ctx, &per_commitment_point, &htlc_base_key)))
                                },
                        };
-                       let delayed_key = ignore_error!(chan_utils::derive_public_key(&self.secp_ctx, &PublicKey::from_secret_key(&self.secp_ctx, &per_commitment_key), &self.delayed_payment_base_key));
+                       let delayed_key = ignore_error!(chan_utils::derive_public_key(&self.secp_ctx, &PublicKey::from_secret_key(&self.secp_ctx, &per_commitment_key), &self.their_delayed_payment_base_key.unwrap()));
                        let a_htlc_key = match self.their_htlc_base_key {
                                None => return (txn_to_broadcast, (commitment_txid, watch_outputs)),
                                Some(their_htlc_base_key) => ignore_error!(chan_utils::derive_public_key(&self.secp_ctx, &PublicKey::from_secret_key(&self.secp_ctx, &per_commitment_key), &their_htlc_base_key)),
@@ -856,7 +856,7 @@ impl ChannelMonitor {
                                                };
                                                let sighash_parts = bip143::SighashComponents::new(&single_htlc_tx);
                                                sign_input!(sighash_parts, single_htlc_tx.input[0], Some(idx), htlc.amount_msat / 1000);
-                                               txn_to_broadcast.push(single_htlc_tx); // TODO: This is not yet tested in ChannelManager!
+                                               txn_to_broadcast.push(single_htlc_tx);
                                        }
                                }
                        }
@@ -1011,7 +1011,9 @@ impl ChannelMonitor {
 
        /// Attempst to claim a remote HTLC-Success/HTLC-Timeout s outputs using the revocation key
        fn check_spend_remote_htlc(&self, tx: &Transaction, commitment_number: u64) -> Option<Transaction> {
-               let htlc_txid = tx.txid(); //TODO: This is gonna be a performance bottleneck for watchtowers!
+               if tx.input.len() != 1 || tx.output.len() != 1 {
+                       return None;
+               }
 
                macro_rules! ignore_error {
                        ( $thing : expr ) => {
@@ -1039,6 +1041,7 @@ impl ChannelMonitor {
                };
                let redeemscript = chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.their_to_self_delay.unwrap(), &delayed_key);
                let revokeable_p2wsh = redeemscript.to_v0_p2wsh();
+               let htlc_txid = tx.txid(); //TODO: This is gonna be a performance bottleneck for watchtowers!
 
                let mut inputs = Vec::new();
                let mut amount = 0;