Merge pull request #13 from TheBlueMatt/2018-03-htlc-failures
[rust-lightning] / src / ln / channel.rs
index 285cdf7b418a888033438e9ad33e86d792eb88a6..ef73db8eb813b2dea164cc00a4b245924c1898a1 100644 (file)
@@ -7,8 +7,6 @@ use bitcoin::util::hash::{Sha256dHash, Hash160};
 use bitcoin::util::bip143;
 use bitcoin::network::serialize::BitcoinHash;
 
-use num::FromPrimitive;
-
 use secp256k1::key::{PublicKey,SecretKey};
 use secp256k1::{Secp256k1,Message,Signature};
 use secp256k1;
@@ -52,25 +50,25 @@ impl ChannelKeys {
 
                let mut okm = [0; 32];
                hkdf_expand(sha, &prk, b"rust-lightning funding key info", &mut okm);
-               let funding_key = try!(SecretKey::from_slice(&secp_ctx, &okm));
+               let funding_key = SecretKey::from_slice(&secp_ctx, &okm)?;
 
                hkdf_expand(sha, &prk, b"rust-lightning revocation base key info", &mut okm);
-               let revocation_base_key = try!(SecretKey::from_slice(&secp_ctx, &okm));
+               let revocation_base_key = SecretKey::from_slice(&secp_ctx, &okm)?;
 
                hkdf_expand(sha, &prk, b"rust-lightning payment base key info", &mut okm);
-               let payment_base_key = try!(SecretKey::from_slice(&secp_ctx, &okm));
+               let payment_base_key = SecretKey::from_slice(&secp_ctx, &okm)?;
 
                hkdf_expand(sha, &prk, b"rust-lightning delayed payment base key info", &mut okm);
-               let delayed_payment_base_key = try!(SecretKey::from_slice(&secp_ctx, &okm));
+               let delayed_payment_base_key = SecretKey::from_slice(&secp_ctx, &okm)?;
 
                hkdf_expand(sha, &prk, b"rust-lightning htlc base key info", &mut okm);
-               let htlc_base_key = try!(SecretKey::from_slice(&secp_ctx, &okm));
+               let htlc_base_key = SecretKey::from_slice(&secp_ctx, &okm)?;
 
                hkdf_expand(sha, &prk, b"rust-lightning channel close key info", &mut okm);
-               let channel_close_key = try!(SecretKey::from_slice(&secp_ctx, &okm));
+               let channel_close_key = SecretKey::from_slice(&secp_ctx, &okm)?;
 
                hkdf_expand(sha, &prk, b"rust-lightning channel monitor claim key info", &mut okm);
-               let channel_monitor_claim_key = try!(SecretKey::from_slice(&secp_ctx, &okm));
+               let channel_monitor_claim_key = SecretKey::from_slice(&secp_ctx, &okm)?;
 
                hkdf_expand(sha, &prk, b"rust-lightning local commitment seed info", &mut okm);
 
@@ -156,7 +154,7 @@ enum ChannelState {
        AwaitingRemoteRevoke = (1 << 7),
 }
 
-// TODO: We should refactor this to be a Inbound/OutboundChannel until initial setup handshaking
+// TODO: We should refactor this to be an Inbound/OutboundChannel until initial setup handshaking
 // has been completed, and then turn into a Channel to get compiler-time enforcement of things like
 // calling get_channel_id() before we're set up or things like get_outbound_funding_signed on an
 // inbound channel.
@@ -376,7 +374,7 @@ impl Channel {
                if msg.htlc_minimum_msat >= (msg.funding_satoshis - msg.channel_reserve_satoshis) * 1000 {
                        return Err(HandleError{err: "Minimum htlc value is full channel value", msg: None});
                }
-               Channel::check_remote_fee(fee_estimator, msg.feerate_per_kw).unwrap();
+               Channel::check_remote_fee(fee_estimator, msg.feerate_per_kw)?;
                if msg.to_self_delay > MAX_LOCAL_BREAKDOWN_TIMEOUT {
                        return Err(HandleError{err: "They wanted our payments to be delayed by a needlessly long period", msg: None});
                }
@@ -612,7 +610,7 @@ impl Channel {
        /// The result is a transaction which we can revoke ownership of (ie a "local" transaction)
        /// TODO Some magic rust shit to compile-time check this?
        fn build_local_transaction_keys(&self, commitment_number: u64) -> Result<TxCreationKeys, HandleError> {
-               let per_commitment_point = PublicKey::from_secret_key(&self.secp_ctx, &try!(self.build_local_commitment_secret(commitment_number))).unwrap();
+               let per_commitment_point = PublicKey::from_secret_key(&self.secp_ctx, &self.build_local_commitment_secret(commitment_number)?).unwrap();
                let delayed_payment_base = PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.delayed_payment_base_key).unwrap();
                let htlc_basepoint = PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.htlc_base_key).unwrap();
 
@@ -784,8 +782,9 @@ impl Channel {
                        return Err(HandleError{err: "Unable to find a pending HTLC which matched the given payment preimage", msg: None});
                }
 
+               //TODO: This is racy af, they may have pending messages in flight to us that will not have
+               //received this yet!
                self.value_to_self_msat += htlc_amount_msat;
-
                Ok(msgs::UpdateFulfillHTLC {
                        channel_id: self.channel_id(),
                        htlc_id: htlc_id,
@@ -793,6 +792,37 @@ impl Channel {
                })
        }
 
+       pub fn get_update_fail_htlc(&mut self, payment_hash: &[u8; 32], err_packet: msgs::OnionErrorPacket) -> Result<msgs::UpdateFailHTLC, HandleError> {
+               if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) {
+                       return Err(HandleError{err: "Was asked to fail an HTLC when channel was not in an operational state", msg: None});
+               }
+
+               let mut htlc_id = 0;
+               let mut htlc_amount_msat = 0;
+               self.pending_htlcs.retain(|ref htlc| {
+                       if !htlc.outbound && htlc.payment_hash == *payment_hash {
+                               if htlc_id != 0 {
+                                       panic!("Duplicate HTLC payment_hash, you probably re-used payment preimages, NEVER DO THIS!");
+                               }
+                               htlc_id = htlc.htlc_id;
+                               htlc_amount_msat += htlc.amount_msat;
+                               false
+                       } else { true }
+               });
+               if htlc_amount_msat == 0 {
+                       return Err(HandleError{err: "Unable to find a pending HTLC which matched the given payment preimage", msg: None});
+               }
+
+               //TODO: This is racy af, they may have pending messages in flight to us that will not have
+               //received this yet!
+
+               Ok(msgs::UpdateFailHTLC {
+                       channel_id: self.channel_id(),
+                       htlc_id,
+                       reason: err_packet
+               })
+       }
+
        // Message handlers:
 
        pub fn accept_channel(&mut self, msg: &msgs::AcceptChannel) -> Result<(), HandleError> {
@@ -847,12 +877,12 @@ impl Channel {
        fn funding_created_signature(&mut self, sig: &Signature) -> Result<(Transaction, Signature), HandleError> {
                let funding_script = self.get_funding_redeemscript();
 
-               let remote_keys = try!(self.build_remote_transaction_keys());
-               let remote_initial_commitment_tx = try!(self.build_commitment_transaction(self.cur_remote_commitment_transaction_number, &remote_keys, false, false)).0;
+               let remote_keys = self.build_remote_transaction_keys()?;
+               let remote_initial_commitment_tx = self.build_commitment_transaction(self.cur_remote_commitment_transaction_number, &remote_keys, false, false)?.0;
                let remote_sighash = secp_call!(Message::from_slice(&bip143::SighashComponents::new(&remote_initial_commitment_tx).sighash_all(&remote_initial_commitment_tx, 0, &funding_script, self.channel_value_satoshis)[..]));
 
-               let local_keys = try!(self.build_local_transaction_keys(self.cur_local_commitment_transaction_number));
-               let local_initial_commitment_tx = try!(self.build_commitment_transaction(self.cur_local_commitment_transaction_number, &local_keys, true, false)).0;
+               let local_keys = self.build_local_transaction_keys(self.cur_local_commitment_transaction_number)?;
+               let local_initial_commitment_tx = self.build_commitment_transaction(self.cur_local_commitment_transaction_number, &local_keys, true, false)?.0;
                let local_sighash = secp_call!(Message::from_slice(&bip143::SighashComponents::new(&local_initial_commitment_tx).sighash_all(&local_initial_commitment_tx, 0, &funding_script, self.channel_value_satoshis)[..]));
 
                // They sign the "local" commitment transaction, allowing us to broadcast the tx if we wish.
@@ -899,7 +929,7 @@ impl Channel {
        }
 
        /// Handles a funding_signed message from the remote end.
-       /// If this call is successfull, broadcast the funding transaction (and not before!)
+       /// If this call is successful, broadcast the funding transaction (and not before!)
        pub fn funding_signed(&mut self, msg: &msgs::FundingSigned) -> Result<(), HandleError> {
                if !self.channel_outbound {
                        return Err(HandleError{err: "Received funding_signed for an inbound channel?", msg: None});
@@ -913,8 +943,8 @@ impl Channel {
 
                let funding_script = self.get_funding_redeemscript();
 
-               let local_keys = try!(self.build_local_transaction_keys(self.cur_local_commitment_transaction_number));
-               let local_initial_commitment_tx = try!(self.build_commitment_transaction(self.cur_local_commitment_transaction_number, &local_keys, true, false)).0;
+               let local_keys = self.build_local_transaction_keys(self.cur_local_commitment_transaction_number)?;
+               let local_initial_commitment_tx = self.build_commitment_transaction(self.cur_local_commitment_transaction_number, &local_keys, true, false)?.0;
                let local_sighash = secp_call!(Message::from_slice(&bip143::SighashComponents::new(&local_initial_commitment_tx).sighash_all(&local_initial_commitment_tx, 0, &funding_script, self.channel_value_satoshis)[..]));
 
                // They sign the "local" commitment transaction, allowing us to broadcast the tx if we wish.
@@ -935,7 +965,7 @@ impl Channel {
                }
 
                //TODO: Note that this must be a duplicate of the previous commitment point they sent us,
-               //as otherwise we will have a commitment transaction that they cant revoke (well, kinda,
+               //as otherwise we will have a commitment transaction that they can't revoke (well, kinda,
                //they can by sending two revoke_and_acks back-to-back, but not really). This appears to be
                //a protocol oversight, but I assume I'm just missing something.
                if self.their_cur_commitment_point != msg.next_per_commitment_point {
@@ -1012,7 +1042,7 @@ impl Channel {
        }
 
        /// Removes an outbound HTLC which has been commitment_signed by the remote end
-       fn remove_htlc(&mut self, htlc_id: u64, check_preimage: Option<[u8; 32]>) -> Result<HTLCOutput, HandleError> {
+       fn remove_outbound_htlc(&mut self, htlc_id: u64, check_preimage: Option<[u8; 32]>) -> Result<HTLCOutput, HandleError> {
                let mut found_idx = None;
                for (idx, ref htlc) in self.pending_htlcs.iter().enumerate() {
                        if htlc.outbound && htlc.htlc_id == htlc_id {
@@ -1028,7 +1058,7 @@ impl Channel {
                        }
                }
                match found_idx {
-                       None => Err(HandleError{err: "Remote tried to fulfill an HTLC we couldn't find", msg: None}),
+                       None => Err(HandleError{err: "Remote tried to fulfill/fail an HTLC we couldn't find", msg: None}),
                        Some(idx) => {
                                Ok(self.pending_htlcs.swap_remove(idx))
                        }
@@ -1063,7 +1093,7 @@ impl Channel {
                        //TODO: Need to examine the type of err - if its a fee issue or similar we may want to
                        //fail it back the route, if its a temporary issue we can ignore it...
                        if update_add_msgs.len() > 0 {
-                               Ok(Some((update_add_msgs, try!(self.send_commitment()))))
+                               Ok(Some((update_add_msgs, self.send_commitment()?)))
                        } else {
                                Err(err.unwrap())
                        }
@@ -1098,9 +1128,7 @@ impl Channel {
                let mut payment_hash = [0; 32];
                sha.result(&mut payment_hash);
 
-               //TODO: Tell channel_monitor about the payment_preimage
-
-               match self.remove_htlc(msg.htlc_id, Some(payment_hash)) {
+               match self.remove_outbound_htlc(msg.htlc_id, Some(payment_hash)) {
                        Err(e) => return Err(e),
                        Ok(htlc) => {
                                //TODO: Double-check that we didn't exceed some limits (or value_to_self went
@@ -1112,43 +1140,40 @@ impl Channel {
                self.check_and_free_holding_cell_htlcs()
        }
 
-
-       pub fn update_fail_htlc(&mut self, msg: &msgs::UpdateFailHTLC) -> Result<Option<(Vec<msgs::UpdateAddHTLC>, msgs::CommitmentSigned)>, HandleError> {
+       pub fn update_fail_htlc(&mut self, msg: &msgs::UpdateFailHTLC) -> Result<([u8; 32], Option<(Vec<msgs::UpdateAddHTLC>, msgs::CommitmentSigned)>), HandleError> {
                if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) {
                        return Err(HandleError{err: "Got add HTLC message when channel was not in an operational state", msg: None});
                }
 
-               //TODO: Lots of checks here (and implementation after the remove?)
-
-               match self.remove_htlc(msg.htlc_id, None) {
+               let payment_hash = match self.remove_outbound_htlc(msg.htlc_id, None) {
                        Err(e) => return Err(e),
-                       Ok(_htlc) => {
+                       Ok(htlc) => {
                                //TODO: Double-check that we didn't exceed some limits (or value_to_self went
                                //negative here?)
-                               ////TODO: Something?
+                               htlc.payment_hash
                        }
-               }
+               };
 
-               self.check_and_free_holding_cell_htlcs()
+               let holding_cell_freedom = self.check_and_free_holding_cell_htlcs()?;
+               Ok((payment_hash, holding_cell_freedom))
        }
 
-       pub fn update_fail_malformed_htlc(&mut self, msg: &msgs::UpdateFailMalformedHTLC) -> Result<Option<(Vec<msgs::UpdateAddHTLC>, msgs::CommitmentSigned)>, HandleError> {
+       pub fn update_fail_malformed_htlc(&mut self, msg: &msgs::UpdateFailMalformedHTLC) -> Result<([u8; 32], Option<(Vec<msgs::UpdateAddHTLC>, msgs::CommitmentSigned)>), HandleError> {
                if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) {
                        return Err(HandleError{err: "Got add HTLC message when channel was not in an operational state", msg: None});
                }
 
-               //TODO: Lots of checks here (and implementation after the remove?)
-
-               match self.remove_htlc(msg.htlc_id, None) {
+               let payment_hash = match self.remove_outbound_htlc(msg.htlc_id, None) {
                        Err(e) => return Err(e),
-                       Ok(_htlc) => {
+                       Ok(htlc) => {
                                //TODO: Double-check that we didn't exceed some limits (or value_to_self went
                                //negative here?)
-                               ////TODO: Something?
+                               htlc.payment_hash
                        }
-               }
+               };
 
-               self.check_and_free_holding_cell_htlcs()
+               let holding_cell_freedom = self.check_and_free_holding_cell_htlcs()?;
+               Ok((payment_hash, holding_cell_freedom))
        }
 
        pub fn commitment_signed(&mut self, msg: &msgs::CommitmentSigned) -> Result<(msgs::RevokeAndACK, Vec<PendingForwardHTLCInfo>), HandleError> {
@@ -1158,8 +1183,8 @@ impl Channel {
 
                let funding_script = self.get_funding_redeemscript();
 
-               let local_keys = try!(self.build_local_transaction_keys(self.cur_local_commitment_transaction_number));
-               let local_commitment_tx = try!(self.build_commitment_transaction(self.cur_local_commitment_transaction_number, &local_keys, true, false));
+               let local_keys = self.build_local_transaction_keys(self.cur_local_commitment_transaction_number)?;
+               let local_commitment_tx = self.build_commitment_transaction(self.cur_local_commitment_transaction_number, &local_keys, true, false)?;
                let local_sighash = secp_call!(Message::from_slice(&bip143::SighashComponents::new(&local_commitment_tx.0).sighash_all(&local_commitment_tx.0, 0, &funding_script, self.channel_value_satoshis)[..]));
                secp_call!(self.secp_ctx.verify(&local_sighash, &msg.signature, &self.their_funding_pubkey));
 
@@ -1168,13 +1193,13 @@ impl Channel {
                }
 
                for (idx, ref htlc) in local_commitment_tx.1.iter().enumerate() {
-                       let htlc_tx = try!(self.build_htlc_transaction(&local_commitment_tx.0.txid(), htlc, true, &local_keys));
+                       let htlc_tx = self.build_htlc_transaction(&local_commitment_tx.0.txid(), htlc, true, &local_keys)?;
                        let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, &local_keys, htlc.offered);
                        let htlc_sighash = secp_call!(Message::from_slice(&bip143::SighashComponents::new(&htlc_tx).sighash_all(&htlc_tx, 0, &htlc_redeemscript, htlc.amount_msat / 1000)[..]));
                        secp_call!(self.secp_ctx.verify(&htlc_sighash, &msg.htlc_signatures[idx], &local_keys.b_htlc_key));
                }
 
-               let next_per_commitment_point = PublicKey::from_secret_key(&self.secp_ctx, &try!(self.build_local_commitment_secret(self.cur_local_commitment_transaction_number - 1))).unwrap();
+               let next_per_commitment_point = PublicKey::from_secret_key(&self.secp_ctx, &self.build_local_commitment_secret(self.cur_local_commitment_transaction_number - 1)?).unwrap();
                let per_commitment_secret = chan_utils::build_commitment_secret(self.local_keys.commitment_seed, self.cur_local_commitment_transaction_number);
 
                //TODO: Store htlc keys in our channel_watcher
@@ -1210,7 +1235,7 @@ impl Channel {
                if PublicKey::from_secret_key(&self.secp_ctx, &get_key!(&self.secp_ctx, &msg.per_commitment_secret)).unwrap() != self.their_cur_commitment_point {
                        return Err(HandleError{err: "Got a revoke commitment secret which didn't correspond to their current pubkey", msg: None});
                }
-               try!(self.channel_monitor.provide_secret(self.cur_remote_commitment_transaction_number, msg.per_commitment_secret));
+               self.channel_monitor.provide_secret(self.cur_remote_commitment_transaction_number, msg.per_commitment_secret)?;
 
                // Update state now that we've passed all the can-fail calls...
                // (note that we may still fail to generate the new commitment_signed message, but that's
@@ -1335,7 +1360,7 @@ impl Channel {
                                        self.funding_tx_confirmed_in = header.bitcoin_hash();
 
                                        //TODO: Note that this must be a duplicate of the previous commitment point they sent us,
-                                       //as otherwise we will have a commitment transaction that they cant revoke (well, kinda,
+                                       //as otherwise we will have a commitment transaction that they can't revoke (well, kinda,
                                        //they can by sending two revoke_and_acks back-to-back, but not really). This appears to be
                                        //a protocol oversight, but I assume I'm just missing something.
                                        let next_per_commitment_secret = match self.build_local_commitment_secret(self.cur_local_commitment_transaction_number) {
@@ -1395,7 +1420,7 @@ impl Channel {
                        panic!("Tried to send an open_channel for a channel that has already advanced");
                }
 
-               let local_commitment_secret = try!(self.build_local_commitment_secret(self.cur_local_commitment_transaction_number));
+               let local_commitment_secret = self.build_local_commitment_secret(self.cur_local_commitment_transaction_number)?;
 
                Ok(msgs::OpenChannel {
                        chain_hash: chain_hash,
@@ -1431,7 +1456,7 @@ impl Channel {
                        panic!("Tried to send an accept_channel for a channel that has already advanced");
                }
 
-               let local_commitment_secret = try!(self.build_local_commitment_secret(self.cur_local_commitment_transaction_number));
+               let local_commitment_secret = self.build_local_commitment_secret(self.cur_local_commitment_transaction_number)?;
 
                Ok(msgs::AcceptChannel {
                        temporary_channel_id: self.channel_id,
@@ -1455,8 +1480,8 @@ impl Channel {
        fn get_outbound_funding_created_signature(&mut self) -> Result<Signature, HandleError> {
                let funding_script = self.get_funding_redeemscript();
 
-               let remote_keys = try!(self.build_remote_transaction_keys());
-               let remote_initial_commitment_tx = try!(self.build_commitment_transaction(self.cur_remote_commitment_transaction_number, &remote_keys, false, false)).0;
+               let remote_keys = self.build_remote_transaction_keys()?;
+               let remote_initial_commitment_tx = self.build_commitment_transaction(self.cur_remote_commitment_transaction_number, &remote_keys, false, false)?.0;
                let remote_sighash = secp_call!(Message::from_slice(&bip143::SighashComponents::new(&remote_initial_commitment_tx).sighash_all(&remote_initial_commitment_tx, 0, &funding_script, self.channel_value_satoshis)[..]));
 
                // We sign the "remote" commitment transaction, allowing them to broadcast the tx if they wish.
@@ -1468,7 +1493,7 @@ impl Channel {
        /// Panics if called at some time other than immediately after initial handshake, if called twice,
        /// or if called on an inbound channel.
        /// Note that channel_id changes during this call!
-       /// Do NOT broadcast the funding transaction until after a successfull funding_signed call!
+       /// Do NOT broadcast the funding transaction until after a successful funding_signed call!
        pub fn get_outbound_funding_created(&mut self, funding_txid: Sha256dHash, funding_output_index: u16) -> Result<msgs::FundingCreated, HandleError> {
                if !self.channel_outbound {
                        panic!("Tried to create outbound funding_created message on an inbound channel!");
@@ -1617,15 +1642,15 @@ impl Channel {
 
                let funding_script = self.get_funding_redeemscript();
 
-               let remote_keys = try!(self.build_remote_transaction_keys());
-               let remote_commitment_tx = try!(self.build_commitment_transaction(self.cur_remote_commitment_transaction_number, &remote_keys, false, true));
+               let remote_keys = self.build_remote_transaction_keys()?;
+               let remote_commitment_tx = self.build_commitment_transaction(self.cur_remote_commitment_transaction_number, &remote_keys, false, true)?;
                let remote_sighash = secp_call!(Message::from_slice(&bip143::SighashComponents::new(&remote_commitment_tx.0).sighash_all(&remote_commitment_tx.0, 0, &funding_script, self.channel_value_satoshis)[..]));
                let our_sig = secp_call!(self.secp_ctx.sign(&remote_sighash, &self.local_keys.funding_key));
 
                let mut htlc_sigs = Vec::new();
 
                for ref htlc in remote_commitment_tx.1.iter() {
-                       let htlc_tx = try!(self.build_htlc_transaction(&remote_commitment_tx.0.txid(), htlc, false, &remote_keys));
+                       let htlc_tx = self.build_htlc_transaction(&remote_commitment_tx.0.txid(), htlc, false, &remote_keys)?;
                        let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, &remote_keys, htlc.offered);
                        let htlc_sighash = secp_call!(Message::from_slice(&bip143::SighashComponents::new(&htlc_tx).sighash_all(&htlc_tx, 0, &htlc_redeemscript, htlc.amount_msat / 1000)[..]));
                        let our_htlc_key = secp_call!(chan_utils::derive_private_key(&self.secp_ctx, &remote_keys.per_commitment_point, &self.local_keys.htlc_base_key));
@@ -1647,9 +1672,9 @@ impl Channel {
        /// Shorthand for calling send_htlc() followed by send_commitment(), see docs on those for
        /// more info.
        pub fn send_htlc_and_commit(&mut self, amount_msat: u64, payment_hash: [u8; 32], cltv_expiry: u32, onion_routing_packet: msgs::OnionPacket) -> Result<Option<(msgs::UpdateAddHTLC, msgs::CommitmentSigned)>, HandleError> {
-               match try!(self.send_htlc(amount_msat, payment_hash, cltv_expiry, onion_routing_packet)) {
+               match self.send_htlc(amount_msat, payment_hash, cltv_expiry, onion_routing_packet)? {
                        Some(update_add_htlc) =>
-                               Ok(Some((update_add_htlc, try!(self.send_commitment())))),
+                               Ok(Some((update_add_htlc, self.send_commitment()?))),
                        None => Ok(None)
                }
        }
@@ -1696,7 +1721,7 @@ mod tests {
                chan.local_keys.payment_base_key = SecretKey::from_slice(&secp_ctx, &hex_bytes("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap();
                chan.local_keys.delayed_payment_base_key = SecretKey::from_slice(&secp_ctx, &hex_bytes("3333333333333333333333333333333333333333333333333333333333333333").unwrap()[..]).unwrap();
                chan.local_keys.htlc_base_key = SecretKey::from_slice(&secp_ctx, &hex_bytes("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap();
-               // chan.local_keys.commitment_seed isnt derived in the test vectors :(
+               // chan.local_keys.commitment_seed isn't derived in the test vectors :(
 
                chan.channel_monitor.set_funding_info(Sha256dHash::from_hex("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(), 0);