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
Reorder the operations in ChannelContext::build_commitment_transaction
This reorganizes the logic in
`ChannelContext::build_commitment_transaction` to clearly separate the
sorting of HTLCs for a commitment transaction based on their state from
the trimming of HTLCs based on the broadcaster's dust limit.
In the future, transaction builders will decide how to handle HTLCs
below the dust limit, but they will not decide which HTLCs to include
based on their state.
log_trace!(logger, " ...including inbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, &htlc.payment_hash, htlc.amount_msat, state_name);
3476
+
let htlc = get_htlc_in_commitment!(htlc, !local);
3477
+
htlcs_in_tx.push((htlc, None));
3504
3478
} else {
3505
3479
log_trace!(logger, " ...not including inbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, &htlc.payment_hash, htlc.amount_msat, state_name);
log_trace!(logger, " ...including outbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, &htlc.payment_hash, htlc.amount_msat, state_name);
3514
+
let htlc_in_tx = get_htlc_in_commitment!(htlc, local);
log_trace!(logger, " ...not including outbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, &htlc.payment_hash, htlc.amount_msat, state_name);
let htlc_tx_fee = if self.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
3539
+
0
3540
+
} else {
3541
+
feerate_per_kw as u64 * htlc_timeout_tx_weight(self.get_channel_type()) / 1000
3542
+
};
3543
+
if htlc.amount_msat / 1000 >= broadcaster_dust_limit_satoshis + htlc_tx_fee {
3544
+
log_trace!(logger, " ...creating output for {} non-dust HTLC (hash {}) with value {}", if outbound { "outbound" } else { "inbound" }, htlc.payment_hash, htlc.amount_msat);
3545
+
included_non_dust_htlcs.push(htlc);
3546
+
} else {
3547
+
log_trace!(logger, " ...trimming {} HTLC (hash {}) with value {} due to dust limit", if outbound { "outbound" } else { "inbound" }, htlc.payment_hash, htlc.amount_msat);
3548
+
}
3549
+
} else {
3550
+
let outbound = !local;
3551
+
if outbound {
3552
+
local_htlc_total_msat += htlc.amount_msat;
3553
+
} else {
3554
+
remote_htlc_total_msat += htlc.amount_msat;
3555
+
}
3556
+
let htlc_tx_fee = if self.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
3557
+
0
3558
+
} else {
3559
+
feerate_per_kw as u64 * htlc_success_tx_weight(self.get_channel_type()) / 1000
3560
+
};
3561
+
if htlc.amount_msat / 1000 >= broadcaster_dust_limit_satoshis + htlc_tx_fee {
3562
+
log_trace!(logger, " ...creating output for {} non-dust HTLC (hash {}) with value {}", if outbound { "outbound" } else { "inbound" }, htlc.payment_hash, htlc.amount_msat);
3563
+
included_non_dust_htlcs.push(htlc);
3564
+
} else {
3565
+
log_trace!(logger, " ...trimming {} HTLC (hash {}) with value {} due to dust limit", if outbound { "outbound" } else { "inbound" }, htlc.payment_hash, htlc.amount_msat);
3566
+
}
3567
+
}
3568
+
}
3569
+
3555
3570
// TODO: When MSRV >= 1.66.0, use u64::checked_add_signed
3556
3571
let mut value_to_self_msat = u64::try_from(funding.value_to_self_msat as i64 + value_to_self_msat_offset).unwrap();
3557
3572
// Note that in case they have several just-awaiting-last-RAA fulfills in-progress (ie
0 commit comments