Skip to content

Commit 1080b0e

Browse files
committed
f: delete IncludedHTLC
1 parent ebd94c2 commit 1080b0e

File tree

2 files changed

+29
-51
lines changed

2 files changed

+29
-51
lines changed

lightning/src/ln/channel.rs

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -450,15 +450,6 @@ impl OutboundHTLCOutput {
450450
}
451451
}
452452

453-
#[derive(Clone, Debug)]
454-
pub(crate) struct IncludedHTLC {
455-
pub offered: bool,
456-
pub amount_msat: u64,
457-
pub cltv_expiry: u32,
458-
pub payment_hash: PaymentHash,
459-
pub is_dust: bool,
460-
}
461-
462453
/// See AwaitingRemoteRevoke ChannelState for more info
463454
#[cfg_attr(test, derive(Clone, Debug, PartialEq))]
464455
enum HTLCUpdateAwaitingACK {
@@ -4550,7 +4541,6 @@ where
45504541

45514542
let num_htlcs = self.pending_inbound_htlcs.len() + self.pending_outbound_htlcs.len();
45524543
let mut htlc_source_table: Vec<(HTLCOutputInCommitment, Option<&HTLCSource>)> = Vec::with_capacity(num_htlcs);
4553-
let mut htlcs_included: Vec<IncludedHTLC> = Vec::with_capacity(num_htlcs);
45544544
let mut value_to_self_claimed_msat = 0;
45554545
let mut value_to_remote_claimed_msat = 0;
45564546

@@ -4572,24 +4562,10 @@ where
45724562
}
45734563
}
45744564

