]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Merge pull request #175 from TheBlueMatt/2018-09-173-whitespace-err
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Thu, 13 Sep 2018 17:11:51 +0000 (13:11 -0400)
committerGitHub <noreply@github.com>
Thu, 13 Sep 2018 17:11:51 +0000 (13:11 -0400)
raise APIError from send_payment (#173 without whitespace nit)

src/ln/channel.rs
src/util/ser.rs

index 0ed2dde04ec9f216141663111ffebf979b743459..f80b516492fb7cd1d6a9db670c7a9fe8669d3d21 100644 (file)
@@ -1263,10 +1263,6 @@ impl Channel {
        fn funding_created_signature(&mut self, sig: &Signature) -> Result<(Transaction, Signature), HandleError> {
                let funding_script = self.get_funding_redeemscript();
 
-               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 = Message::from_slice(&bip143::SighashComponents::new(&remote_initial_commitment_tx).sighash_all(&remote_initial_commitment_tx.input[0], &funding_script, self.channel_value_satoshis)[..]).unwrap();
-
                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 = Message::from_slice(&bip143::SighashComponents::new(&local_initial_commitment_tx).sighash_all(&local_initial_commitment_tx.input[0], &funding_script, self.channel_value_satoshis)[..]).unwrap();
@@ -1274,6 +1270,10 @@ impl Channel {
                // They sign the "local" commitment transaction, allowing us to broadcast the tx if we wish.
                secp_call!(self.secp_ctx.verify(&local_sighash, &sig, &self.their_funding_pubkey.unwrap()), "Invalid funding_created signature from peer", self.channel_id());
 
+               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 = Message::from_slice(&bip143::SighashComponents::new(&remote_initial_commitment_tx).sighash_all(&remote_initial_commitment_tx.input[0], &funding_script, self.channel_value_satoshis)[..]).unwrap();
+
                // We sign the "remote" commitment transaction, allowing them to broadcast the tx if they wish.
                Ok((remote_initial_commitment_tx, self.secp_ctx.sign(&remote_sighash, &self.local_keys.funding_key)))
        }
index 0a247d41a67d532c3ffd77c6ad2ff2938760fadc..299515d9022ed46341754d2eca417a5f48f85fce 100644 (file)
@@ -13,7 +13,7 @@ use ln::msgs::DecodeError;
 
 use util::byte_utils::{be64_to_array, be32_to_array, be16_to_array, slice_to_be16, slice_to_be32, slice_to_be64};
 
-const MAX_BUF_SIZE: usize = 16 * 1024;
+const MAX_BUF_SIZE: usize = 64 * 1024;
 
 pub struct Writer<W> { writer: W }
 pub struct Reader<R> { reader: R }
@@ -183,7 +183,7 @@ impl<R, K, V> Readable<R> for HashMap<K, V>
                let len: u16 = Readable::read(r)?;
                let mut ret = HashMap::with_capacity(len as usize);
                for _ in 0..len {
-                               ret.insert(K::read(r)?, V::read(r)?);
+                       ret.insert(K::read(r)?, V::read(r)?);
                }
                Ok(ret)
        }
@@ -197,7 +197,7 @@ impl<W: Write, T: Writeable<W>> Writeable<W> for Vec<T> {
                                .checked_mul(mem::size_of::<T>())
                                .ok_or(DecodeError::BadLengthDescriptor)?;
                if byte_size > MAX_BUF_SIZE {
-                               return Err(DecodeError::BadLengthDescriptor);
+                       return Err(DecodeError::BadLengthDescriptor);
                }
                (self.len() as u16).write(w)?;
                // performance with Vec<u8>
@@ -211,16 +211,16 @@ impl<W: Write, T: Writeable<W>> Writeable<W> for Vec<T> {
 impl<R: Read, T: Readable<R>> Readable<R> for Vec<T> {
        #[inline]
        fn read(r: &mut Reader<R>) -> Result<Self, DecodeError> {
-                       let len: u16 = Readable::read(r)?;
-                       let byte_size = (len as usize)
-                                       .checked_mul(mem::size_of::<T>())
-                                       .ok_or(DecodeError::BadLengthDescriptor)?;
-                       if byte_size > MAX_BUF_SIZE {
-                                       return Err(DecodeError::BadLengthDescriptor);
-                       }
-                       let mut ret = Vec::with_capacity(len as usize);
-                       for _ in 0..len { ret.push(T::read(r)?); }
-                       Ok(ret)
+               let len: u16 = Readable::read(r)?;
+               let byte_size = (len as usize)
+                               .checked_mul(mem::size_of::<T>())
+                               .ok_or(DecodeError::BadLengthDescriptor)?;
+               if byte_size > MAX_BUF_SIZE {
+                       return Err(DecodeError::BadLengthDescriptor);
+               }
+               let mut ret = Vec::with_capacity(len as usize);
+               for _ in 0..len { ret.push(T::read(r)?); }
+               Ok(ret)
        }
 }