@@ -608,6 +608,21 @@ impl_writeable_tlv_based_enum_upgradable!(ChannelMonitorUpdateStep,
608608 } ,
609609) ;
610610
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+
611626/// Details about the balance(s) available for spending once the channel appears on chain.
612627///
613628/// See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
@@ -675,6 +690,8 @@ pub enum Balance {
675690 /// The height at which an [`Event::SpendableOutputs`] event will be generated for this
676691 /// amount.
677692 confirmation_height : u32 ,
693+ /// Whether this balance is a result of cooperative close, a force-close, or an HTLC.
694+ source : BalanceSource ,
678695 } ,
679696 /// The channel has been closed, and the given balance should be ours but awaiting spending
680697 /// transaction confirmation. If the spending transaction does not confirm in time, it is
@@ -2104,6 +2121,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
21042121 return Some ( Balance :: ClaimableAwaitingConfirmations {
21052122 amount_satoshis : htlc. amount_msat / 1000 ,
21062123 confirmation_height : conf_thresh,
2124+ source : BalanceSource :: Htlc ,
21072125 } ) ;
21082126 } else if htlc_resolved. is_some ( ) && !htlc_output_spend_pending {
21092127 // Funding transaction spends should be fully confirmed by the time any
@@ -2151,6 +2169,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
21512169 return Some ( Balance :: ClaimableAwaitingConfirmations {
21522170 amount_satoshis : htlc. amount_msat / 1000 ,
21532171 confirmation_height : conf_thresh,
2172+ source : BalanceSource :: Htlc ,
21542173 } ) ;
21552174 } else {
21562175 let outbound_payment = match source {
@@ -2179,6 +2198,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
21792198 return Some ( Balance :: ClaimableAwaitingConfirmations {
21802199 amount_satoshis : htlc. amount_msat / 1000 ,
21812200 confirmation_height : conf_thresh,
2201+ source : BalanceSource :: Htlc ,
21822202 } ) ;
21832203 } else {
21842204 return Some ( Balance :: ContentiousClaimable {
@@ -2266,6 +2286,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
22662286 res. push ( Balance :: ClaimableAwaitingConfirmations {
22672287 amount_satoshis : value. to_sat ( ) ,
22682288 confirmation_height : conf_thresh,
2289+ source : BalanceSource :: CounterpartyForceClosed ,
22692290 } ) ;
22702291 } else {
22712292 // If a counterparty commitment transaction is awaiting confirmation, we
@@ -2289,6 +2310,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
22892310 res. push ( Balance :: ClaimableAwaitingConfirmations {
22902311 amount_satoshis : output. value . to_sat ( ) ,
22912312 confirmation_height : event. confirmation_threshold ( ) ,
2313+ source : BalanceSource :: CounterpartyForceClosed ,
22922314 } ) ;
22932315 if let Some ( confirmed_to_self_idx) = confirmed_counterparty_output. map ( |( idx, _) | idx) {
22942316 if event. transaction . as_ref ( ) . map ( |tx|
@@ -2321,6 +2343,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23212343 res. push ( Balance :: ClaimableAwaitingConfirmations {
23222344 amount_satoshis : us. current_holder_commitment_tx . to_self_value_sat ,
23232345 confirmation_height : conf_thresh,
2346+ source : BalanceSource :: HolderForceClosed ,
23242347 } ) ;
23252348 }
23262349 found_commitment_tx = true ;
@@ -2331,6 +2354,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23312354 res. push ( Balance :: ClaimableAwaitingConfirmations {
23322355 amount_satoshis : prev_commitment. to_self_value_sat ,
23332356 confirmation_height : conf_thresh,
2357+ source : BalanceSource :: CounterpartyForceClosed ,
23342358 } ) ;
23352359 }
23362360 found_commitment_tx = true ;
@@ -2344,6 +2368,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23442368 res. push ( Balance :: ClaimableAwaitingConfirmations {
23452369 amount_satoshis : us. current_holder_commitment_tx . to_self_value_sat ,
23462370 confirmation_height : conf_thresh,
2371+ source : BalanceSource :: CoopClose ,
23472372 } ) ;
23482373 }
23492374 }
0 commit comments