@@ -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.
@@ -912,6 +919,10 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
912
919
// of block connection between ChannelMonitors and the ChannelManager.
913
920
funding_spend_seen : bool ,
914
921
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
+
915
926
/// Set to `Some` of the confirmed transaction spending the funding input of the channel after
916
927
/// reaching `ANTI_REORG_DELAY` confirmations.
917
928
funding_spend_confirmed : Option < Txid > ,
@@ -1160,6 +1171,7 @@ impl<Signer: EcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signer> {
1160
1171
( 17 , self . initial_counterparty_commitment_info, option) ,
1161
1172
( 19 , self . channel_id, required) ,
1162
1173
( 21 , self . balances_empty_height, option) ,
1174
+ ( 23 , self . holder_pays_commitment_tx_fee, option) ,
1163
1175
} ) ;
1164
1176
1165
1177
Ok ( ( ) )
@@ -1261,7 +1273,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1261
1273
1262
1274
pub ( crate ) fn new ( secp_ctx : Secp256k1 < secp256k1:: All > , keys : Signer , shutdown_script : Option < ScriptBuf > ,
1263
1275
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 ,
1265
1277
funding_redeemscript : ScriptBuf , channel_value_satoshis : u64 ,
1266
1278
commitment_transaction_number_obscure_factor : u64 ,
1267
1279
initial_holder_commitment_tx : HolderCommitmentTransaction ,
@@ -1353,6 +1365,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1353
1365
1354
1366
onchain_tx_handler,
1355
1367
1368
+ holder_pays_commitment_tx_fee : Some ( holder_pays_commitment_tx_fee) ,
1356
1369
lockdown_from_offchain : false ,
1357
1370
holder_tx_signed : false ,
1358
1371
funding_spend_seen : false ,
@@ -2306,8 +2319,11 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2306
2319
}
2307
2320
} else {
2308
2321
let mut claimable_inbound_htlc_value_sat = 0 ;
2322
+ let mut nondust_htlc_count = 0 ;
2309
2323
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 ; }
2311
2327
if htlc. offered {
2312
2328
let outbound_payment = match source {
2313
2329
None => {
@@ -2337,6 +2353,11 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2337
2353
}
2338
2354
res. push ( Balance :: ClaimableOnChannelClose {
2339
2355
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 } ,
2340
2361
} ) ;
2341
2362
}
2342
2363
@@ -4743,6 +4764,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
4743
4764
let mut initial_counterparty_commitment_info = None ;
4744
4765
let mut balances_empty_height = None ;
4745
4766
let mut channel_id = None ;
4767
+ let mut holder_pays_commitment_tx_fee = None ;
4746
4768
read_tlv_fields ! ( reader, {
4747
4769
( 1 , funding_spend_confirmed, option) ,
4748
4770
( 3 , htlcs_resolved_on_chain, optional_vec) ,
@@ -4755,6 +4777,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
4755
4777
( 17 , initial_counterparty_commitment_info, option) ,
4756
4778
( 19 , channel_id, option) ,
4757
4779
( 21 , balances_empty_height, option) ,
4780
+ ( 23 , holder_pays_commitment_tx_fee, option) ,
4758
4781
} ) ;
4759
4782
4760
4783
// `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
4824
4847
4825
4848
lockdown_from_offchain,
4826
4849
holder_tx_signed,
4850
+ holder_pays_commitment_tx_fee,
4827
4851
funding_spend_seen : funding_spend_seen. unwrap ( ) ,
4828
4852
funding_spend_confirmed,
4829
4853
confirmed_commitment_tx_counterparty_output,
@@ -5063,7 +5087,7 @@ mod tests {
5063
5087
let monitor = ChannelMonitor :: new ( Secp256k1 :: new ( ) , keys,
5064
5088
Some ( ShutdownScript :: new_p2wpkh_from_pubkey ( shutdown_pubkey) . into_inner ( ) ) , 0 , & ScriptBuf :: new ( ) ,
5065
5089
( 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 ( ) ) ,
5067
5091
best_block, dummy_key, channel_id) ;
5068
5092
5069
5093
let mut htlcs = preimages_slice_to_htlcs ! ( preimages[ 0 ..10 ] ) ;
@@ -5311,7 +5335,7 @@ mod tests {
5311
5335
let monitor = ChannelMonitor :: new ( Secp256k1 :: new ( ) , keys,
5312
5336
Some ( ShutdownScript :: new_p2wpkh_from_pubkey ( shutdown_pubkey) . into_inner ( ) ) , 0 , & ScriptBuf :: new ( ) ,
5313
5337
( 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 ( ) ) ,
5315
5339
best_block, dummy_key, channel_id) ;
5316
5340
5317
5341
let chan_id = monitor. inner . lock ( ) . unwrap ( ) . channel_id ( ) ;
0 commit comments