Skip to content

Commit

Permalink
wip stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Nov 14, 2023
1 parent 09e6cf3 commit 3bc8048
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,25 +591,33 @@ pub enum Balance {
/// [`Balance::MaybeTimeoutClaimableHTLC`] with their
/// [`Balance::MaybeTimeoutClaimableHTLC::outbound_payment`] flag set, as well as any dust
/// HTLCs which would otherwise be represented the same.
///
/// XXX: Talk about how this is included in the overall balance
outbound_payment_htlc_rounded_msat: u64,
/// The amount of millisatoshis which has been burned to fees from HTLCs which are outbound
/// from us and are related to a forwarded HTLC. This is the sum of the millisatoshis part
/// of all HTLCs which are otherwise represented by [`Balance::MaybeTimeoutClaimableHTLC`]
/// with their [`Balance::MaybeTimeoutClaimableHTLC::outbound_payment`] flag *not* set, as
/// well as any dust HTLCs which would otherwise be represented the same.
///
/// XXX: Talk about how this is included in the overall balance
outbound_forwarded_htlc_rounded_msat: u64,
/// The amount of millisatoshis which has been burned to fees from HTLCs which are inbound
/// to us and for which we know the preimage. This is the sum of the millisatoshis part of
/// all HTLCs which would be represented by [`Balance::ContentiousClaimable`] on channel
/// close, but who's current value is included in
/// [`Balance::ClaimableOnChannelClose::amount_satoshis`], as well as any dust HTLCs which
/// would otherwise be represented the same.
///
/// XXX: Talk about how this is included in the overall balance
inbound_claiming_htlc_rounded_msat: u64,
/// The amount of millisatoshis which has been burned to fees from HTLCs which are inbound
/// to us and for which we do not know the preimage. This is the sum of the millisatoshis
/// part of all HTLCs which would be represented by [`Balance::MaybePreimageClaimableHTLC`]
/// on channel close, as well as any dust HTLCs which would otherwise be represented the
/// same.
///
/// XXX: Talk about how this is included in the overall balance
inbound_htlc_rounded_msat: u64,
},
/// The channel has been closed, and the given balance is ours but awaiting confirmations until
Expand Down Expand Up @@ -2097,7 +2105,11 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
}
}
} else {
let mut expected_tx_value_sats = if us.holder_pays_commitment_tx_fee.unwrap_or(true) {
us.channel_value_satoshis
} else { 0 };
let mut claimable_inbound_htlc_value_sat = 0;
let mut claimable_inbound_htlc_value_msat = 0;
let mut nondust_htlc_count = 0;
let mut outbound_payment_htlc_rounded_msat = 0;
let mut outbound_forwarded_htlc_rounded_msat = 0;
Expand All @@ -2124,6 +2136,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
} else {
outbound_forwarded_htlc_rounded_msat += rounded_value_msat;
}
expectex_tx_value_sats -= (htlc.amount_msat + 999) / 1000;
if htlc.transaction_output_index.is_some() {
res.push(Balance::MaybeTimeoutClaimableHTLC {
amount_satoshis: htlc.amount_msat / 1000,
Expand All @@ -2150,12 +2163,15 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
}
}
}
let tx_fee_satoshis = chan_utils::commit_tx_fee_sat(
us.current_holder_commitment_tx.feerate_per_kw, nondust_htlc_count,
us.onchain_tx_handler.channel_type_features());
//XXX: Debug assert that we're able to rebuild the amount_satoshis amount from other
//information we provide here (and provide such other information)
res.push(Balance::ClaimableOnChannelClose {
amount_satoshis: us.current_holder_commitment_tx.to_self_value_sat + claimable_inbound_htlc_value_sat,
transaction_fee_satoshis: if us.holder_pays_commitment_tx_fee.unwrap_or(true) {
chan_utils::commit_tx_fee_sat(
us.current_holder_commitment_tx.feerate_per_kw, nondust_htlc_count,
us.onchain_tx_handler.channel_type_features())
tx_fee_satoshis
} else { 0 },
outbound_payment_htlc_rounded_msat,
outbound_forwarded_htlc_rounded_msat,
Expand Down

0 comments on commit 3bc8048

Please sign in to comment.