Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,8 @@ pub enum Balance {
amount_satoshis: u64,
/// The transaction fee we pay for the closing commitment transaction. This amount is not
/// included in the [`Balance::ClaimableOnChannelClose::amount_satoshis`] value.
/// This amount includes the sum of dust HTLCs on the commitment transaction, any elided anchors,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit you might heave meant to include a newline here to create a paragraph break. when rustdocs renders it ignores line breaks unless there's a full empty line between sections of text, which creates a paragraph break. Makes the in-source docs look a little tall but the rendering isn't that bad.

/// as well as the sum of msat amounts rounded down from non-dust HTLCs.
///
/// Note that if this channel is inbound (and thus our counterparty pays the commitment
/// transaction fee) this value will be zero. For [`ChannelMonitor`]s created prior to LDK
Expand Down Expand Up @@ -2860,11 +2862,11 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
let to_self_value_sat = us.funding.current_holder_commitment_tx.to_broadcaster_value_sat();
res.push(Balance::ClaimableOnChannelClose {
amount_satoshis: to_self_value_sat + claimable_inbound_htlc_value_sat,
// In addition to `commit_tx_fee_sat`, this can also include dust HTLCs, and the total msat amount rounded down from non-dust HTLCs
// In addition to `commit_tx_fee_sat`, this can also include dust HTLCs, any elided anchors,
// and the total msat amount rounded down from non-dust HTLCs
transaction_fee_satoshis: if us.holder_pays_commitment_tx_fee.unwrap_or(true) {
let transaction = &us.funding.current_holder_commitment_tx.trust().built_transaction().transaction;
// Unwrap here; commitment transactions always have at least one output
let output_value_sat = transaction.output.iter().map(|txout| txout.value).reduce(|sum, value| sum + value).unwrap().to_sat();
let output_value_sat: u64 = transaction.output.iter().map(|txout| txout.value.to_sat()).sum();
us.funding.channel_parameters.channel_value_satoshis - output_value_sat
} else { 0 },
outbound_payment_htlc_rounded_msat,
Expand Down
37 changes: 23 additions & 14 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4140,12 +4140,17 @@ where
// Channel state once they will not be present in the next received commitment
// transaction).
let (local_balance_before_fee_msat, remote_balance_before_fee_msat) = {
let mut removed_outbound_total_msat = 0;
for htlc in self.pending_outbound_htlcs.iter() {
if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _)) | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _)) = htlc.state {
removed_outbound_total_msat += htlc.amount_msat;
}
}
let removed_outbound_total_msat: u64 = self.pending_outbound_htlcs
.iter()
.filter_map(|htlc| {
matches!(
htlc.state,
OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _))
| OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _))
)
.then_some(htlc.amount_msat)
})
.sum();
let pending_value_to_self_msat =
funding.value_to_self_msat + htlc_stats.pending_inbound_htlcs_value_msat - removed_outbound_total_msat;
let pending_remote_value_msat =
Expand Down Expand Up @@ -4372,13 +4377,17 @@ where
}

if !funding.is_outbound() {
let mut removed_outbound_total_msat = 0;
for htlc in self.pending_outbound_htlcs.iter() {
if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _)) | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _)) = htlc.state {
removed_outbound_total_msat += htlc.amount_msat;
}
}

let removed_outbound_total_msat: u64 = self.pending_outbound_htlcs
.iter()
.filter_map(|htlc| {
matches!(
htlc.state,
OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _))
| OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _))
)
.then_some(htlc.amount_msat)
})
.sum();
let pending_value_to_self_msat =
funding.value_to_self_msat + htlc_stats.pending_inbound_htlcs_value_msat - removed_outbound_total_msat;
let pending_remote_value_msat =
Expand Down Expand Up @@ -4615,7 +4624,7 @@ where
broadcaster_dust_limit_sat,
logger,
);
debug_assert_eq!(stats, self.build_commitment_stats(funding, local, generated_by_local, None, None));
debug_assert_eq!(stats, self.build_commitment_stats(funding, local, generated_by_local, None, None), "Caught an inconsistency between `TxBuilder::build_commitment_transaction` and the rest of the `TxBuilder` methods");

// This populates the HTLC-source table with the indices from the HTLCs in the commitment
// transaction.
Expand Down
Loading