@@ -608,6 +608,19 @@ impl_writeable_tlv_based_enum_upgradable!(ChannelMonitorUpdateStep,
608
608
} ,
609
609
) ;
610
610
611
+ /// Indicates whether the balance is derived from a cooperative close, a force-close
612
+ /// (for holder or counterparty), or whether it is for an HTLC.
613
+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
614
+ #[ cfg_attr( test, derive( PartialOrd , Ord ) ) ]
615
+ pub enum BalanceSource {
616
+ /// The channel was force closed.
617
+ ForceClosed ,
618
+ /// The channel was cooperatively closed.
619
+ CoopClose ,
620
+ /// This balance is the result of an HTLC.
621
+ Htlc ,
622
+ }
623
+
611
624
/// Details about the balance(s) available for spending once the channel appears on chain.
612
625
///
613
626
/// See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
@@ -677,6 +690,8 @@ pub enum Balance {
677
690
/// The height at which an [`Event::SpendableOutputs`] event will be generated for this
678
691
/// amount.
679
692
confirmation_height : u32 ,
693
+ /// Whether this balance is a result of cooperative close, a force-close, or an HTLC.
694
+ source : BalanceSource ,
680
695
} ,
681
696
/// The channel has been closed, and the given balance should be ours but awaiting spending
682
697
/// transaction confirmation. If the spending transaction does not confirm in time, it is
@@ -2106,6 +2121,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2106
2121
return Some ( Balance :: ClaimableAwaitingConfirmations {
2107
2122
amount_satoshis : htlc. amount_msat / 1000 ,
2108
2123
confirmation_height : conf_thresh,
2124
+ source : BalanceSource :: Htlc ,
2109
2125
} ) ;
2110
2126
} else if htlc_resolved. is_some ( ) && !htlc_output_spend_pending {
2111
2127
// Funding transaction spends should be fully confirmed by the time any
@@ -2153,6 +2169,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2153
2169
return Some ( Balance :: ClaimableAwaitingConfirmations {
2154
2170
amount_satoshis : htlc. amount_msat / 1000 ,
2155
2171
confirmation_height : conf_thresh,
2172
+ source : BalanceSource :: Htlc ,
2156
2173
} ) ;
2157
2174
} else {
2158
2175
let outbound_payment = match source {
@@ -2181,6 +2198,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2181
2198
return Some ( Balance :: ClaimableAwaitingConfirmations {
2182
2199
amount_satoshis : htlc. amount_msat / 1000 ,
2183
2200
confirmation_height : conf_thresh,
2201
+ source : BalanceSource :: Htlc ,
2184
2202
} ) ;
2185
2203
} else {
2186
2204
return Some ( Balance :: ContentiousClaimable {
@@ -2268,6 +2286,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2268
2286
res. push ( Balance :: ClaimableAwaitingConfirmations {
2269
2287
amount_satoshis : value. to_sat ( ) ,
2270
2288
confirmation_height : conf_thresh,
2289
+ source : BalanceSource :: ForceClosed ,
2271
2290
} ) ;
2272
2291
} else {
2273
2292
// If a counterparty commitment transaction is awaiting confirmation, we
@@ -2291,6 +2310,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2291
2310
res. push ( Balance :: ClaimableAwaitingConfirmations {
2292
2311
amount_satoshis : output. value . to_sat ( ) ,
2293
2312
confirmation_height : event. confirmation_threshold ( ) ,
2313
+ source : BalanceSource :: ForceClosed ,
2294
2314
} ) ;
2295
2315
if let Some ( confirmed_to_self_idx) = confirmed_counterparty_output. map ( |( idx, _) | idx) {
2296
2316
if event. transaction . as_ref ( ) . map ( |tx|
@@ -2323,6 +2343,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2323
2343
res. push ( Balance :: ClaimableAwaitingConfirmations {
2324
2344
amount_satoshis : us. current_holder_commitment_tx . to_self_value_sat ,
2325
2345
confirmation_height : conf_thresh,
2346
+ source : BalanceSource :: ForceClosed ,
2326
2347
} ) ;
2327
2348
}
2328
2349
found_commitment_tx = true ;
@@ -2333,6 +2354,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2333
2354
res. push ( Balance :: ClaimableAwaitingConfirmations {
2334
2355
amount_satoshis : prev_commitment. to_self_value_sat ,
2335
2356
confirmation_height : conf_thresh,
2357
+ source : BalanceSource :: ForceClosed ,
2336
2358
} ) ;
2337
2359
}
2338
2360
found_commitment_tx = true ;
@@ -2346,6 +2368,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2346
2368
res. push ( Balance :: ClaimableAwaitingConfirmations {
2347
2369
amount_satoshis : us. current_holder_commitment_tx . to_self_value_sat ,
2348
2370
confirmation_height : conf_thresh,
2371
+ source : BalanceSource :: CoopClose ,
2349
2372
} ) ;
2350
2373
}
2351
2374
}
0 commit comments