]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Merge pull request #335 from TheBlueMatt/2019-04-330-nits
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Wed, 10 Apr 2019 17:19:42 +0000 (13:19 -0400)
committerGitHub <noreply@github.com>
Wed, 10 Apr 2019 17:19:42 +0000 (13:19 -0400)
Make channel open confs configurable (and change from 12 to 6)

src/ln/channelmonitor.rs
src/util/transaction_utils.rs

index 25f41d882964d0e6d0af4ac89f36f9d0bcb1ddf8..cc77003cd9fb29be0c1eb9e25e1cf3467c85429c 100644 (file)
@@ -801,18 +801,8 @@ impl ChannelMonitor {
                                writer.write_all(&delayed_payment_base_key[..])?;
                                writer.write_all(&payment_base_key[..])?;
                                writer.write_all(&shutdown_pubkey.serialize())?;
-                               if let Some(ref prev_latest_per_commitment_point) = *prev_latest_per_commitment_point {
-                                       writer.write_all(&[1; 1])?;
-                                       writer.write_all(&prev_latest_per_commitment_point.serialize())?;
-                               } else {
-                                       writer.write_all(&[0; 1])?;
-                               }
-                               if let Some(ref latest_per_commitment_point) = *latest_per_commitment_point {
-                                       writer.write_all(&[1; 1])?;
-                                       writer.write_all(&latest_per_commitment_point.serialize())?;
-                               } else {
-                                       writer.write_all(&[0; 1])?;
-                               }
+                               prev_latest_per_commitment_point.write(writer)?;
+                               latest_per_commitment_point.write(writer)?;
                                match funding_info  {
                                        &Some((ref outpoint, ref script)) => {
                                                writer.write_all(&outpoint.txid[..])?;
@@ -823,8 +813,8 @@ impl ChannelMonitor {
                                                debug_assert!(false, "Try to serialize a useless Local monitor !");
                                        },
                                }
-                               write_option!(current_remote_commitment_txid);
-                               write_option!(prev_remote_commitment_txid);
+                               current_remote_commitment_txid.write(writer)?;
+                               prev_remote_commitment_txid.write(writer)?;
                        },
                        Storage::Watchtower { .. } => unimplemented!(),
                }
@@ -864,7 +854,7 @@ impl ChannelMonitor {
                                writer.write_all(&byte_utils::be64_to_array($htlc_output.amount_msat))?;
                                writer.write_all(&byte_utils::be32_to_array($htlc_output.cltv_expiry))?;
                                writer.write_all(&$htlc_output.payment_hash.0[..])?;
-                               write_option!(&$htlc_output.transaction_output_index);
+                               $htlc_output.transaction_output_index.write(writer)?;
                        }
                }
 
index f9ee1bd82effd4737176359e64f21087fd8bf51b..a7c1e6bc6f78a48e15b69cf4081f0b88534b30e3 100644 (file)
@@ -88,6 +88,26 @@ mod tests {
                assert_eq!(&outputs, &vec![(txout1_, "ignore"), (txout2_, "ignore")]);
        }
 
+       #[test]
+       fn sort_output_tie_breaker_test() {
+               let txout1 = TxOut {
+                       value:  100,
+                       script_pubkey: Builder::new().push_int(1).push_int(2).into_script()
+               };
+               let txout1_ = txout1.clone();
+
+               let txout2 = txout1.clone();
+               let txout2_ = txout1.clone();
+
+               let mut outputs = vec![(txout1, 420), (txout2, 69)];
+               sort_outputs(&mut outputs, |a, b| { a.cmp(b) });
+
+               assert_eq!(
+                       &outputs,
+                       &vec![(txout2_, 69), (txout1_, 420)]
+               );
+       }
+
        fn script_from_hex(hex_str: &str) -> Script {
                Script::from(decode(hex_str).unwrap())
        }