@@ -622,6 +622,13 @@ pub enum Balance {
622622 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
623623 /// required to do so.
624624 amount_satoshis : u64 ,
625+ /// The transaction fee we pay for the closing commitment transaction. This amount is not
626+ /// included in the [`Balance::ClaimableOnChannelClose::amount_satoshis`] value.
627+ ///
628+ /// Note that if this channel is inbound (and thus our counterparty pays the commitment
629+ /// transaction fee) this value will be zero. For [`ChannelMonitor`]s created prior to LDK
630+ /// 0.0.124, the channel is always treated as outbound (and thus this value is never zero).
631+ transaction_fee_satoshis : u64 ,
625632 } ,
626633 /// The channel has been closed, and the given balance is ours but awaiting confirmations until
627634 /// we consider it spendable.
@@ -912,6 +919,10 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
912919 // of block connection between ChannelMonitors and the ChannelManager.
913920 funding_spend_seen : bool ,
914921
922+ /// True if the commitment transaction fee is paid by us.
923+ /// Added in 0.0.124.
924+ holder_pays_commitment_tx_fee : Option < bool > ,
925+
915926 /// Set to `Some` of the confirmed transaction spending the funding input of the channel after
916927 /// reaching `ANTI_REORG_DELAY` confirmations.
917928 funding_spend_confirmed : Option < Txid > ,
@@ -1160,6 +1171,7 @@ impl<Signer: EcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signer> {
11601171 ( 17 , self . initial_counterparty_commitment_info, option) ,
11611172 ( 19 , self . channel_id, required) ,
11621173 ( 21 , self . balances_empty_height, option) ,
1174+ ( 23 , self . holder_pays_commitment_tx_fee, option) ,
11631175 } ) ;
11641176
11651177 Ok ( ( ) )
@@ -1261,7 +1273,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
12611273
12621274 pub ( crate ) fn new ( secp_ctx : Secp256k1 < secp256k1:: All > , keys : Signer , shutdown_script : Option < ScriptBuf > ,
12631275 on_counterparty_tx_csv : u16 , destination_script : & Script , funding_info : ( OutPoint , ScriptBuf ) ,
1264- channel_parameters : & ChannelTransactionParameters ,
1276+ channel_parameters : & ChannelTransactionParameters , holder_pays_commitment_tx_fee : bool ,
12651277 funding_redeemscript : ScriptBuf , channel_value_satoshis : u64 ,
12661278 commitment_transaction_number_obscure_factor : u64 ,
12671279 initial_holder_commitment_tx : HolderCommitmentTransaction ,
@@ -1353,6 +1365,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
13531365
13541366 onchain_tx_handler,
13551367
1368+ holder_pays_commitment_tx_fee : Some ( holder_pays_commitment_tx_fee) ,
13561369 lockdown_from_offchain : false ,
13571370 holder_tx_signed : false ,
13581371 funding_spend_seen : false ,
@@ -2306,8 +2319,11 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23062319 }
23072320 } else {
23082321 let mut claimable_inbound_htlc_value_sat = 0 ;
2322+ let mut nondust_htlc_count = 0 ;
23092323 for ( htlc, _, source) in us. current_holder_commitment_tx . htlc_outputs . iter ( ) {
2310- if htlc. transaction_output_index . is_none ( ) { continue ; }
2324+ if htlc. transaction_output_index . is_some ( ) {
2325+ nondust_htlc_count += 1 ;
2326+ } else { continue ; }
23112327 if htlc. offered {
23122328 let outbound_payment = match source {
23132329 None => {
@@ -2337,6 +2353,11 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23372353 }
23382354 res. push ( Balance :: ClaimableOnChannelClose {
23392355 amount_satoshis : us. current_holder_commitment_tx . to_self_value_sat + claimable_inbound_htlc_value_sat,
2356+ transaction_fee_satoshis : if us. holder_pays_commitment_tx_fee . unwrap_or ( true ) {
2357+ chan_utils:: commit_tx_fee_sat (
2358+ us. current_holder_commitment_tx . feerate_per_kw , nondust_htlc_count,
2359+ us. onchain_tx_handler . channel_type_features ( ) )
2360+ } else { 0 } ,
23402361 } ) ;
23412362 }
23422363
@@ -4743,6 +4764,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
47434764 let mut initial_counterparty_commitment_info = None ;
47444765 let mut balances_empty_height = None ;
47454766 let mut channel_id = None ;
4767+ let mut holder_pays_commitment_tx_fee = None ;
47464768 read_tlv_fields ! ( reader, {
47474769 ( 1 , funding_spend_confirmed, option) ,
47484770 ( 3 , htlcs_resolved_on_chain, optional_vec) ,
@@ -4755,6 +4777,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
47554777 ( 17 , initial_counterparty_commitment_info, option) ,
47564778 ( 19 , channel_id, option) ,
47574779 ( 21 , balances_empty_height, option) ,
4780+ ( 23 , holder_pays_commitment_tx_fee, option) ,
47584781 } ) ;
47594782
47604783 // `HolderForceClosedWithInfo` replaced `HolderForceClosed` in v0.0.122. If we have both
@@ -4824,6 +4847,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
48244847
48254848 lockdown_from_offchain,
48264849 holder_tx_signed,
4850+ holder_pays_commitment_tx_fee,
48274851 funding_spend_seen : funding_spend_seen. unwrap ( ) ,
48284852 funding_spend_confirmed,
48294853 confirmed_commitment_tx_counterparty_output,
@@ -5063,7 +5087,7 @@ mod tests {
50635087 let monitor = ChannelMonitor :: new ( Secp256k1 :: new ( ) , keys,
50645088 Some ( ShutdownScript :: new_p2wpkh_from_pubkey ( shutdown_pubkey) . into_inner ( ) ) , 0 , & ScriptBuf :: new ( ) ,
50655089 ( OutPoint { txid : Txid :: from_slice ( & [ 43 ; 32 ] ) . unwrap ( ) , index : 0 } , ScriptBuf :: new ( ) ) ,
5066- & channel_parameters, ScriptBuf :: new ( ) , 46 , 0 , HolderCommitmentTransaction :: dummy ( & mut Vec :: new ( ) ) ,
5090+ & channel_parameters, true , ScriptBuf :: new ( ) , 46 , 0 , HolderCommitmentTransaction :: dummy ( & mut Vec :: new ( ) ) ,
50675091 best_block, dummy_key, channel_id) ;
50685092
50695093 let mut htlcs = preimages_slice_to_htlcs ! ( preimages[ 0 ..10 ] ) ;
@@ -5311,7 +5335,7 @@ mod tests {
53115335 let monitor = ChannelMonitor :: new ( Secp256k1 :: new ( ) , keys,
53125336 Some ( ShutdownScript :: new_p2wpkh_from_pubkey ( shutdown_pubkey) . into_inner ( ) ) , 0 , & ScriptBuf :: new ( ) ,
53135337 ( OutPoint { txid : Txid :: from_slice ( & [ 43 ; 32 ] ) . unwrap ( ) , index : 0 } , ScriptBuf :: new ( ) ) ,
5314- & channel_parameters, ScriptBuf :: new ( ) , 46 , 0 , HolderCommitmentTransaction :: dummy ( & mut Vec :: new ( ) ) ,
5338+ & channel_parameters, true , ScriptBuf :: new ( ) , 46 , 0 , HolderCommitmentTransaction :: dummy ( & mut Vec :: new ( ) ) ,
53155339 best_block, dummy_key, channel_id) ;
53165340
53175341 let chan_id = monitor. inner . lock ( ) . unwrap ( ) . channel_id ( ) ;
0 commit comments