@@ -547,6 +547,9 @@ pub(crate) enum ChannelMonitorUpdateStep {
547
547
feerate_per_kw : Option < u32 > ,
548
548
to_broadcaster_value_sat : Option < u64 > ,
549
549
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 > ,
550
553
} ,
551
554
PaymentPreimage {
552
555
payment_preimage : PaymentPreimage ,
@@ -598,6 +601,8 @@ impl_writeable_tlv_based_enum_upgradable!(ChannelMonitorUpdateStep,
598
601
( 4 , their_per_commitment_point, required) ,
599
602
( 5 , to_countersignatory_value_sat, option) ,
600
603
( 6 , htlc_outputs, required_vec) ,
604
+ ( 7 , value_to_self_with_offset_msat, option) ,
605
+ ( 9 , counterparty_dust_limit_satoshis, option) ,
601
606
} ,
602
607
( 2 , PaymentPreimage ) => {
603
608
( 0 , payment_preimage, required) ,
@@ -1024,8 +1029,8 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
1024
1029
/// monitors created after 0.0.117.
1025
1030
///
1026
1031
/// 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 ) > ,
1029
1034
1030
1035
/// The first block height at which we had no remaining claimable balances.
1031
1036
balances_empty_height : Option < u32 > ,
@@ -1501,15 +1506,16 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1501
1506
pub ( crate ) fn provide_initial_counterparty_commitment_tx < L : Deref > (
1502
1507
& self , txid : Txid , htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < Box < HTLCSource > > ) > ,
1503
1508
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 ,
1505
1511
)
1506
1512
where L :: Target : Logger
1507
1513
{
1508
1514
let mut inner = self . inner . lock ( ) . unwrap ( ) ;
1509
1515
let logger = WithChannelMonitor :: from_impl ( logger, & * inner, None ) ;
1510
1516
inner. provide_initial_counterparty_commitment_tx ( txid,
1511
1517
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) ;
1513
1519
}
1514
1520
1515
1521
/// Informs this monitor of the latest counterparty (ie non-broadcastable) commitment transaction.
@@ -2874,10 +2880,11 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2874
2880
fn provide_initial_counterparty_commitment_tx < L : Deref > (
2875
2881
& mut self , txid : Txid , htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < Box < HTLCSource > > ) > ,
2876
2882
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 > ,
2878
2885
) where L :: Target : Logger {
2879
2886
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 ) ) ;
2881
2888
2882
2889
#[ cfg( debug_assertions) ] {
2883
2890
let rebuilt_commitment_tx = self . initial_counterparty_commitment_tx ( ) . unwrap ( ) ;
@@ -3437,14 +3444,17 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3437
3444
}
3438
3445
3439
3446
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 ;
3442
3450
let htlc_outputs = vec ! [ ] ;
3443
3451
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 )
3448
3458
}
3449
3459
3450
3460
fn build_counterparty_commitment_tx (
@@ -3477,7 +3487,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3477
3487
ref htlc_outputs, commitment_number, their_per_commitment_point,
3478
3488
feerate_per_kw : Some ( feerate_per_kw) ,
3479
3489
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 } => {
3481
3492
3482
3493
let nondust_htlcs = htlc_outputs. iter ( ) . filter_map ( |( htlc, _) | {
3483
3494
htlc. transaction_output_index . map ( |_| ( htlc. clone ( ) , None ) )
@@ -3491,6 +3502,25 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3491
3502
3492
3503
Some ( commitment_tx)
3493
3504
} ,
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
+ } ,
3494
3524
_ => None ,
3495
3525
}
3496
3526
} ) . collect ( )
0 commit comments