@@ -622,6 +622,13 @@ pub enum Balance {
622
622
/// The amount available to claim, in satoshis, excluding the on-chain fees which will be
623
623
/// required to do so.
624
624
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 ,
625
632
} ,
626
633
/// The channel has been closed, and the given balance is ours but awaiting confirmations until
627
634
/// we consider it spendable.
@@ -906,6 +913,10 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
906
913
// of block connection between ChannelMonitors and the ChannelManager.
907
914
funding_spend_seen : bool ,
908
915
916
+ /// True if the commitment transaction fee is paid by us.
917
+ /// Added in 0.0.124.
918
+ holder_pays_commitment_tx_fee : Option < bool > ,
919
+
909
920
/// Set to `Some` of the confirmed transaction spending the funding input of the channel after
910
921
/// reaching `ANTI_REORG_DELAY` confirmations.
911
922
funding_spend_confirmed : Option < Txid > ,
@@ -1154,6 +1165,7 @@ impl<Signer: EcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signer> {
1154
1165
( 17 , self . initial_counterparty_commitment_info, option) ,
1155
1166
( 19 , self . channel_id, required) ,
1156
1167
( 21 , self . balances_empty_height, option) ,
1168
+ ( 23 , self . holder_pays_commitment_tx_fee, option) ,
1157
1169
} ) ;
1158
1170
1159
1171
Ok ( ( ) )
@@ -1255,7 +1267,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1255
1267
1256
1268
pub ( crate ) fn new ( secp_ctx : Secp256k1 < secp256k1:: All > , keys : Signer , shutdown_script : Option < ScriptBuf > ,
1257
1269
on_counterparty_tx_csv : u16 , destination_script : & Script , funding_info : ( OutPoint , ScriptBuf ) ,
1258
- channel_parameters : & ChannelTransactionParameters ,
1270
+ channel_parameters : & ChannelTransactionParameters , holder_pays_commitment_tx_fee : bool ,
1259
1271
funding_redeemscript : ScriptBuf , channel_value_satoshis : u64 ,
1260
1272
commitment_transaction_number_obscure_factor : u64 ,
1261
1273
initial_holder_commitment_tx : HolderCommitmentTransaction ,
@@ -1347,6 +1359,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1347
1359
1348
1360
onchain_tx_handler,
1349
1361
1362
+ holder_pays_commitment_tx_fee : Some ( holder_pays_commitment_tx_fee) ,
1350
1363
lockdown_from_offchain : false ,
1351
1364
holder_tx_signed : false ,
1352
1365
funding_spend_seen : false ,
@@ -2300,8 +2313,11 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2300
2313
}
2301
2314
} else {
2302
2315
let mut claimable_inbound_htlc_value_sat = 0 ;
2316
+ let mut nondust_htlc_count = 0 ;
2303
2317
for ( htlc, _, source) in us. current_holder_commitment_tx . htlc_outputs . iter ( ) {
2304
- if htlc. transaction_output_index . is_none ( ) { continue ; }
2318
+ if htlc. transaction_output_index . is_some ( ) {
2319
+ nondust_htlc_count += 1 ;
2320
+ } else { continue ; }
2305
2321
if htlc. offered {
2306
2322
let outbound_payment = match source {
2307
2323
None => {
@@ -2331,6 +2347,11 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2331
2347
}
2332
2348
res. push ( Balance :: ClaimableOnChannelClose {
2333
2349
amount_satoshis : us. current_holder_commitment_tx . to_self_value_sat + claimable_inbound_htlc_value_sat,
2350
+ transaction_fee_satoshis : if us. holder_pays_commitment_tx_fee . unwrap_or ( true ) {
2351
+ chan_utils:: commit_tx_fee_sat (
2352
+ us. current_holder_commitment_tx . feerate_per_kw , nondust_htlc_count,
2353
+ us. onchain_tx_handler . channel_type_features ( ) )
2354
+ } else { 0 } ,
2334
2355
} ) ;
2335
2356
}
2336
2357
@@ -4737,6 +4758,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
4737
4758
let mut initial_counterparty_commitment_info = None ;
4738
4759
let mut balances_empty_height = None ;
4739
4760
let mut channel_id = None ;
4761
+ let mut holder_pays_commitment_tx_fee = None ;
4740
4762
read_tlv_fields ! ( reader, {
4741
4763
( 1 , funding_spend_confirmed, option) ,
4742
4764
( 3 , htlcs_resolved_on_chain, optional_vec) ,
@@ -4749,6 +4771,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
4749
4771
( 17 , initial_counterparty_commitment_info, option) ,
4750
4772
( 19 , channel_id, option) ,
4751
4773
( 21 , balances_empty_height, option) ,
4774
+ ( 23 , holder_pays_commitment_tx_fee, option) ,
4752
4775
} ) ;
4753
4776
4754
4777
// `HolderForceClosedWithInfo` replaced `HolderForceClosed` in v0.0.122. If we have both
@@ -4818,6 +4841,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
4818
4841
4819
4842
lockdown_from_offchain,
4820
4843
holder_tx_signed,
4844
+ holder_pays_commitment_tx_fee,
4821
4845
funding_spend_seen : funding_spend_seen. unwrap ( ) ,
4822
4846
funding_spend_confirmed,
4823
4847
confirmed_commitment_tx_counterparty_output,
@@ -5057,7 +5081,7 @@ mod tests {
5057
5081
let monitor = ChannelMonitor :: new ( Secp256k1 :: new ( ) , keys,
5058
5082
Some ( ShutdownScript :: new_p2wpkh_from_pubkey ( shutdown_pubkey) . into_inner ( ) ) , 0 , & ScriptBuf :: new ( ) ,
5059
5083
( OutPoint { txid : Txid :: from_slice ( & [ 43 ; 32 ] ) . unwrap ( ) , index : 0 } , ScriptBuf :: new ( ) ) ,
5060
- & channel_parameters, ScriptBuf :: new ( ) , 46 , 0 , HolderCommitmentTransaction :: dummy ( & mut Vec :: new ( ) ) ,
5084
+ & channel_parameters, true , ScriptBuf :: new ( ) , 46 , 0 , HolderCommitmentTransaction :: dummy ( & mut Vec :: new ( ) ) ,
5061
5085
best_block, dummy_key, channel_id) ;
5062
5086
5063
5087
let mut htlcs = preimages_slice_to_htlcs ! ( preimages[ 0 ..10 ] ) ;
@@ -5305,7 +5329,7 @@ mod tests {
5305
5329
let monitor = ChannelMonitor :: new ( Secp256k1 :: new ( ) , keys,
5306
5330
Some ( ShutdownScript :: new_p2wpkh_from_pubkey ( shutdown_pubkey) . into_inner ( ) ) , 0 , & ScriptBuf :: new ( ) ,
5307
5331
( OutPoint { txid : Txid :: from_slice ( & [ 43 ; 32 ] ) . unwrap ( ) , index : 0 } , ScriptBuf :: new ( ) ) ,
5308
- & channel_parameters, ScriptBuf :: new ( ) , 46 , 0 , HolderCommitmentTransaction :: dummy ( & mut Vec :: new ( ) ) ,
5332
+ & channel_parameters, true , ScriptBuf :: new ( ) , 46 , 0 , HolderCommitmentTransaction :: dummy ( & mut Vec :: new ( ) ) ,
5309
5333
best_block, dummy_key, channel_id) ;
5310
5334
5311
5335
let chan_id = monitor. inner . lock ( ) . unwrap ( ) . channel_id ( ) ;
0 commit comments