You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let txout_htlc_pairs:Vec<(TxOut,Option<&HTLCOutputInCommitment>)> = Self::build_txout_htlc_pairs(keys,self.to_broadcaster_value_sat,self.to_countersignatory_value_sat,&self.nondust_htlcs, channel_parameters);
1565
-
let outputs = txout_htlc_pairs.into_iter().map(|(output, _)| output).collect();
let insert_non_htlc_output = |non_htlc_output:TxOut| {
1567
+
let idx = match outputs.binary_search_by(|output| output.value.cmp(&non_htlc_output.value).then(output.script_pubkey.cmp(&non_htlc_output.script_pubkey))){
1568
+
// For non-HTLC outputs, if they're copying our SPK we don't really care if we
1569
+
// close the channel due to mismatches - they're doing something dumb
1570
+
Ok(i) => i,
1571
+
Err(i) => i,
1572
+
};
1573
+
outputs.insert(idx, non_htlc_output);
1574
+
};
1575
+
1576
+
Self::insert_non_htlc_outputs(
1577
+
keys,
1578
+
self.to_broadcaster_value_sat,
1579
+
self.to_countersignatory_value_sat,
1580
+
channel_parameters,
1581
+
!self.nondust_htlcs.is_empty(),
1582
+
insert_non_htlc_output
1583
+
);
1566
1584
1567
1585
let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
let insert_non_htlc_output = |non_htlc_output:TxOut| {
1616
+
let idx = match outputs.binary_search_by(|output| output.value.cmp(&non_htlc_output.value).then(output.script_pubkey.cmp(&non_htlc_output.script_pubkey))){
1617
+
// For non-HTLC outputs, if they're copying our SPK we don't really care if we
1618
+
// close the channel due to mismatches - they're doing something dumb
1619
+
Ok(i) => i,
1620
+
Err(i) => i,
1621
+
};
1622
+
outputs.insert(idx, non_htlc_output);
1623
+
1624
+
// Increment the transaction output indices of all the HTLCs that come after the output we
1625
+
// just inserted.
1626
+
nondust_htlcs
1627
+
.iter_mut()
1628
+
.rev()
1629
+
.map_while(|htlc| {
1630
+
let i = htlc.transaction_output_index.as_mut().unwrap();
1631
+
(*i >= idx asu32).then(|| i)
1632
+
})
1633
+
.for_each(|i| *i += 1);
1634
+
};
1635
+
1636
+
Self::insert_non_htlc_outputs(
1637
+
keys,
1638
+
to_broadcaster_value_sat,
1639
+
to_countersignatory_value_sat,
1640
+
channel_parameters,
1641
+
tx_has_htlc_outputs,
1642
+
insert_non_htlc_output
1643
+
);
1644
+
1599
1645
(outputs, nondust_htlcs)
1600
1646
}
1601
1647
1602
-
// Builds the set of outputs for the commitment transaction. Each HTLC output is paired with its corresponding data.
1603
-
// There will be an output for all passed HTLCs, since they are all non-dust.
1604
-
// Then depending on amounts, and features, this function assigns holder, counterparty, and anchor outputs.
1605
-
//
1606
-
// The set of outputs are sorted according to BIP-69 ordering, guaranteeing that HTLCs are
1607
-
// returned in increasing output index order.
1608
-
//
1609
-
// This is used in two cases:
1610
-
// - initial sorting of outputs / HTLCs in the constructor, via `build_outputs_and_htlcs`
1611
-
// - building of a bitcoin transaction during a verify() call
1612
-
//
1613
-
// Note that the HTLC data in the second column of the returned table is not populated with the
1614
-
// output indices of the HTLCs; this is done in `build_outputs_and_htlcs`.
0 commit comments