@@ -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
@@ -2110,6 +2127,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2110
2127
return Some ( Balance :: ClaimableAwaitingConfirmations {
2111
2128
amount_satoshis : htlc. amount_msat / 1000 ,
2112
2129
confirmation_height : conf_thresh,
2130
+ source : BalanceSource :: Htlc ,
2113
2131
} ) ;
2114
2132
} else if htlc_resolved. is_some ( ) && !htlc_output_spend_pending {
2115
2133
// Funding transaction spends should be fully confirmed by the time any
@@ -2157,6 +2175,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2157
2175
return Some ( Balance :: ClaimableAwaitingConfirmations {
2158
2176
amount_satoshis : htlc. amount_msat / 1000 ,
2159
2177
confirmation_height : conf_thresh,
2178
+ source : BalanceSource :: Htlc ,
2160
2179
} ) ;
2161
2180
} else {
2162
2181
let outbound_payment = match source {
@@ -2185,6 +2204,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2185
2204
return Some ( Balance :: ClaimableAwaitingConfirmations {
2186
2205
amount_satoshis : htlc. amount_msat / 1000 ,
2187
2206
confirmation_height : conf_thresh,
2207
+ source : BalanceSource :: Htlc ,
2188
2208
} ) ;
2189
2209
} else {
2190
2210
return Some ( Balance :: ContentiousClaimable {
@@ -2272,6 +2292,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2272
2292
res. push ( Balance :: ClaimableAwaitingConfirmations {
2273
2293
amount_satoshis : value. to_sat ( ) ,
2274
2294
confirmation_height : conf_thresh,
2295
+ source : BalanceSource :: CounterpartyForceClosed ,
2275
2296
} ) ;
2276
2297
} else {
2277
2298
// If a counterparty commitment transaction is awaiting confirmation, we
@@ -2295,6 +2316,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2295
2316
res. push ( Balance :: ClaimableAwaitingConfirmations {
2296
2317
amount_satoshis : output. value . to_sat ( ) ,
2297
2318
confirmation_height : event. confirmation_threshold ( ) ,
2319
+ source : BalanceSource :: CounterpartyForceClosed ,
2298
2320
} ) ;
2299
2321
if let Some ( confirmed_to_self_idx) = confirmed_counterparty_output. map ( |( idx, _) | idx) {
2300
2322
if event. transaction . as_ref ( ) . map ( |tx|
@@ -2327,6 +2349,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2327
2349
res. push ( Balance :: ClaimableAwaitingConfirmations {
2328
2350
amount_satoshis : us. current_holder_commitment_tx . to_self_value_sat ,
2329
2351
confirmation_height : conf_thresh,
2352
+ source : BalanceSource :: HolderForceClosed ,
2330
2353
} ) ;
2331
2354
}
2332
2355
found_commitment_tx = true ;
@@ -2337,6 +2360,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2337
2360
res. push ( Balance :: ClaimableAwaitingConfirmations {
2338
2361
amount_satoshis : prev_commitment. to_self_value_sat ,
2339
2362
confirmation_height : conf_thresh,
2363
+ source : BalanceSource :: HolderForceClosed ,
2340
2364
} ) ;
2341
2365
}
2342
2366
found_commitment_tx = true ;
@@ -2350,6 +2374,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2350
2374
res. push ( Balance :: ClaimableAwaitingConfirmations {
2351
2375
amount_satoshis : us. current_holder_commitment_tx . to_self_value_sat ,
2352
2376
confirmation_height : conf_thresh,
2377
+ source : BalanceSource :: CoopClose ,
2353
2378
} ) ;
2354
2379
}
2355
2380
}
0 commit comments