Skip to content

Commit c1aba64

Browse files
committed
Delete TxBuilder::subtract_non_htlc_outputs
1 parent 027c822 commit c1aba64

File tree

1 file changed

+4
-36
lines changed

1 file changed

+4
-36
lines changed

lightning/src/sign/tx_builder.rs

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,6 @@ pub(crate) trait TxBuilder {
148148
fn commit_tx_fee_sat(
149149
&self, feerate_per_kw: u32, nondust_htlc_count: usize, channel_type: &ChannelTypeFeatures,
150150
) -> u64;
151-
fn subtract_non_htlc_outputs(
152-
&self, is_outbound_from_holder: bool, value_to_self_after_htlcs: u64,
153-
value_to_remote_after_htlcs: u64, channel_type: &ChannelTypeFeatures,
154-
) -> (u64, u64);
155151
fn build_commitment_transaction<L: Deref>(
156152
&self, local: bool, commitment_number: u64, per_commitment_point: &PublicKey,
157153
channel_parameters: &ChannelTransactionParameters, secp_ctx: &Secp256k1<secp256k1::All>,
@@ -413,36 +409,6 @@ impl TxBuilder for SpecTxBuilder {
413409
) -> u64 {
414410
commit_tx_fee_sat(feerate_per_kw, nondust_htlc_count, channel_type)
415411
}
416-
fn subtract_non_htlc_outputs(
417-
&self, is_outbound_from_holder: bool, value_to_self_after_htlcs: u64,
418-
value_to_remote_after_htlcs: u64, channel_type: &ChannelTypeFeatures,
419-
) -> (u64, u64) {
420-
let total_anchors_sat = if channel_type.supports_anchors_zero_fee_htlc_tx() {
421-
ANCHOR_OUTPUT_VALUE_SATOSHI * 2
422-
} else {
423-
0
424-
};
425-
426-
let mut local_balance_before_fee_msat = value_to_self_after_htlcs;
427-
let mut remote_balance_before_fee_msat = value_to_remote_after_htlcs;
428-
429-
// We MUST use saturating subs here, as the funder's balance is not guaranteed to be greater
430-
// than or equal to `total_anchors_sat`.
431-
//
432-
// This is because when the remote party sends an `update_fee` message, we build the new
433-
// commitment transaction *before* checking whether the remote party's balance is enough to
434-
// cover the total anchor sum.
435-
436-
if is_outbound_from_holder {
437-
local_balance_before_fee_msat =
438-
local_balance_before_fee_msat.saturating_sub(total_anchors_sat * 1000);
439-
} else {
440-
remote_balance_before_fee_msat =
441-
remote_balance_before_fee_msat.saturating_sub(total_anchors_sat * 1000);
442-
}
443-
444-
(local_balance_before_fee_msat, remote_balance_before_fee_msat)
445-
}
446412
#[rustfmt::skip]
447413
fn build_commitment_transaction<L: Deref>(
448414
&self, local: bool, commitment_number: u64, per_commitment_point: &PublicKey,
@@ -497,8 +463,10 @@ impl TxBuilder for SpecTxBuilder {
497463
let value_to_self_after_htlcs_msat = value_to_self_msat.checked_sub(local_htlc_total_msat).unwrap();
498464
let value_to_remote_after_htlcs_msat =
499465
(channel_parameters.channel_value_satoshis * 1000).checked_sub(value_to_self_msat).unwrap().checked_sub(remote_htlc_total_msat).unwrap();
500-
let (local_balance_before_fee_msat, remote_balance_before_fee_msat) =
501-
self.subtract_non_htlc_outputs(channel_parameters.is_outbound_from_holder, value_to_self_after_htlcs_msat, value_to_remote_after_htlcs_msat, &channel_parameters.channel_type_features);
466+
let (local_balance_before_fee_msat, remote_balance_before_fee_msat) = subtract_addl_outputs(
467+
channel_parameters.is_outbound_from_holder, Some(value_to_self_after_htlcs_msat), Some(value_to_remote_after_htlcs_msat), &channel_parameters.channel_type_features);
468+
let local_balance_before_fee_msat = local_balance_before_fee_msat.unwrap_or(0);
469+
let remote_balance_before_fee_msat = remote_balance_before_fee_msat.unwrap_or(0);
502470

503471
// We MUST use saturating subs here, as the funder's balance is not guaranteed to be greater
504472
// than or equal to `commit_tx_fee_sat`.

0 commit comments

Comments
 (0)