Skip to content

Commit 5ac7b10

Browse files
TheBlueMattdunxen
authored andcommitted
Explain how rounded millisat values are included in overall balance
1 parent 2b0fbd5 commit 5ac7b10

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,25 +635,37 @@ pub enum Balance {
635635
/// [`Balance::MaybeTimeoutClaimableHTLC`] with their
636636
/// [`Balance::MaybeTimeoutClaimableHTLC::outbound_payment`] flag set, as well as any dust
637637
/// HTLCs which would otherwise be represented the same.
638+
///
639+
/// This value will not be included in `amount_satoshis` and any representable (quotient
640+
/// when divided by 1000 without the remainder) value will go toward fees
638641
outbound_payment_htlc_rounded_msat: u64,
639642
/// The amount of millisatoshis which has been burned to fees from HTLCs which are outbound
640643
/// from us and are related to a forwarded HTLC. This is the sum of the millisatoshis part
641644
/// of all HTLCs which are otherwise represented by [`Balance::MaybeTimeoutClaimableHTLC`]
642645
/// with their [`Balance::MaybeTimeoutClaimableHTLC::outbound_payment`] flag *not* set, as
643646
/// well as any dust HTLCs which would otherwise be represented the same.
647+
///
648+
/// This value will not be included in `amount_satoshis` and any representable (quotient
649+
/// when divided by 1000 without the remainder) value will go toward fees
644650
outbound_forwarded_htlc_rounded_msat: u64,
645651
/// The amount of millisatoshis which has been burned to fees from HTLCs which are inbound
646652
/// to us and for which we know the preimage. This is the sum of the millisatoshis part of
647653
/// all HTLCs which would be represented by [`Balance::ContentiousClaimable`] on channel
648654
/// close, but who's current value is included in
649655
/// [`Balance::ClaimableOnChannelClose::amount_satoshis`], as well as any dust HTLCs which
650656
/// would otherwise be represented the same.
657+
///
658+
/// This value will not be included in `amount_satoshis` and any representable (quotient
659+
/// when divided by 1000 without the remainder) value will go toward fees
651660
inbound_claiming_htlc_rounded_msat: u64,
652661
/// The amount of millisatoshis which has been burned to fees from HTLCs which are inbound
653662
/// to us and for which we do not know the preimage. This is the sum of the millisatoshis
654663
/// part of all HTLCs which would be represented by [`Balance::MaybePreimageClaimableHTLC`]
655664
/// on channel close, as well as any dust HTLCs which would otherwise be represented the
656665
/// same.
666+
///
667+
/// This value will not be included in `amount_satoshis` and any representable (quotient
668+
/// when divided by 1000 without the remainder) value will go toward fees
657669
inbound_htlc_rounded_msat: u64,
658670
},
659671
/// The channel has been closed, and the given balance is ours but awaiting confirmations until
@@ -2338,6 +2350,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23382350
}
23392351
}
23402352
} else {
2353+
let mut expected_tx_value_sats = if us.holder_pays_commitment_tx_fee.unwrap_or(true) {
2354+
us.channel_value_satoshis
2355+
} else { 0 };
23412356
let mut claimable_inbound_htlc_value_sat = 0;
23422357
let mut nondust_htlc_count = 0;
23432358
let mut outbound_payment_htlc_rounded_msat = 0;
@@ -2365,6 +2380,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23652380
} else {
23662381
outbound_forwarded_htlc_rounded_msat += rounded_value_msat;
23672382
}
2383+
expected_tx_value_sats = expected_tx_value_sats.saturating_sub((htlc.amount_msat + 999) / 1000);
23682384
if htlc.transaction_output_index.is_some() {
23692385
res.push(Balance::MaybeTimeoutClaimableHTLC {
23702386
amount_satoshis: htlc.amount_msat / 1000,
@@ -2391,12 +2407,13 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23912407
}
23922408
}
23932409
}
2410+
let tx_fee_satoshis = chan_utils::commit_tx_fee_sat(
2411+
us.current_holder_commitment_tx.feerate_per_kw, nondust_htlc_count,
2412+
us.onchain_tx_handler.channel_type_features());
23942413
res.push(Balance::ClaimableOnChannelClose {
23952414
amount_satoshis: us.current_holder_commitment_tx.to_self_value_sat + claimable_inbound_htlc_value_sat,
23962415
transaction_fee_satoshis: if us.holder_pays_commitment_tx_fee.unwrap_or(true) {
2397-
chan_utils::commit_tx_fee_sat(
2398-
us.current_holder_commitment_tx.feerate_per_kw, nondust_htlc_count,
2399-
us.onchain_tx_handler.channel_type_features())
2416+
tx_fee_satoshis
24002417
} else { 0 },
24012418
outbound_payment_htlc_rounded_msat,
24022419
outbound_forwarded_htlc_rounded_msat,

0 commit comments

Comments
 (0)