Skip to content

Commit be6ea4e

Browse files
committed
fixup: Rename balance members to highlight they don't include fees
1 parent b2a7d2c commit be6ea4e

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

lightning/src/ln/channel.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4350,7 +4350,7 @@ where
43504350
return Err(ChannelError::close(format!("Remote HTLC add would put them over our max HTLC value ({})", self.holder_max_htlc_value_in_flight_msat)));
43514351
}
43524352

4353-
let remote_balance_before_fee_msat = next_remote_commitment_stats.counterparty_balance_msat.ok_or(ChannelError::close("Remote HTLC add would overdraw remaining funds".to_owned()))?;
4353+
let remote_balance_before_fee_msat = next_remote_commitment_stats.counterparty_balance_before_fee_msat.ok_or(ChannelError::close("Remote HTLC add would overdraw remaining funds".to_owned()))?;
43544354

43554355
// Check that the remote can afford to pay for this HTLC on-chain at the current
43564356
// feerate_per_kw, while maintaining their channel reserve (as required by the spec).
@@ -4381,7 +4381,7 @@ where
43814381

43824382
if funding.is_outbound() {
43834383
let next_local_commitment_stats = self.get_next_local_commitment_stats(funding, Some(HTLCAmountDirection { outbound: false, amount_msat: msg.amount_msat }), include_counterparty_unknown_htlcs, fee_spike_buffer_htlc, self.feerate_per_kw, dust_exposure_limiting_feerate);
4384-
let holder_balance_msat = next_local_commitment_stats.holder_balance_msat.expect("Adding an inbound HTLC should never exhaust the holder's balance before fees");
4384+
let holder_balance_msat = next_local_commitment_stats.holder_balance_before_fee_msat.expect("Adding an inbound HTLC should never exhaust the holder's balance before fees");
43854385
// Check that they won't violate our local required channel reserve by adding this HTLC.
43864386
if holder_balance_msat < funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 + next_local_commitment_stats.commit_tx_fee_sat * 1000 {
43874387
return Err(ChannelError::close("Cannot accept HTLC that would put our balance under counterparty-announced channel reserve value".to_owned()));
@@ -4520,7 +4520,7 @@ where
45204520
// Include outbound update_add_htlc's in the holding cell, and those which haven't yet been ACK'ed by the counterparty (ie. LocalAnnounced HTLCs)
45214521
let include_counterparty_unknown_htlcs = true;
45224522
let next_remote_commitment_stats = self.get_next_remote_commitment_stats(funding, None, include_counterparty_unknown_htlcs, CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize, feerate_per_kw, dust_exposure_limiting_feerate);
4523-
let holder_balance_msat = next_remote_commitment_stats.holder_balance_msat.expect("The holder's balance before fees should never underflow.");
4523+
let holder_balance_msat = next_remote_commitment_stats.holder_balance_before_fee_msat.expect("The holder's balance before fees should never underflow.");
45244524
// Note that `stats.commit_tx_fee_sat` accounts for any HTLCs that transition from non-dust to dust under a higher feerate (in the case where HTLC-transactions pay endogenous fees).
45254525
if holder_balance_msat < next_remote_commitment_stats.commit_tx_fee_sat * 1000 + funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 {
45264526
//TODO: auto-close after a number of failures?
@@ -4588,7 +4588,7 @@ where
45884588
}
45894589
// We unwrap here; if the HTLC exhausts the counterparty's balance, we should have rejected it at `update_add_htlc`, here the HTLC is already
45904590
// irrevocably committed to the channel.
4591-
let remote_balance_before_fee_msat = next_remote_commitment_stats.counterparty_balance_msat.expect("The counterparty's balance before fees should never underflow");
4591+
let remote_balance_before_fee_msat = next_remote_commitment_stats.counterparty_balance_before_fee_msat.expect("The counterparty's balance before fees should never underflow");
45924592
if remote_balance_before_fee_msat.saturating_sub(funding.holder_selected_channel_reserve_satoshis * 1000) < remote_fee_incl_fee_spike_buffer_htlc_msat {
45934593
log_info!(logger, "Attempting to fail HTLC due to fee spike buffer violation in channel {}. Rebalancing is required.", &self.channel_id());
45944594
return Err(LocalHTLCFailureReason::FeeSpikeBuffer);

lightning/src/sign/tx_builder.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ impl HTLCAmountDirection {
3737
pub(crate) struct NextCommitmentStats {
3838
pub inbound_htlcs_count: usize,
3939
pub inbound_htlcs_value_msat: u64,
40-
pub holder_balance_msat: Option<u64>,
41-
pub counterparty_balance_msat: Option<u64>,
40+
pub holder_balance_before_fee_msat: Option<u64>,
41+
pub counterparty_balance_before_fee_msat: Option<u64>,
4242
pub nondust_htlc_count: usize,
4343
pub commit_tx_fee_sat: u64,
4444
pub dust_exposure_msat: u64,
@@ -187,12 +187,13 @@ impl TxBuilder for SpecTxBuilder {
187187
value_to_counterparty_msat.checked_sub(inbound_htlcs_value_msat);
188188

189189
// Subtract the anchors from the channel funder
190-
let (holder_balance_msat, counterparty_balance_msat) = subtract_addl_outputs(
191-
is_outbound_from_holder,
192-
value_to_holder_after_htlcs_msat,
193-
value_to_counterparty_after_htlcs_msat,
194-
channel_type,
195-
);
190+
let (holder_balance_before_fee_msat, counterparty_balance_before_fee_msat) =
191+
subtract_addl_outputs(
192+
is_outbound_from_holder,
193+
value_to_holder_after_htlcs_msat,
194+
value_to_counterparty_after_htlcs_msat,
195+
channel_type,
196+
);
196197

197198
// Increment the feerate by a buffer to calculate dust exposure
198199
let dust_buffer_feerate = get_dust_buffer_feerate(feerate_per_kw);
@@ -244,8 +245,8 @@ impl TxBuilder for SpecTxBuilder {
244245
NextCommitmentStats {
245246
inbound_htlcs_count,
246247
inbound_htlcs_value_msat,
247-
holder_balance_msat,
248-
counterparty_balance_msat,
248+
holder_balance_before_fee_msat,
249+
counterparty_balance_before_fee_msat,
249250
nondust_htlc_count: nondust_htlc_count + addl_nondust_htlc_count,
250251
commit_tx_fee_sat,
251252
dust_exposure_msat,

0 commit comments

Comments
 (0)