55// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
66// accordance with one or both of these licenses.
77
8- use crate :: sweep:: value_satoshis_from_descriptor ;
8+ use crate :: sweep:: value_from_descriptor ;
99
1010use lightning:: chain:: channelmonitor:: Balance as LdkBalance ;
11- use lightning:: ln:: { ChannelId , PaymentHash , PaymentPreimage } ;
11+ use lightning:: chain:: channelmonitor:: BalanceSource ;
12+ use lightning:: ln:: types:: ChannelId ;
13+ use lightning:: ln:: { PaymentHash , PaymentPreimage } ;
1214use lightning:: util:: sweep:: { OutputSpendStatus , TrackedSpendableOutput } ;
1315
1416use bitcoin:: secp256k1:: PublicKey ;
@@ -80,6 +82,49 @@ pub enum LightningBalance {
8082 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
8183 /// required to do so.
8284 amount_satoshis : u64 ,
85+ /// The transaction fee we pay for the closing commitment transaction. This amount is not
86+ /// included in the `amount_satoshis` value.
87+ ///
88+ /// Note that if this channel is inbound (and thus our counterparty pays the commitment
89+ /// transaction fee) this value will be zero. For channels created prior to LDK Node 0.4
90+ /// the channel is always treated as outbound (and thus this value is never zero).
91+ transaction_fee_satoshis : u64 ,
92+ /// The amount of millisatoshis which has been burned to fees from HTLCs which are outbound
93+ /// from us and are related to a payment which was sent by us. This is the sum of the
94+ /// millisatoshis part of all HTLCs which are otherwise represented by
95+ /// [`LightningBalance::MaybeTimeoutClaimableHTLC`] with their
96+ /// [`LightningBalance::MaybeTimeoutClaimableHTLC::outbound_payment`] flag set, as well as
97+ /// any dust HTLCs which would otherwise be represented the same.
98+ ///
99+ /// This amount (rounded up to a whole satoshi value) will not be included in `amount_satoshis`.
100+ outbound_payment_htlc_rounded_msat : u64 ,
101+ /// The amount of millisatoshis which has been burned to fees from HTLCs which are outbound
102+ /// from us and are related to a forwarded HTLC. This is the sum of the millisatoshis part
103+ /// of all HTLCs which are otherwise represented by
104+ /// [`LightningBalance::MaybeTimeoutClaimableHTLC`] with their
105+ /// [`LightningBalance::MaybeTimeoutClaimableHTLC::outbound_payment`] flag *not* set, as
106+ /// well as any dust HTLCs which would otherwise be represented the same.
107+ ///
108+ /// This amount (rounded up to a whole satoshi value) will not be included in `amount_satoshis`.
109+ outbound_forwarded_htlc_rounded_msat : u64 ,
110+ /// The amount of millisatoshis which has been burned to fees from HTLCs which are inbound
111+ /// to us and for which we know the preimage. This is the sum of the millisatoshis part of
112+ /// all HTLCs which would be represented by [`LightningBalance::ContentiousClaimable`] on
113+ /// channel close, but whose current value is included in `amount_satoshis`, as well as any
114+ /// dust HTLCs which would otherwise be represented the same.
115+ ///
116+ /// This amount (rounded up to a whole satoshi value) will not be included in the counterparty's
117+ /// `amount_satoshis`.
118+ inbound_claiming_htlc_rounded_msat : u64 ,
119+ /// The amount of millisatoshis which has been burned to fees from HTLCs which are inbound
120+ /// to us and for which we do not know the preimage. This is the sum of the millisatoshis
121+ /// part of all HTLCs which would be represented by
122+ /// [`LightningBalance::MaybePreimageClaimableHTLC`] on channel close, as well as any dust
123+ /// HTLCs which would otherwise be represented the same.
124+ ///
125+ /// This amount (rounded up to a whole satoshi value) will not be included in the
126+ /// counterparty's `amount_satoshis`.
127+ inbound_htlc_rounded_msat : u64 ,
83128 } ,
84129 /// The channel has been closed, and the given balance is ours but awaiting confirmations until
85130 /// we consider it spendable.
@@ -96,6 +141,8 @@ pub enum LightningBalance {
96141 ///
97142 /// [`Event::SpendableOutputs`]: lightning::events::Event::SpendableOutputs
98143 confirmation_height : u32 ,
144+ /// Whether this balance is a result of cooperative close, a force-close, or an HTLC.
145+ source : BalanceSource ,
99146 } ,
100147 /// The channel has been closed, and the given balance should be ours but awaiting spending
101148 /// transaction confirmation. If the spending transaction does not confirm in time, it is
@@ -136,6 +183,8 @@ pub enum LightningBalance {
136183 claimable_height : u32 ,
137184 /// The payment hash whose preimage our counterparty needs to claim this HTLC.
138185 payment_hash : PaymentHash ,
186+ /// Indicates whether this HTLC represents a payment which was sent outbound from us.
187+ outbound_payment : bool ,
139188 } ,
140189 /// HTLCs which we received from our counterparty which are claimable with a preimage which we
141190 /// do not currently have. This will only be claimable if we receive the preimage from the node
@@ -174,16 +223,33 @@ impl LightningBalance {
174223 channel_id : ChannelId , counterparty_node_id : PublicKey , balance : LdkBalance ,
175224 ) -> Self {
176225 match balance {
177- LdkBalance :: ClaimableOnChannelClose { amount_satoshis } => {
178- Self :: ClaimableOnChannelClose { channel_id, counterparty_node_id, amount_satoshis }
226+ LdkBalance :: ClaimableOnChannelClose {
227+ amount_satoshis,
228+ transaction_fee_satoshis,
229+ outbound_payment_htlc_rounded_msat,
230+ outbound_forwarded_htlc_rounded_msat,
231+ inbound_claiming_htlc_rounded_msat,
232+ inbound_htlc_rounded_msat,
233+ } => Self :: ClaimableOnChannelClose {
234+ channel_id,
235+ counterparty_node_id,
236+ amount_satoshis,
237+ transaction_fee_satoshis,
238+ outbound_payment_htlc_rounded_msat,
239+ outbound_forwarded_htlc_rounded_msat,
240+ inbound_claiming_htlc_rounded_msat,
241+ inbound_htlc_rounded_msat,
179242 } ,
180- LdkBalance :: ClaimableAwaitingConfirmations { amount_satoshis, confirmation_height } => {
181- Self :: ClaimableAwaitingConfirmations {
182- channel_id,
183- counterparty_node_id,
184- amount_satoshis,
185- confirmation_height,
186- }
243+ LdkBalance :: ClaimableAwaitingConfirmations {
244+ amount_satoshis,
245+ confirmation_height,
246+ source,
247+ } => Self :: ClaimableAwaitingConfirmations {
248+ channel_id,
249+ counterparty_node_id,
250+ amount_satoshis,
251+ confirmation_height,
252+ source,
187253 } ,
188254 LdkBalance :: ContentiousClaimable {
189255 amount_satoshis,
@@ -202,12 +268,14 @@ impl LightningBalance {
202268 amount_satoshis,
203269 claimable_height,
204270 payment_hash,
271+ outbound_payment,
205272 } => Self :: MaybeTimeoutClaimableHTLC {
206273 channel_id,
207274 counterparty_node_id,
208275 amount_satoshis,
209276 claimable_height,
210277 payment_hash,
278+ outbound_payment,
211279 } ,
212280 LdkBalance :: MaybePreimageClaimableHTLC {
213281 amount_satoshis,
@@ -278,7 +346,7 @@ impl PendingSweepBalance {
278346 match output_info. status {
279347 OutputSpendStatus :: PendingInitialBroadcast { .. } => {
280348 let channel_id = output_info. channel_id ;
281- let amount_satoshis = value_satoshis_from_descriptor ( & output_info. descriptor ) ;
349+ let amount_satoshis = value_from_descriptor ( & output_info. descriptor ) . to_sat ( ) ;
282350 Self :: PendingBroadcast { channel_id, amount_satoshis }
283351 } ,
284352 OutputSpendStatus :: PendingFirstConfirmation {
@@ -287,8 +355,8 @@ impl PendingSweepBalance {
287355 ..
288356 } => {
289357 let channel_id = output_info. channel_id ;
290- let amount_satoshis = value_satoshis_from_descriptor ( & output_info. descriptor ) ;
291- let latest_spending_txid = latest_spending_tx. txid ( ) ;
358+ let amount_satoshis = value_from_descriptor ( & output_info. descriptor ) . to_sat ( ) ;
359+ let latest_spending_txid = latest_spending_tx. compute_txid ( ) ;
292360 Self :: BroadcastAwaitingConfirmation {
293361 channel_id,
294362 latest_broadcast_height,
@@ -303,8 +371,8 @@ impl PendingSweepBalance {
303371 ..
304372 } => {
305373 let channel_id = output_info. channel_id ;
306- let amount_satoshis = value_satoshis_from_descriptor ( & output_info. descriptor ) ;
307- let latest_spending_txid = latest_spending_tx. txid ( ) ;
374+ let amount_satoshis = value_from_descriptor ( & output_info. descriptor ) . to_sat ( ) ;
375+ let latest_spending_txid = latest_spending_tx. compute_txid ( ) ;
308376 Self :: AwaitingThresholdConfirmations {
309377 channel_id,
310378 latest_spending_txid,
0 commit comments