4575-
macro_rules! get_included_htlc {
4576-
($htlc: expr, $offered: expr, $is_dust: expr) => {
4577-
IncludedHTLC {
4578-
offered: $offered,
4579-
amount_msat: $htlc.amount_msat,
4580-
cltv_expiry: $htlc.cltv_expiry,
4581-
payment_hash: $htlc.payment_hash,
4582-
is_dust: $is_dust,
4583-
}
4584-
}
4585-
}
4586-
45874565
macro_rules! add_htlc_output {
4588-
($htlc: expr, $outbound: expr, $source: expr, $is_dust: expr) => {
4589-
let table_htlc = get_htlc_in_commitment!($htlc, $outbound == local);
4590-
let included_htlc = get_included_htlc!($htlc, $outbound == local, $is_dust);
4591-
htlc_source_table.push((table_htlc, $source));
4592-
htlcs_included.push(included_htlc);
4566+
($htlc: expr, $outbound: expr, $source: expr) => {
4567+
let htlc = get_htlc_in_commitment!($htlc, $outbound == local);
4568+
htlc_source_table.push((htlc, $source));
45934569
}
45944570
}
45954571

@@ -4599,8 +4575,7 @@ where
45994575
for htlc in self.pending_inbound_htlcs.iter() {
46004576
if htlc.state.included_in_commitment(generated_by_local) {
46014577
log_trace!(logger, " ...including inbound {} HTLC {} (hash {}) with value {}", htlc.state, htlc.htlc_id, htlc.payment_hash, htlc.amount_msat);
4602-
let is_dust = htlc.is_dust(local, feerate_per_kw, broadcaster_dust_limit_sat, funding.get_channel_type());
4603-
add_htlc_output!(htlc, false, None, is_dust);
4578+
add_htlc_output!(htlc, false, None);
46044579
} else {
46054580
log_trace!(logger, " ...not including inbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, htlc.payment_hash, htlc.amount_msat, htlc.state);
46064581
if let Some(preimage) = htlc.state.preimage() {
@@ -4616,8 +4591,7 @@ where
46164591
}
46174592
if htlc.state.included_in_commitment(generated_by_local) {
46184593
log_trace!(logger, " ...including outbound {} HTLC {} (hash {}) with value {}", htlc.state, htlc.htlc_id, htlc.payment_hash, htlc.amount_msat);
4619-
let is_dust = htlc.is_dust(local, feerate_per_kw, broadcaster_dust_limit_sat, funding.get_channel_type());
4620-
add_htlc_output!(htlc, true, Some(&htlc.source), is_dust);
4594+
add_htlc_output!(htlc, true, Some(&htlc.source));
46214595
} else {
46224596
log_trace!(logger, " ...not including outbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, htlc.payment_hash, htlc.amount_msat, htlc.state);
46234597
if htlc.state.preimage().is_some() {
@@ -4639,7 +4613,7 @@ where
46394613
&funding.channel_transaction_parameters,
46404614
&self.secp_ctx,
46414615
value_to_self_msat,
4642-
htlcs_included,
4616+
htlc_source_table.iter().map(|(htlc, _source)| htlc).cloned().collect(),
46434617
feerate_per_kw,
46444618
broadcaster_dust_limit_sat,
46454619
logger,

lightning/src/sign/tx_builder.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ use core::ops::Deref;
55
use bitcoin::secp256k1::{self, PublicKey, Secp256k1};
66

77
use crate::ln::chan_utils::{
8-
commit_tx_fee_sat, ChannelTransactionParameters, CommitmentTransaction, HTLCOutputInCommitment,
8+
commit_tx_fee_sat, htlc_success_tx_weight, htlc_timeout_tx_weight,
9+
ChannelTransactionParameters, CommitmentTransaction, HTLCOutputInCommitment,
910
};
10-
use crate::ln::channel::{CommitmentStats, IncludedHTLC, ANCHOR_OUTPUT_VALUE_SATOSHI};
11+
use crate::ln::channel::{CommitmentStats, ANCHOR_OUTPUT_VALUE_SATOSHI};
1112
use crate::prelude::*;
1213
use crate::types::features::ChannelTypeFeatures;
1314
use crate::util::logger::Logger;
@@ -23,7 +24,7 @@ pub(crate) trait TxBuilder {
2324
fn build_commitment_transaction<L: Deref>(
2425
&self, local: bool, commitment_number: u64, per_commitment_point: &PublicKey,
2526
channel_parameters: &ChannelTransactionParameters, secp_ctx: &Secp256k1<secp256k1::All>,
26-
value_to_self_msat: u64, htlcs_in_tx: Vec<IncludedHTLC>, feerate_per_kw: u32,
27+
value_to_self_msat: u64, htlcs_in_tx: Vec<HTLCOutputInCommitment>, feerate_per_kw: u32,
2728
broadcaster_dust_limit_satoshis: u64, logger: &L,
2829
) -> (CommitmentTransaction, CommitmentStats)
2930
where
@@ -72,14 +73,30 @@ impl TxBuilder for SpecTxBuilder {
7273
fn build_commitment_transaction<L: Deref>(
7374
&self, local: bool, commitment_number: u64, per_commitment_point: &PublicKey,
7475
channel_parameters: &ChannelTransactionParameters, secp_ctx: &Secp256k1<secp256k1::All>,
75-
value_to_self_msat: u64, mut htlcs_in_tx: Vec<IncludedHTLC>, feerate_per_kw: u32,
76+
value_to_self_msat: u64, mut htlcs_in_tx: Vec<HTLCOutputInCommitment>, feerate_per_kw: u32,
7677
broadcaster_dust_limit_satoshis: u64, logger: &L,
7778
) -> (CommitmentTransaction, CommitmentStats)
7879
where
7980
L::Target: Logger,
8081
{
8182
let mut local_htlc_total_msat = 0;
8283
let mut remote_htlc_total_msat = 0;
84+
let channel_type = &channel_parameters.channel_type_features;
85+
86+
let is_dust = |offered: bool, amount_msat: u64| -> bool {
87+
let htlc_tx_fee_sat = if channel_type.supports_anchors_zero_fee_htlc_tx() {
88+
0
89+
} else {
90+
let htlc_tx_weight = if offered {
91+
htlc_timeout_tx_weight(channel_type)
92+
} else {
93+
htlc_success_tx_weight(channel_type)
94+
};
95+
// As required by the spec, round down
96+
feerate_per_kw as u64 * htlc_tx_weight / 1000
97+
};
98+
amount_msat / 1000 < broadcaster_dust_limit_satoshis + htlc_tx_fee_sat
99+
};
83100

84101
// Trim dust htlcs
85102
htlcs_in_tx.retain(|htlc| {
@@ -89,7 +106,7 @@ impl TxBuilder for SpecTxBuilder {
89106
} else {
90107
remote_htlc_total_msat += htlc.amount_msat;
91108
}
92-
if htlc.is_dust {
109+
if is_dust(htlc.offered, htlc.amount_msat) {
93110
log_trace!(
94111
logger,
95112
" ...trimming {} HTLC with value {}sat, hash {}, due to dust limit {}",
@@ -182,20 +199,7 @@ impl TxBuilder for SpecTxBuilder {
182199
to_broadcaster_value_sat,
183200
to_countersignatory_value_sat,
184201
feerate_per_kw,
185-
htlcs_in_tx
186-
.into_iter()
187-
.map(|htlc| {
188-
// We filtered out all dust HTLCs above
189-
debug_assert!(!htlc.is_dust);
190-
HTLCOutputInCommitment {
191-
offered: htlc.offered,
192-
amount_msat: htlc.amount_msat,
193-
cltv_expiry: htlc.cltv_expiry,
194-
payment_hash: htlc.payment_hash,
195-
transaction_output_index: None,
196-
}
197-
})
198-
.collect(),
202+
htlcs_in_tx,
199203
&directed_parameters,
200204
secp_ctx,
201205
);

0 commit comments

Comments
 (0)