Fix typos
[rust-lightning] / src / ln / channelmonitor.rs
index 01634f9d5f66c21249ea528af7141be71926ae4b..3b5905e702bc55dd3789a600350dee35ec1c4376 100644 (file)
@@ -24,7 +24,7 @@ use bitcoin_hashes::Hash;
 use bitcoin_hashes::sha256::Hash as Sha256;
 use bitcoin_hashes::hash160::Hash as Hash160;
 
-use secp256k1::{Secp256k1,Message,Signature};
+use secp256k1::{Secp256k1,Signature};
 use secp256k1::key::{SecretKey,PublicKey};
 use secp256k1;
 
@@ -219,7 +219,7 @@ impl<Key : Send + cmp::Eq + hash::Hash + 'static> SimpleManyChannelMonitor<Key>
                res
        }
 
-       /// Adds or udpates the monitor which monitors the channel referred to by the given key.
+       /// Adds or updates the monitor which monitors the channel referred to by the given key.
        pub fn add_update_monitor_by_key(&self, key: Key, monitor: ChannelMonitor) -> Result<(), MonitorUpdateError> {
                let mut monitors = self.monitors.lock().unwrap();
                match monitors.get_mut(&key) {
@@ -299,7 +299,7 @@ pub(crate) const HTLC_FAIL_TIMEOUT_BLOCKS: u32 = 3;
 /// Number of blocks we wait on seeing a confirmed HTLC-Timeout or previous revoked commitment
 /// transaction before we fail corresponding inbound HTLCs. This prevents us from failing backwards
 /// and then getting a reorg resulting in us losing money.
-//TODO: We currently dont actually use this...we should
+//TODO: We currently don't actually use this...we should
 pub(crate) const HTLC_FAIL_ANTI_REORG_DELAY: u32 = 6;
 
 #[derive(Clone, PartialEq)]
@@ -642,7 +642,7 @@ impl ChannelMonitor {
                                let our_funding_info = funding_info;
                                if let Storage::Local { ref funding_info, .. } = other.key_storage {
                                        if funding_info.is_none() { return Err(MonitorUpdateError("Try to combine a Local monitor without funding_info")); }
-                                       // We should be able to compare the entire funding_txo, but in fuzztarget its trivially
+                                       // We should be able to compare the entire funding_txo, but in fuzztarget it's trivially
                                        // easy to collide the funding_txo hash and have a different scriptPubKey.
                                        if funding_info.as_ref().unwrap().0 != our_funding_info.as_ref().unwrap().0 {
                                                return Err(MonitorUpdateError("Funding transaction outputs are not identical!"));
@@ -1105,7 +1105,7 @@ impl ChannelMonitor {
                                                                        let htlc = &per_commitment_option.unwrap()[$htlc_idx.unwrap()].0;
                                                                        chan_utils::get_htlc_redeemscript_with_explicit_keys(htlc, &a_htlc_key, &b_htlc_key, &revocation_pubkey)
                                                                };
-                                                               let sighash = ignore_error!(Message::from_slice(&$sighash_parts.sighash_all(&$input, &redeemscript, $amount)[..]));
+                                                               let sighash = hash_to_message!(&$sighash_parts.sighash_all(&$input, &redeemscript, $amount)[..]);
                                                                let revocation_key = ignore_error!(chan_utils::derive_private_revocation_key(&self.secp_ctx, &per_commitment_key, &revocation_base_key));
                                                                (self.secp_ctx.sign(&sighash, &revocation_key), redeemscript)
                                                        },
@@ -1327,7 +1327,7 @@ impl ChannelMonitor {
                                                                        Storage::Local { ref htlc_base_key, .. } => {
                                                                                let htlc = &per_commitment_option.unwrap()[$input.sequence as usize].0;
                                                                                let redeemscript = chan_utils::get_htlc_redeemscript_with_explicit_keys(htlc, &a_htlc_key, &b_htlc_key, &revocation_pubkey);
-                                                                               let sighash = ignore_error!(Message::from_slice(&$sighash_parts.sighash_all(&$input, &redeemscript, $amount)[..]));
+                                                                               let sighash = hash_to_message!(&$sighash_parts.sighash_all(&$input, &redeemscript, $amount)[..]);
                                                                                let htlc_key = ignore_error!(chan_utils::derive_private_key(&self.secp_ctx, revocation_point, &htlc_base_key));
                                                                                (self.secp_ctx.sign(&sighash, &htlc_key), redeemscript)
                                                                        },
@@ -1445,7 +1445,7 @@ impl ChannelMonitor {
                (txn_to_broadcast, (commitment_txid, watch_outputs), spendable_outputs, htlc_updated)
        }
 
-       /// Attempst to claim a remote HTLC-Success/HTLC-Timeout s outputs using the revocation key
+       /// Attempts 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>, Option<SpendableOutputDescriptor>) {
                if tx.input.len() != 1 || tx.output.len() != 1 {
                        return (None, None)
@@ -1512,7 +1512,7 @@ impl ChannelMonitor {
 
                        let sig = match self.key_storage {
                                Storage::Local { ref revocation_base_key, .. } => {
-                                       let sighash = ignore_error!(Message::from_slice(&sighash_parts.sighash_all(&spend_tx.input[0], &redeemscript, amount)[..]));
+                                       let sighash = hash_to_message!(&sighash_parts.sighash_all(&spend_tx.input[0], &redeemscript, amount)[..]);
                                        let revocation_key = ignore_error!(chan_utils::derive_private_revocation_key(&self.secp_ctx, &per_commitment_key, &revocation_base_key));
                                        self.secp_ctx.sign(&sighash, &revocation_key)
                                }
@@ -1615,7 +1615,7 @@ impl ChannelMonitor {
        /// Should not be used if check_spend_revoked_transaction succeeds.
        fn check_spend_local_transaction(&self, tx: &Transaction, _height: u32) -> (Vec<Transaction>, Vec<SpendableOutputDescriptor>, (Sha256dHash, Vec<TxOut>)) {
                let commitment_txid = tx.txid();
-               // TODO: If we find a match here we need to fail back HTLCs that were't included in the
+               // TODO: If we find a match here we need to fail back HTLCs that weren't included in the
                // broadcast commitment transaction, either because they didn't meet dust or because they
                // weren't yet included in our commitment transaction(s).
                if let &Some(ref local_tx) = &self.current_local_signed_commitment_tx {
@@ -1669,7 +1669,7 @@ impl ChannelMonitor {
                                }
                                Storage::Watchtower { .. } => {
                                        //TODO: we need to ensure an offline client will generate the event when it
-                                       // cames back online after only the watchtower saw the transaction
+                                       // comes back online after only the watchtower saw the transaction
                                }
                        }
                }
@@ -1960,13 +1960,6 @@ impl<R: ::std::io::Read> ReadableArgs<R, Arc<Logger>> for (Sha256dHash, ChannelM
                                }
                        }
                }
-               macro_rules! read_option { () => {
-                       match <u8 as Readable<R>>::read(reader)? {
-                               0 => None,
-                               1 => Some(Readable::read(reader)?),
-                               _ => return Err(DecodeError::InvalidValue),
-                       }
-               } }
 
                let _ver: u8 = Readable::read(reader)?;
                let min_ver: u8 = Readable::read(reader)?;
@@ -1983,16 +1976,8 @@ impl<R: ::std::io::Read> ReadableArgs<R, Arc<Logger>> for (Sha256dHash, ChannelM
                                let delayed_payment_base_key = Readable::read(reader)?;
                                let payment_base_key = Readable::read(reader)?;
                                let shutdown_pubkey = Readable::read(reader)?;
-                               let prev_latest_per_commitment_point = match <u8 as Readable<R>>::read(reader)? {
-                                       0 => None,
-                                       1 => Some(Readable::read(reader)?),
-                                       _ => return Err(DecodeError::InvalidValue),
-                               };
-                               let latest_per_commitment_point = match <u8 as Readable<R>>::read(reader)? {
-                                       0 => None,
-                                       1 => Some(Readable::read(reader)?),
-                                       _ => return Err(DecodeError::InvalidValue),
-                               };
+                               let prev_latest_per_commitment_point = Readable::read(reader)?;
+                               let latest_per_commitment_point = Readable::read(reader)?;
                                // Technically this can fail and serialize fail a round-trip, but only for serialization of
                                // barely-init'd ChannelMonitors that we can't do anything with.
                                let outpoint = OutPoint {
@@ -2000,8 +1985,8 @@ impl<R: ::std::io::Read> ReadableArgs<R, Arc<Logger>> for (Sha256dHash, ChannelM
                                        index: Readable::read(reader)?,
                                };
                                let funding_info = Some((outpoint, Readable::read(reader)?));
-                               let current_remote_commitment_txid = read_option!();
-                               let prev_remote_commitment_txid = read_option!();
+                               let current_remote_commitment_txid = Readable::read(reader)?;
+                               let prev_remote_commitment_txid = Readable::read(reader)?;
                                Storage::Local {
                                        revocation_base_key,
                                        htlc_base_key,
@@ -2052,7 +2037,7 @@ impl<R: ::std::io::Read> ReadableArgs<R, Arc<Logger>> for (Sha256dHash, ChannelM
                                        let amount_msat: u64 = Readable::read(reader)?;
                                        let cltv_expiry: u32 = Readable::read(reader)?;
                                        let payment_hash: PaymentHash = Readable::read(reader)?;
-                                       let transaction_output_index: Option<u32> = read_option!();
+                                       let transaction_output_index: Option<u32> = Readable::read(reader)?;
 
                                        HTLCOutputInCommitment {
                                                offered, amount_msat, cltv_expiry, payment_hash, transaction_output_index
@@ -2068,7 +2053,7 @@ impl<R: ::std::io::Read> ReadableArgs<R, Arc<Logger>> for (Sha256dHash, ChannelM
                        let htlcs_count: u64 = Readable::read(reader)?;
                        let mut htlcs = Vec::with_capacity(cmp::min(htlcs_count as usize, MAX_ALLOC_SIZE / 32));
                        for _ in 0..htlcs_count {
-                               htlcs.push((read_htlc_in_commitment!(), read_option!().map(|o: HTLCSource| Box::new(o))));
+                               htlcs.push((read_htlc_in_commitment!(), <Option<HTLCSource> as Readable<R>>::read(reader)?.map(|o: HTLCSource| Box::new(o))));
                        }
                        if let Some(_) = remote_claimable_outpoints.insert(txid, htlcs) {
                                return Err(DecodeError::InvalidValue);
@@ -2131,7 +2116,7 @@ impl<R: ::std::io::Read> ReadableArgs<R, Arc<Logger>> for (Sha256dHash, ChannelM
                                                        1 => Some((Readable::read(reader)?, Readable::read(reader)?)),
                                                        _ => return Err(DecodeError::InvalidValue),
                                                };
-                                               htlcs.push((htlc, sigs, read_option!()));
+                                               htlcs.push((htlc, sigs, Readable::read(reader)?));
                                        }
 
                                        LocalSignedTx {