Skip to content

Commit c76b382

Browse files
committed
Rename CommitmentTransaction::htlcs to nondust_htlcs
1 parent 1a8bdb2 commit c76b382

File tree

5 files changed

+51
-51
lines changed

5 files changed

+51
-51
lines changed

Diff for: lightning/src/chain/channelmonitor.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ impl HolderCommitment {
317317
let delayed_payment_key = &tx_keys.broadcaster_delayed_payment_key;
318318
let per_commitment_point = &tx_keys.per_commitment_point;
319319

320-
let mut nondust_htlcs = self.tx.htlcs().iter().zip(self.tx.counterparty_htlc_sigs.iter());
320+
let mut nondust_htlcs = self.tx.nondust_htlcs().iter().zip(self.tx.counterparty_htlc_sigs.iter());
321321
let mut sources = self.nondust_htlc_sources.iter();
322322

323323
// Use an iterator to write `htlc_outputs` to avoid allocations.
@@ -937,7 +937,7 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment
937937
// HTLC sources, separately. All offered, non-dust HTLCs must have a source available.
938938

939939
let mut missing_nondust_source = false;
940-
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.htlcs().len());
940+
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.nondust_htlcs().len());
941941
let dust_htlcs = holder_signed_tx.htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
942942
// Filter our non-dust HTLCs, while at the same time pushing their sources into
943943
// `nondust_htlc_sources`.
@@ -967,16 +967,16 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment
967967

