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