@@ -79,32 +79,33 @@ fn excess_fees_on_counterparty_tx_dust_exposure_msat(
79
79
}
80
80
81
81
fn subtract_addl_outputs (
82
- is_outbound_from_holder : bool , value_to_self_after_htlcs : Option < u64 > ,
83
- value_to_remote_after_htlcs : Option < u64 > , channel_type : & ChannelTypeFeatures ,
82
+ is_outbound_from_holder : bool , value_to_self_after_htlcs : u64 ,
83
+ value_to_remote_after_htlcs : u64 , channel_type : & ChannelTypeFeatures ,
84
84
) -> ( Option < u64 > , Option < u64 > ) {
85
85
let total_anchors_sat = if channel_type. supports_anchors_zero_fee_htlc_tx ( ) {
86
86
ANCHOR_OUTPUT_VALUE_SATOSHI * 2
87
87
} else {
88
88
0
89
89
} ;
90
90
91
- let mut local_balance_before_fee_msat = value_to_self_after_htlcs;
92
- let mut remote_balance_before_fee_msat = value_to_remote_after_htlcs;
93
-
94
91
// We MUST use checked subs here, as the funder's balance is not guaranteed to be greater
95
92
// than or equal to `total_anchors_sat`.
96
93
//
97
94
// This is because when the remote party sends an `update_fee` message, we build the new
98
95
// commitment transaction *before* checking whether the remote party's balance is enough to
99
96
// cover the total anchor sum.
100
97
101
- if is_outbound_from_holder {
102
- local_balance_before_fee_msat = local_balance_before_fee_msat
103
- . and_then ( |balance_msat| balance_msat. checked_sub ( total_anchors_sat * 1000 ) ) ;
98
+ let local_balance_before_fee_msat = if is_outbound_from_holder {
99
+ value_to_self_after_htlcs. checked_sub ( total_anchors_sat * 1000 )
104
100
} else {
105
- remote_balance_before_fee_msat = remote_balance_before_fee_msat
106
- . and_then ( |balance_msat| balance_msat. checked_sub ( total_anchors_sat * 1000 ) ) ;
107
- }
101
+ Some ( value_to_self_after_htlcs)
102
+ } ;
103
+
104
+ let remote_balance_before_fee_msat = if !is_outbound_from_holder {
105
+ value_to_remote_after_htlcs. checked_sub ( total_anchors_sat * 1000 )
106
+ } else {
107
+ Some ( value_to_remote_after_htlcs)
108
+ } ;
108
109
109
110
( local_balance_before_fee_msat, remote_balance_before_fee_msat)
110
111
}
@@ -181,10 +182,12 @@ impl TxBuilder for SpecTxBuilder {
181
182
. iter ( )
182
183
. filter_map ( |htlc| ( !htlc. outbound ) . then_some ( htlc. amount_msat ) )
183
184
. sum ( ) ;
184
- let value_to_holder_after_htlcs =
185
- value_to_holder_msat. checked_sub ( outbound_htlcs_value_msat) ;
186
- let value_to_counterparty_after_htlcs =
187
- value_to_counterparty_msat. checked_sub ( inbound_htlcs_value_msat) ;
185
+ let value_to_holder_after_htlcs = value_to_holder_msat
186
+ . checked_sub ( outbound_htlcs_value_msat)
187
+ . expect ( "outbound_htlcs_value_msat is greater than value_to_holder_msat" ) ;
188
+ let value_to_counterparty_after_htlcs = value_to_counterparty_msat
189
+ . checked_sub ( inbound_htlcs_value_msat)
190
+ . expect ( "inbound_htlcs_value_msat is greater than value_to_counterparty_msat" ) ;
188
191
189
192
// Subtract the anchors from the channel funder
190
193
let ( holder_balance_msat, counterparty_balance_msat) = subtract_addl_outputs (
0 commit comments