@@ -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
@@ -673,6 +686,8 @@ pub enum Balance {
673
686
/// The height at which an [`Event::SpendableOutputs`] event will be generated for this
674
687
/// amount.
675
688
confirmation_height : u32 ,
689
+ /// Whether this balance is a result of cooperative close, a force-close, or an HTLC.
690
+ source : BalanceSource ,
676
691
} ,
677
692
/// The channel has been closed, and the given balance should be ours but awaiting spending
678
693
/// transaction confirmation. If the spending transaction does not confirm in time, it is
@@ -2102,6 +2117,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2102
2117
return Some ( Balance :: ClaimableAwaitingConfirmations {
2103
2118
amount_satoshis : htlc. amount_msat / 1000 ,
2104
2119
confirmation_height : conf_thresh,
2120
+ source : BalanceSource :: Htlc ,
2105
2121
} ) ;
2106
2122
} else if htlc_resolved. is_some ( ) && !htlc_output_spend_pending {
2107
2123
// Funding transaction spends should be fully confirmed by the time any
@@ -2149,6 +2165,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2149
2165
return Some ( Balance :: ClaimableAwaitingConfirmations {
2150
2166
amount_satoshis : htlc. amount_msat / 1000 ,
2151
2167
confirmation_height : conf_thresh,
2168
+ source : BalanceSource :: Htlc ,
2152
2169
} ) ;
2153
2170
} else {
2154
2171
let outbound_payment = match source {
@@ -2177,6 +2194,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2177
2194
return Some ( Balance :: ClaimableAwaitingConfirmations {
2178
2195
amount_satoshis : htlc. amount_msat / 1000 ,
2179
2196
confirmation_height : conf_thresh,
2197
+ source : BalanceSource :: Htlc ,
2180
2198
} ) ;
2181
2199
} else {
2182
2200
return Some ( Balance :: ContentiousClaimable {
@@ -2264,6 +2282,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2264
2282
res. push ( Balance :: ClaimableAwaitingConfirmations {
2265
2283
amount_satoshis : value. to_sat ( ) ,
2266
2284
confirmation_height : conf_thresh,
2285
+ source : BalanceSource :: ForceClosed ,
2267
2286
} ) ;
2268
2287
} else {
2269
2288
// If a counterparty commitment transaction is awaiting confirmation, we
@@ -2287,6 +2306,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2287
2306
res. push ( Balance :: ClaimableAwaitingConfirmations {
2288
2307
amount_satoshis : output. value . to_sat ( ) ,
2289
2308
confirmation_height : event. confirmation_threshold ( ) ,
2309
+ source : BalanceSource :: ForceClosed ,
2290
2310
} ) ;
2291
2311
if let Some ( confirmed_to_self_idx) = confirmed_counterparty_output. map ( |( idx, _) | idx) {
2292
2312
if event. transaction . as_ref ( ) . map ( |tx|
@@ -2319,6 +2339,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2319
2339
res. push ( Balance :: ClaimableAwaitingConfirmations {
2320
2340
amount_satoshis : us. current_holder_commitment_tx . to_self_value_sat ,
2321
2341
confirmation_height : conf_thresh,
2342
+ source : BalanceSource :: ForceClosed ,
2322
2343
} ) ;
2323
2344
}
2324
2345
found_commitment_tx = true ;
@@ -2329,6 +2350,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2329
2350
res. push ( Balance :: ClaimableAwaitingConfirmations {
2330
2351
amount_satoshis : prev_commitment. to_self_value_sat ,
2331
2352
confirmation_height : conf_thresh,
2353
+ source : BalanceSource :: ForceClosed ,
2332
2354
} ) ;
2333
2355
}
2334
2356
found_commitment_tx = true ;
@@ -2342,6 +2364,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2342
2364
res. push ( Balance :: ClaimableAwaitingConfirmations {
2343
2365
amount_satoshis : us. current_holder_commitment_tx . to_self_value_sat ,
2344
2366
confirmation_height : conf_thresh,
2367
+ source : BalanceSource :: CoopClose ,
2345
2368
} ) ;
2346
2369
}
2347
2370
}
0 commit comments