968968
impl HolderCommitment {
969969
fn has_htlcs(&self) -> bool {
970-
self.tx.htlcs().len() > 0 || self.dust_htlcs.len() > 0
970+
self.tx.nondust_htlcs().len() > 0 || self.dust_htlcs.len() > 0
971971
}
972972

973973
fn htlcs(&self) -> impl Iterator<Item = &HTLCOutputInCommitment> {
974-
self.tx.htlcs().iter().chain(self.dust_htlcs.iter().map(|(htlc, _)| htlc))
974+
self.tx.nondust_htlcs().iter().chain(self.dust_htlcs.iter().map(|(htlc, _)| htlc))
975975
}
976976

977977
fn htlcs_with_sources(&self) -> impl Iterator<Item = (&HTLCOutputInCommitment, Option<&HTLCSource>)> {
978978
let mut sources = self.nondust_htlc_sources.iter();
979-
let nondust_htlcs = self.tx.htlcs().iter().map(move |htlc| {
979+
let nondust_htlcs = self.tx.nondust_htlcs().iter().map(move |htlc| {
980980
let mut source = None;
981981
if htlc.offered && htlc.transaction_output_index.is_some() {
982982
source = sources.next();
@@ -3093,8 +3093,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
30933093
// If we have non-dust HTLCs in htlc_outputs, ensure they match the HTLCs in the
30943094
// `holder_commitment_tx`. In the future, we'll no longer provide the redundant data
30953095
// and just pass in source data via `nondust_htlc_sources`.
3096-
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.trust().htlcs().len());
3097-
for (a, b) in htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).map(|(h, _, _)| h).zip(holder_commitment_tx.trust().htlcs().iter()) {
3096+
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.trust().nondust_htlcs().len());
3097+
for (a, b) in htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).map(|(h, _, _)| h).zip(holder_commitment_tx.trust().nondust_htlcs().iter()) {
30983098
debug_assert_eq!(a, b);
30993099
}
31003100
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.counterparty_htlc_sigs.len());
@@ -3104,7 +3104,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
31043104

31053105
// Backfill the non-dust HTLC sources.
31063106
debug_assert!(nondust_htlc_sources.is_empty());
3107-
nondust_htlc_sources.reserve_exact(holder_commitment_tx.htlcs().len());
3107+
nondust_htlc_sources.reserve_exact(holder_commitment_tx.nondust_htlcs().len());
31083108
let dust_htlcs = htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
31093109
// Filter our non-dust HTLCs, while at the same time pushing their sources into
31103110
// `nondust_htlc_sources`.
@@ -3124,18 +3124,18 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
31243124
// `nondust_htlc_sources` and the `holder_commitment_tx`
31253125
{
31263126
let mut prev = -1;
3127-
for htlc in holder_commitment_tx.trust().htlcs().iter() {
3127+
for htlc in holder_commitment_tx.trust().nondust_htlcs().iter() {
31283128
assert!(htlc.transaction_output_index.unwrap() as i32 > prev);
31293129
prev = htlc.transaction_output_index.unwrap() as i32;
31303130
}
31313131
}
31323132

31333133
debug_assert!(htlc_outputs.iter().all(|(htlc, _, _)| htlc.transaction_output_index.is_none()));
31343134
debug_assert!(htlc_outputs.iter().all(|(_, sig_opt, _)| sig_opt.is_none()));
3135-
debug_assert_eq!(holder_commitment_tx.trust().htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());
3135+
debug_assert_eq!(holder_commitment_tx.trust().nondust_htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());
31363136

31373137
let mut sources = nondust_htlc_sources.iter();
3138-
for htlc in holder_commitment_tx.trust().htlcs().iter() {
3138+
for htlc in holder_commitment_tx.trust().nondust_htlcs().iter() {
31393139
if htlc.offered {
31403140
let source = sources.next().expect("Non-dust HTLC sources didn't match commitment tx");
31413141
assert!(source.possibly_matches_output(htlc));
@@ -3526,7 +3526,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
35263526
let counterparty_node_id = self.counterparty_node_id;
35273527
let commitment_txid = commitment_tx.compute_txid();
35283528
debug_assert_eq!(self.funding.current_holder_commitment.tx.trust().txid(), commitment_txid);
3529-
let pending_htlcs = self.funding.current_holder_commitment.tx.trust().htlcs().to_vec();
3529+
let pending_htlcs = self.funding.current_holder_commitment.tx.trust().nondust_htlcs().to_vec();
35303530
let channel_value_satoshis = self.funding.channel_parameters.channel_value_satoshis;
35313531
let commitment_tx_fee_satoshis = channel_value_satoshis -
35323532
commitment_tx.output.iter().fold(0u64, |sum, output| sum + output.value.to_sat());
@@ -3973,7 +3973,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39733973
fn get_broadcasted_holder_claims(
39743974
&self, holder_tx: &HolderCommitmentTransaction, conf_height: u32,
39753975
) -> (Vec<PackageTemplate>, Option<(ScriptBuf, PublicKey, RevocationKey)>) {
3976-
let mut claim_requests = Vec::with_capacity(holder_tx.htlcs().len());
3976+
let mut claim_requests = Vec::with_capacity(holder_tx.nondust_htlcs().len());
39773977

39783978
let tx = holder_tx.trust();
39793979
let keys = tx.keys();
@@ -3985,7 +3985,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39853985
));
39863986

39873987
let txid = tx.txid();
3988-
for htlc in holder_tx.htlcs() {
3988+
for htlc in holder_tx.nondust_htlcs() {
39893989
if let Some(transaction_output_index) = htlc.transaction_output_index {
39903990
let (htlc_output, counterparty_spendable_height) = if htlc.offered {
39913991
let htlc_output = HolderHTLCOutput::build_offered(
@@ -4020,9 +4020,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
40204020

40214021
// Returns holder HTLC outputs to watch and react to in case of spending.
40224022
fn get_broadcasted_holder_watch_outputs(&self, holder_tx: &HolderCommitmentTransaction) -> Vec<(u32, TxOut)> {
4023-
let mut watch_outputs = Vec::with_capacity(holder_tx.htlcs().len());
4023+
let mut watch_outputs = Vec::with_capacity(holder_tx.nondust_htlcs().len());
40244024
let tx = holder_tx.trust();
4025-
for htlc in holder_tx.htlcs() {
4025+
for htlc in holder_tx.nondust_htlcs() {
40264026
if let Some(transaction_output_index) = htlc.transaction_output_index {
40274027
watch_outputs.push((
40284028
transaction_output_index,
@@ -4115,7 +4115,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
41154115
let txid = self.funding.current_holder_commitment.tx.trust().txid();
41164116
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}", txid);
41174117
let mut outpoint = BitcoinOutPoint { txid, vout: 0 };
4118-
for htlc in self.funding.current_holder_commitment.tx.htlcs() {
4118+
for htlc in self.funding.current_holder_commitment.tx.nondust_htlcs() {
41194119
if let Some(vout) = htlc.transaction_output_index {
41204120
outpoint.vout = vout;
41214121
self.onchain_tx_handler.abandon_claim(&outpoint);
@@ -4129,7 +4129,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
41294129
if txid != *confirmed_commitment_txid {
41304130
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}", txid);
41314131
let mut outpoint = BitcoinOutPoint { txid, vout: 0 };
4132-
for htlc in prev_holder_commitment.tx.htlcs() {
4132+
for htlc in prev_holder_commitment.tx.nondust_htlcs() {
41334133
if let Some(vout) = htlc.transaction_output_index {
41344134
outpoint.vout = vout;
41354135
self.onchain_tx_handler.abandon_claim(&outpoint);
@@ -4155,7 +4155,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
41554155
if self.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
41564156
return holder_transactions;
41574157
}
4158-
for htlc in self.funding.current_holder_commitment.tx.htlcs() {
4158+
for htlc in self.funding.current_holder_commitment.tx.nondust_htlcs() {
41594159
if let Some(vout) = htlc.transaction_output_index {
41604160
let preimage = if !htlc.offered {
41614161
if let Some((preimage, _)) = self.payment_preimages.get(&htlc.payment_hash) { Some(preimage.clone()) } else {

Diff for: lightning/src/chain/onchaintx.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
12051205
if trusted_tx.txid() != outp.txid {
12061206
return None;
12071207
}
1208-
let (htlc_idx, htlc) = trusted_tx.htlcs().iter().enumerate()
1208+
let (htlc_idx, htlc) = trusted_tx.nondust_htlcs().iter().enumerate()
12091209
.find(|(_, htlc)| htlc.transaction_output_index.unwrap() == outp.vout)
12101210
.unwrap();
12111211
let counterparty_htlc_sig = holder_commitment.counterparty_htlc_sigs[htlc_idx];
@@ -1248,7 +1248,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
12481248
if outp.txid != trusted_tx.txid() {
12491249
return None;
12501250
}
1251-
trusted_tx.htlcs().iter().enumerate()
1251+
trusted_tx.nondust_htlcs().iter().enumerate()
12521252
.find(|(_, htlc)| if let Some(output_index) = htlc.transaction_output_index {
12531253
output_index == outp.vout
12541254
} else {

Diff for: lightning/src/ln/chan_utils.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ pub struct CommitmentTransaction {
14231423
feerate_per_kw: u32,
14241424
// The set of non-dust HTLCs included in the commitment. They must be sorted in increasing
14251425
// output index order.
1426-
htlcs: Vec<HTLCOutputInCommitment>,
1426+
nondust_htlcs: Vec<HTLCOutputInCommitment>,
14271427
// Note that on upgrades, some features of existing outputs may be missed.
14281428
channel_type_features: ChannelTypeFeatures,
14291429
// A cache of the parties' pubkeys required to construct the transaction, see doc for trust()
@@ -1439,7 +1439,7 @@ impl PartialEq for CommitmentTransaction {
14391439
self.to_broadcaster_value_sat == o.to_broadcaster_value_sat &&
14401440
self.to_countersignatory_value_sat == o.to_countersignatory_value_sat &&
14411441
self.feerate_per_kw == o.feerate_per_kw &&
1442-
self.htlcs == o.htlcs &&
1442+
self.nondust_htlcs == o.nondust_htlcs &&
14431443
self.channel_type_features == o.channel_type_features &&
14441444
self.keys == o.keys;
14451445
if eq {
@@ -1461,7 +1461,7 @@ impl Writeable for CommitmentTransaction {
14611461
(6, self.feerate_per_kw, required),
14621462
(8, self.keys, required),
14631463
(10, self.built, required),
1464-
(12, self.htlcs, required_vec),
1464+
(12, self.nondust_htlcs, required_vec),
14651465
(14, legacy_deserialization_prevention_marker, option),
14661466
(15, self.channel_type_features, required),
14671467
});
@@ -1479,7 +1479,7 @@ impl Readable for CommitmentTransaction {
14791479
(6, feerate_per_kw, required),
14801480
(8, keys, required),
14811481
(10, built, required),
1482-
(12, htlcs, required_vec),
1482+
(12, nondust_htlcs, required_vec),
14831483
(14, _legacy_deserialization_prevention_marker, (option, explicit_type: ())),
14841484
(15, channel_type_features, option),
14851485
});
@@ -1496,7 +1496,7 @@ impl Readable for CommitmentTransaction {
14961496
feerate_per_kw: feerate_per_kw.0.unwrap(),
14971497
keys: keys.0.unwrap(),
14981498
built: built.0.unwrap(),
1499-
htlcs,
1499+
nondust_htlcs,
15001500
channel_type_features: channel_type_features.unwrap_or(ChannelTypeFeatures::only_static_remote_key())
15011501
})
15021502
}
@@ -1519,7 +1519,7 @@ impl CommitmentTransaction {
15191519
let keys = TxCreationKeys::from_channel_static_keys(per_commitment_point, channel_parameters.broadcaster_pubkeys(), channel_parameters.countersignatory_pubkeys(), secp_ctx);
15201520

15211521
// Sort outputs and populate output indices while keeping track of the auxiliary data
1522-
let (outputs, htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters);
1522+
let (outputs, nondust_htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters);
15231523

15241524
let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(commitment_number, channel_parameters);
15251525
let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
@@ -1530,7 +1530,7 @@ impl CommitmentTransaction {
15301530
to_countersignatory_value_sat,
15311531
to_broadcaster_delay: Some(channel_parameters.contest_delay()),
15321532
feerate_per_kw,
1533-
htlcs,
1533+
nondust_htlcs,
15341534
channel_type_features: channel_parameters.channel_type_features().clone(),
15351535
keys,
15361536
built: BuiltCommitmentTransaction {
@@ -1551,7 +1551,7 @@ impl CommitmentTransaction {
15511551
fn internal_rebuild_transaction(&self, keys: &TxCreationKeys, channel_parameters: &DirectedChannelTransactionParameters) -> BuiltCommitmentTransaction {
15521552
let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(self.commitment_number, channel_parameters);
15531553

1554-
let mut htlcs_with_aux = self.htlcs.iter().map(|h| (h.clone(), ())).collect();
1554+
let mut htlcs_with_aux = self.nondust_htlcs.iter().map(|h| (h.clone(), ())).collect();
15551555
let (outputs, _) = Self::internal_build_outputs(keys, self.to_broadcaster_value_sat, self.to_countersignatory_value_sat, &mut htlcs_with_aux, channel_parameters);
15561556

15571557
let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
@@ -1646,7 +1646,7 @@ impl CommitmentTransaction {
16461646
}
16471647
}
16481648

1649-
let mut htlcs = Vec::with_capacity(htlcs_with_aux.len());
1649+
let mut nondust_htlcs = Vec::with_capacity(htlcs_with_aux.len());
16501650
for (htlc, _) in htlcs_with_aux {
16511651
let script = get_htlc_redeemscript(htlc, channel_type, keys);
16521652
let txout = TxOut {
@@ -1676,11 +1676,11 @@ impl CommitmentTransaction {
16761676
for (idx, out) in txouts.drain(..).enumerate() {
16771677
if let Some(htlc) = out.1 {
16781678
htlc.transaction_output_index = Some(idx as u32);
1679-
htlcs.push(htlc.clone());
1679+
nondust_htlcs.push(htlc.clone());
16801680
}
16811681
outputs.push(out.0);
16821682
}
1683-
(outputs, htlcs)
1683+
(outputs, nondust_htlcs)
16841684
}
16851685

16861686
fn internal_build_inputs(commitment_number: u64, channel_parameters: &DirectedChannelTransactionParameters) -> (u64, Vec<TxIn>) {
@@ -1739,8 +1739,8 @@ impl CommitmentTransaction {
17391739
///
17401740
/// This is not exported to bindings users as we cannot currently convert Vec references to/from C, though we should
17411741
/// expose a less effecient version which creates a Vec of references in the future.
1742-
pub fn htlcs(&self) -> &Vec<HTLCOutputInCommitment> {
1743-
&self.htlcs
1742+
pub fn nondust_htlcs(&self) -> &Vec<HTLCOutputInCommitment> {
1743+
&self.nondust_htlcs
17441744
}
17451745

17461746
/// Trust our pre-built transaction and derived transaction creation public keys.
@@ -1824,10 +1824,10 @@ impl<'a> TrustedCommitmentTransaction<'a> {
18241824
let inner = self.inner;
18251825
let keys = &inner.keys;
18261826
let txid = inner.built.txid;
1827-
let mut ret = Vec::with_capacity(inner.htlcs.len());
1827+
let mut ret = Vec::with_capacity(inner.nondust_htlcs.len());
18281828
let holder_htlc_key = derive_private_key(secp_ctx, &inner.keys.per_commitment_point, htlc_base_key);
18291829

1830-
for this_htlc in inner.htlcs.iter() {
1830+
for this_htlc in inner.nondust_htlcs.iter() {
18311831
assert!(this_htlc.transaction_output_index.is_some());
18321832
let htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, &self.channel_type_features, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
18331833

@@ -1845,7 +1845,7 @@ impl<'a> TrustedCommitmentTransaction<'a> {
18451845
preimage: &Option<PaymentPreimage>,
18461846
) -> Transaction {
18471847
let keys = &self.inner.keys;
1848-
let this_htlc = &self.inner.htlcs[htlc_index];
1848+
let this_htlc = &self.inner.nondust_htlcs[htlc_index];
18491849
assert!(this_htlc.transaction_output_index.is_some());
18501850
// if we don't have preimage for an HTLC-Success, we can't generate an HTLC transaction.
18511851
if !this_htlc.offered && preimage.is_none() { unreachable!(); }
@@ -1867,7 +1867,7 @@ impl<'a> TrustedCommitmentTransaction<'a> {
18671867
) -> Witness {
18681868
let keys = &self.inner.keys;
18691869
let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(
1870-
&self.inner.htlcs[htlc_index], &self.channel_type_features, &keys.broadcaster_htlc_key,
1870+
&self.inner.nondust_htlcs[htlc_index], &self.channel_type_features, &keys.broadcaster_htlc_key,
18711871
&keys.countersignatory_htlc_key, &keys.revocation_key
18721872
);
18731873
build_htlc_input_witness(

0 commit comments

Comments
 (0)