From: Devrandom Date: Wed, 15 Jan 2020 18:33:38 +0000 (-0800) Subject: refactor output sorting X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=0a99bd9c52234eede2555cdfe5bc414c36f663c0;p=rust-lightning refactor output sorting --- diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 6b6e52275..dcdde52a5 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -814,7 +814,8 @@ impl Channel { ins }; - let mut txouts: Vec<(TxOut, Option<(HTLCOutputInCommitment, Option<&HTLCSource>)>, Script)> = Vec::with_capacity(self.pending_inbound_htlcs.len() + self.pending_outbound_htlcs.len() + 2); + let mut txouts: Vec<(TxOut, (Option<(HTLCOutputInCommitment, Option<&HTLCSource>)>, Script))> = + Vec::with_capacity(self.pending_inbound_htlcs.len() + self.pending_outbound_htlcs.len() + 2); let mut included_dust_htlcs: Vec<(HTLCOutputInCommitment, Option<&HTLCSource>)> = Vec::new(); let dust_limit_satoshis = if local { self.our_dust_limit_satoshis } else { self.their_dust_limit_satoshis }; @@ -846,7 +847,7 @@ impl Channel { txouts.push((TxOut { script_pubkey: script.to_v0_p2wsh(), value: $htlc.amount_msat / 1000 - }, Some((htlc_in_tx, $source)), script)); + }, (Some((htlc_in_tx, $source)), script))); } else { log_trace!(self, " ...including {} {} dust HTLC {} (hash {}) with value {} due to dust limit", if $outbound { "outbound" } else { "inbound" }, $state_name, $htlc.htlc_id, log_bytes!($htlc.payment_hash.0), $htlc.amount_msat); included_dust_htlcs.push((htlc_in_tx, $source)); @@ -859,7 +860,7 @@ impl Channel { txouts.push((TxOut { // "received HTLC output" script_pubkey: script.to_v0_p2wsh(), value: $htlc.amount_msat / 1000 - }, Some((htlc_in_tx, $source)), script)); + }, (Some((htlc_in_tx, $source)), script))); } else { log_trace!(self, " ...including {} {} dust HTLC {} (hash {}) with value {}", if $outbound { "outbound" } else { "inbound" }, $state_name, $htlc.htlc_id, log_bytes!($htlc.payment_hash.0), $htlc.amount_msat); included_dust_htlcs.push((htlc_in_tx, $source)); @@ -965,7 +966,7 @@ impl Channel { txouts.push((TxOut { script_pubkey: script.to_v0_p2wsh(), value: value_to_a as u64 - }, None, script)); + }, (None, script))); } if value_to_b >= (dust_limit_satoshis as i64) { @@ -978,10 +979,10 @@ impl Channel { txouts.push((TxOut { script_pubkey: script, value: value_to_b as u64 - }, None, redeem_script)); + }, (None, redeem_script))); } - transaction_utils::sort_outputs2(&mut txouts, |a, b| { + transaction_utils::sort_outputs(&mut txouts, |(a, _), (b, _)| { if let &Some(ref a_htlc) = a { if let &Some(ref b_htlc) = b { a_htlc.0.cltv_expiry.cmp(&b_htlc.0.cltv_expiry) @@ -998,10 +999,10 @@ impl Channel { let mut outputs: Vec = Vec::with_capacity(txouts.len()); let mut scripts: Vec