@@ -608,6 +608,19 @@ 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.
617+ ForceClosed ,
618+ /// The channel was cooperatively closed.
619+ CoopClose ,
620+ /// This balance is the result of an HTLC.
621+ Htlc ,
622+ }
623+
611624/// Details about the balance(s) available for spending once the channel appears on chain.
612625///
613626/// See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
@@ -677,6 +690,8 @@ pub enum Balance {
677690 /// The height at which an [`Event::SpendableOutputs`] event will be generated for this
678691 /// amount.
679692 confirmation_height : u32 ,
693+ /// Whether this balance is a result of cooperative close, a force-close, or an HTLC.
694+ source : BalanceSource ,
680695 } ,
681696 /// The channel has been closed, and the given balance should be ours but awaiting spending
682697 /// transaction confirmation. If the spending transaction does not confirm in time, it is
@@ -2106,6 +2121,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
21062121 return Some ( Balance :: ClaimableAwaitingConfirmations {
21072122 amount_satoshis : htlc. amount_msat / 1000 ,
21082123 confirmation_height : conf_thresh,
2124+ source : BalanceSource :: Htlc ,
21092125 } ) ;
21102126 } else if htlc_resolved. is_some ( ) && !htlc_output_spend_pending {
21112127 // Funding transaction spends should be fully confirmed by the time any
@@ -2153,6 +2169,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
21532169 return Some ( Balance :: ClaimableAwaitingConfirmations {
21542170 amount_satoshis : htlc. amount_msat / 1000 ,
21552171 confirmation_height : conf_thresh,
2172+ source : BalanceSource :: Htlc ,
21562173 } ) ;
21572174 } else {
21582175 let outbound_payment = match source {
@@ -2181,6 +2198,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
21812198 return Some ( Balance :: ClaimableAwaitingConfirmations {
21822199 amount_satoshis : htlc. amount_msat / 1000 ,
21832200 confirmation_height : conf_thresh,
2201+ source : BalanceSource :: Htlc ,
21842202 } ) ;
21852203 } else {
21862204 return Some ( Balance :: ContentiousClaimable {
@@ -2268,6 +2286,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
22682286 res. push ( Balance :: ClaimableAwaitingConfirmations {
22692287 amount_satoshis : value. to_sat ( ) ,
22702288 confirmation_height : conf_thresh,
2289+ source : BalanceSource :: ForceClosed ,
22712290 } ) ;
22722291 } else {
22732292 // If a counterparty commitment transaction is awaiting confirmation, we
@@ -2291,6 +2310,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
22912310 res. push ( Balance :: ClaimableAwaitingConfirmations {
22922311 amount_satoshis : output. value . to_sat ( ) ,
22932312 confirmation_height : event. confirmation_threshold ( ) ,
2313+ source : BalanceSource :: ForceClosed ,
22942314 } ) ;
22952315 if let Some ( confirmed_to_self_idx) = confirmed_counterparty_output. map ( |( idx, _) | idx) {
22962316 if event. transaction . as_ref ( ) . map ( |tx|
@@ -2323,6 +2343,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23232343 res. push ( Balance :: ClaimableAwaitingConfirmations {
23242344 amount_satoshis : us. current_holder_commitment_tx . to_self_value_sat ,
23252345 confirmation_height : conf_thresh,
2346+ source : BalanceSource :: ForceClosed ,
23262347 } ) ;
23272348 }
23282349 found_commitment_tx = true ;
@@ -2333,6 +2354,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23332354 res. push ( Balance :: ClaimableAwaitingConfirmations {
23342355 amount_satoshis : prev_commitment. to_self_value_sat ,
23352356 confirmation_height : conf_thresh,
2357+ source : BalanceSource :: ForceClosed ,
23362358 } ) ;
23372359 }
23382360 found_commitment_tx = true ;
@@ -2346,6 +2368,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23462368 res. push ( Balance :: ClaimableAwaitingConfirmations {
23472369 amount_satoshis : us. current_holder_commitment_tx . to_self_value_sat ,
23482370 confirmation_height : conf_thresh,
2371+ source : BalanceSource :: CoopClose ,
23492372 } ) ;
23502373 }
23512374 }
0 commit comments