@@ -547,6 +547,9 @@ pub(crate) enum ChannelMonitorUpdateStep {
547547 feerate_per_kw : Option < u32 > ,
548548 to_broadcaster_value_sat : Option < u64 > ,
549549 to_countersignatory_value_sat : Option < u64 > ,
550+ // See docs for `CommitmentStats`, and `ChannelContext::build_commitment_transaction`
551+ value_to_self_with_offset_msat : Option < u64 > ,
552+ counterparty_dust_limit_satoshis : Option < u64 > ,
550553 } ,
551554 PaymentPreimage {
552555 payment_preimage : PaymentPreimage ,
@@ -598,6 +601,8 @@ impl_writeable_tlv_based_enum_upgradable!(ChannelMonitorUpdateStep,
598601 ( 4 , their_per_commitment_point, required) ,
599602 ( 5 , to_countersignatory_value_sat, option) ,
600603 ( 6 , htlc_outputs, required_vec) ,
604+ ( 7 , value_to_self_with_offset_msat, option) ,
605+ ( 9 , counterparty_dust_limit_satoshis, option) ,
601606 } ,
602607 ( 2 , PaymentPreimage ) => {
603608 ( 0 , payment_preimage, required) ,
@@ -1024,8 +1029,8 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
10241029 /// monitors created after 0.0.117.
10251030 ///
10261031 /// Ordering of tuple data: (their_per_commitment_point, feerate_per_kw, to_broadcaster_sats,
1027- /// to_countersignatory_sats)
1028- initial_counterparty_commitment_info : Option < ( PublicKey , u32 , u64 , u64 ) > ,
1032+ /// to_countersignatory_sats, value_to_self_with_offset_msat, counterparty_dust_limit_satoshis )
1033+ initial_counterparty_commitment_info : Option < ( PublicKey , u32 , u64 , u64 , u64 , u64 ) > ,
10291034
10301035 /// The first block height at which we had no remaining claimable balances.
10311036 balances_empty_height : Option < u32 > ,
@@ -1501,15 +1506,16 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
15011506 pub ( crate ) fn provide_initial_counterparty_commitment_tx < L : Deref > (
15021507 & self , txid : Txid , htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < Box < HTLCSource > > ) > ,
15031508 commitment_number : u64 , their_cur_per_commitment_point : PublicKey , feerate_per_kw : u32 ,
1504- to_broadcaster_value_sat : u64 , to_countersignatory_value_sat : u64 , logger : & L ,
1509+ to_broadcaster_value_sat : u64 , to_countersignatory_value_sat : u64 , value_to_self_with_offset_msat : u64 , counterparty_dust_limit_satoshis : u64 ,
1510+ logger : & L ,
15051511 )
15061512 where L :: Target : Logger
15071513 {
15081514 let mut inner = self . inner . lock ( ) . unwrap ( ) ;
15091515 let logger = WithChannelMonitor :: from_impl ( logger, & * inner, None ) ;
15101516 inner. provide_initial_counterparty_commitment_tx ( txid,
15111517 htlc_outputs, commitment_number, their_cur_per_commitment_point, feerate_per_kw,
1512- to_broadcaster_value_sat, to_countersignatory_value_sat, & logger) ;
1518+ to_broadcaster_value_sat, to_countersignatory_value_sat, value_to_self_with_offset_msat , counterparty_dust_limit_satoshis , & logger) ;
15131519 }
15141520
15151521 /// Informs this monitor of the latest counterparty (ie non-broadcastable) commitment transaction.
@@ -2874,10 +2880,11 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
28742880 fn provide_initial_counterparty_commitment_tx < L : Deref > (
28752881 & mut self , txid : Txid , htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < Box < HTLCSource > > ) > ,
28762882 commitment_number : u64 , their_per_commitment_point : PublicKey , feerate_per_kw : u32 ,
2877- to_broadcaster_value : u64 , to_countersignatory_value : u64 , logger : & WithChannelMonitor < L > ,
2883+ to_broadcaster_value : u64 , to_countersignatory_value : u64 , value_to_self_with_offset_msat : u64 , counterparty_dust_limit_satoshis : u64 ,
2884+ logger : & WithChannelMonitor < L > ,
28782885 ) where L :: Target : Logger {
28792886 self . initial_counterparty_commitment_info = Some ( ( their_per_commitment_point. clone ( ) ,
2880- feerate_per_kw, to_broadcaster_value, to_countersignatory_value) ) ;
2887+ feerate_per_kw, to_broadcaster_value, to_countersignatory_value, value_to_self_with_offset_msat , counterparty_dust_limit_satoshis ) ) ;
28812888
28822889 #[ cfg( debug_assertions) ] {
28832890 let rebuilt_commitment_tx = self . initial_counterparty_commitment_tx ( ) . unwrap ( ) ;
@@ -3437,14 +3444,17 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
34373444 }
34383445
34393446 fn initial_counterparty_commitment_tx ( & mut self ) -> Option < CommitmentTransaction > {
3440- let ( their_per_commitment_point, feerate_per_kw, to_broadcaster_value,
3441- to_countersignatory_value) = self . initial_counterparty_commitment_info ?;
3447+ let ( their_per_commitment_point, feerate_per_kw, _to_broadcaster_value,
3448+ _to_countersignatory_value, value_to_self_with_offset_msat, counterparty_dust_limit_satoshis) = self . initial_counterparty_commitment_info ?;
3449+ let channel_transaction_parameters = & self . onchain_tx_handler . channel_transaction_parameters ;
34423450 let htlc_outputs = vec ! [ ] ;
34433451
3444- let commitment_tx = self . build_counterparty_commitment_tx ( INITIAL_COMMITMENT_NUMBER ,
3445- & their_per_commitment_point, to_broadcaster_value, to_countersignatory_value,
3446- feerate_per_kw, htlc_outputs) ;
3447- Some ( commitment_tx)
3452+ use crate :: sign:: tx_builder:: { SpecTxBuilder , TxBuilder } ;
3453+ let stats = TxBuilder :: build_commitment_transaction ( & SpecTxBuilder { } , false , INITIAL_COMMITMENT_NUMBER ,
3454+ & their_per_commitment_point, channel_transaction_parameters, & self . onchain_tx_handler . secp_ctx ,
3455+ self . channel_value_satoshis , value_to_self_with_offset_msat, htlc_outputs, feerate_per_kw, counterparty_dust_limit_satoshis) ;
3456+
3457+ Some ( stats. tx )
34483458 }
34493459
34503460 fn build_counterparty_commitment_tx (
@@ -3477,7 +3487,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
34773487 ref htlc_outputs, commitment_number, their_per_commitment_point,
34783488 feerate_per_kw : Some ( feerate_per_kw) ,
34793489 to_broadcaster_value_sat : Some ( to_broadcaster_value) ,
3480- to_countersignatory_value_sat : Some ( to_countersignatory_value) } => {
3490+ to_countersignatory_value_sat : Some ( to_countersignatory_value) ,
3491+ value_to_self_with_offset_msat : None , counterparty_dust_limit_satoshis : None } => {
34813492
34823493 let nondust_htlcs = htlc_outputs. iter ( ) . filter_map ( |( htlc, _) | {
34833494 htlc. transaction_output_index . map ( |_| ( htlc. clone ( ) , None ) )
@@ -3491,6 +3502,25 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
34913502
34923503 Some ( commitment_tx)
34933504 } ,
3505+ & ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { commitment_txid,
3506+ ref htlc_outputs, commitment_number, their_per_commitment_point,
3507+ feerate_per_kw : Some ( feerate_per_kw) ,
3508+ to_broadcaster_value_sat : Some ( _to_broadcaster_value) ,
3509+ to_countersignatory_value_sat : Some ( _to_countersignatory_value) ,
3510+ value_to_self_with_offset_msat : Some ( value_to_self_with_offset) , counterparty_dust_limit_satoshis : Some ( dust_limit_satoshis) } => {
3511+
3512+ let channel_transaction_parameters = & self . onchain_tx_handler . channel_transaction_parameters ;
3513+ let htlc_outputs = htlc_outputs. iter ( ) . map ( |( htlc, source) | ( htlc. clone ( ) , source. as_ref ( ) . map ( |s| s. as_ref ( ) ) ) ) . collect ( ) ;
3514+
3515+ use crate :: sign:: tx_builder:: { SpecTxBuilder , TxBuilder } ;
3516+ let stats = TxBuilder :: build_commitment_transaction ( & SpecTxBuilder { } , false , commitment_number, & their_per_commitment_point,
3517+ channel_transaction_parameters, & self . onchain_tx_handler . secp_ctx , self . channel_value_satoshis , value_to_self_with_offset,
3518+ htlc_outputs, feerate_per_kw, dust_limit_satoshis) ;
3519+
3520+ debug_assert_eq ! ( stats. tx. trust( ) . txid( ) , commitment_txid) ;
3521+
3522+ Some ( stats. tx )
3523+ } ,
34943524 _ => None ,
34953525 }
34963526 } ) . collect ( )
0 commit comments