@@ -548,6 +548,7 @@ pub(crate) enum ChannelMonitorUpdateStep {
548
548
feerate_per_kw : Option < u32 > ,
549
549
to_broadcaster_value_sat : Option < u64 > ,
550
550
to_countersignatory_value_sat : Option < u64 > ,
551
+ commitment_tx : Option < CommitmentTransaction > ,
551
552
} ,
552
553
PaymentPreimage {
553
554
payment_preimage : PaymentPreimage ,
@@ -599,6 +600,7 @@ impl_writeable_tlv_based_enum_upgradable!(ChannelMonitorUpdateStep,
599
600
( 4 , their_per_commitment_point, required) ,
600
601
( 5 , to_countersignatory_value_sat, option) ,
601
602
( 6 , htlc_outputs, required_vec) ,
603
+ ( 7 , commitment_tx, option) ,
602
604
} ,
603
605
( 2 , PaymentPreimage ) => {
604
606
( 0 , payment_preimage, required) ,
@@ -1027,6 +1029,10 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
1027
1029
/// Ordering of tuple data: (their_per_commitment_point, feerate_per_kw, to_broadcaster_sats,
1028
1030
/// to_countersignatory_sats)
1029
1031
initial_counterparty_commitment_info : Option < ( PublicKey , u32 , u64 , u64 ) > ,
1032
+ /// Initial counterparty commitment transaction
1033
+ ///
1034
+ /// We previously used the field above to re-build the transaction, we now provide it outright.
1035
+ initial_counterparty_commitment_tx : Option < CommitmentTransaction > ,
1030
1036
1031
1037
/// The first block height at which we had no remaining claimable balances.
1032
1038
balances_empty_height : Option < u32 > ,
@@ -1250,6 +1256,7 @@ impl<Signer: EcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signer> {
1250
1256
( 23 , self . holder_pays_commitment_tx_fee, option) ,
1251
1257
( 25 , self . payment_preimages, required) ,
1252
1258
( 27 , self . first_confirmed_funding_txo, required) ,
1259
+ ( 29 , self . initial_counterparty_commitment_tx, option) ,
1253
1260
} ) ;
1254
1261
1255
1262
Ok ( ( ) )
@@ -1461,6 +1468,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1461
1468
best_block,
1462
1469
counterparty_node_id : Some ( counterparty_node_id) ,
1463
1470
initial_counterparty_commitment_info : None ,
1471
+ initial_counterparty_commitment_tx : None ,
1464
1472
balances_empty_height : None ,
1465
1473
1466
1474
failed_back_htlc_ids : new_hash_set ( ) ,
@@ -1500,17 +1508,14 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1500
1508
/// This is used to provide the counterparty commitment information directly to the monitor
1501
1509
/// before the initial persistence of a new channel.
1502
1510
pub ( crate ) fn provide_initial_counterparty_commitment_tx < L : Deref > (
1503
- & self , txid : Txid , htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < Box < HTLCSource > > ) > ,
1504
- commitment_number : u64 , their_cur_per_commitment_point : PublicKey , feerate_per_kw : u32 ,
1505
- to_broadcaster_value_sat : u64 , to_countersignatory_value_sat : u64 , logger : & L ,
1511
+ & self , htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < Box < HTLCSource > > ) > ,
1512
+ commitment_tx : CommitmentTransaction , logger : & L ,
1506
1513
)
1507
1514
where L :: Target : Logger
1508
1515
{
1509
1516
let mut inner = self . inner . lock ( ) . unwrap ( ) ;
1510
1517
let logger = WithChannelMonitor :: from_impl ( logger, & * inner, None ) ;
1511
- inner. provide_initial_counterparty_commitment_tx ( txid,
1512
- htlc_outputs, commitment_number, their_cur_per_commitment_point, feerate_per_kw,
1513
- to_broadcaster_value_sat, to_countersignatory_value_sat, & logger) ;
1518
+ inner. provide_initial_counterparty_commitment_tx ( htlc_outputs, commitment_tx, & logger) ;
1514
1519
}
1515
1520
1516
1521
/// Informs this monitor of the latest counterparty (ie non-broadcastable) commitment transaction.
@@ -2878,20 +2883,22 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2878
2883
}
2879
2884
2880
2885
fn provide_initial_counterparty_commitment_tx < L : Deref > (
2881
- & mut self , txid : Txid , htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < Box < HTLCSource > > ) > ,
2882
- commitment_number : u64 , their_per_commitment_point : PublicKey , feerate_per_kw : u32 ,
2883
- to_broadcaster_value : u64 , to_countersignatory_value : u64 , logger : & WithChannelMonitor < L > ,
2886
+ & mut self , htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < Box < HTLCSource > > ) > ,
2887
+ commitment_tx : CommitmentTransaction , logger : & WithChannelMonitor < L > ,
2884
2888
) where L :: Target : Logger {
2885
- self . initial_counterparty_commitment_info = Some ( ( their_per_commitment_point. clone ( ) ,
2886
- feerate_per_kw, to_broadcaster_value, to_countersignatory_value) ) ;
2889
+ // We populate this field for downgrades
2890
+ self . initial_counterparty_commitment_info = Some ( ( commitment_tx. per_commitment_point ( ) ,
2891
+ commitment_tx. feerate_per_kw ( ) , commitment_tx. to_broadcaster_value_sat ( ) , commitment_tx. to_countersignatory_value_sat ( ) ) ) ;
2887
2892
2888
2893
#[ cfg( debug_assertions) ] {
2889
2894
let rebuilt_commitment_tx = self . initial_counterparty_commitment_tx ( ) . unwrap ( ) ;
2890
- debug_assert_eq ! ( rebuilt_commitment_tx. trust( ) . txid( ) , txid) ;
2895
+ debug_assert_eq ! ( rebuilt_commitment_tx. trust( ) . txid( ) , commitment_tx . trust ( ) . txid( ) ) ;
2891
2896
}
2892
2897
2893
- self . provide_latest_counterparty_commitment_tx ( txid, htlc_outputs, commitment_number,
2894
- their_per_commitment_point, logger) ;
2898
+ self . provide_latest_counterparty_commitment_tx ( commitment_tx. trust ( ) . txid ( ) , htlc_outputs, commitment_tx. commitment_number ( ) ,
2899
+ commitment_tx. per_commitment_point ( ) , logger) ;
2900
+ // Soon, we will only populate this field
2901
+ self . initial_counterparty_commitment_tx = Some ( commitment_tx) ;
2895
2902
}
2896
2903
2897
2904
fn provide_latest_counterparty_commitment_tx < L : Deref > (
@@ -3442,15 +3449,20 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3442
3449
ret
3443
3450
}
3444
3451
3445
- fn initial_counterparty_commitment_tx ( & mut self ) -> Option < CommitmentTransaction > {
3446
- let ( their_per_commitment_point, feerate_per_kw, to_broadcaster_value,
3447
- to_countersignatory_value) = self . initial_counterparty_commitment_info ?;
3448
- let htlc_outputs = vec ! [ ] ;
3452
+ fn initial_counterparty_commitment_tx ( & self ) -> Option < CommitmentTransaction > {
3453
+ // This provides forward compatibility; an old monitor will not contain the full transaction; only enough
3454
+ // information to rebuild it
3455
+ if let Some ( ( their_per_commitment_point, feerate_per_kw, to_broadcaster_value,
3456
+ to_countersignatory_value) ) = self . initial_counterparty_commitment_info {
3457
+ let htlc_outputs = vec ! [ ] ;
3449
3458
3450
- let commitment_tx = self . build_counterparty_commitment_tx ( INITIAL_COMMITMENT_NUMBER ,
3451
- & their_per_commitment_point, to_broadcaster_value, to_countersignatory_value,
3452
- feerate_per_kw, htlc_outputs) ;
3453
- Some ( commitment_tx)
3459
+ let commitment_tx = self . build_counterparty_commitment_tx ( INITIAL_COMMITMENT_NUMBER ,
3460
+ & their_per_commitment_point, to_broadcaster_value, to_countersignatory_value,
3461
+ feerate_per_kw, htlc_outputs) ;
3462
+ Some ( commitment_tx)
3463
+ } else {
3464
+ self . initial_counterparty_commitment_tx . clone ( )
3465
+ }
3454
3466
}
3455
3467
3456
3468
fn build_counterparty_commitment_tx (
@@ -3479,11 +3491,13 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3479
3491
fn counterparty_commitment_txs_from_update ( & self , update : & ChannelMonitorUpdate ) -> Vec < CommitmentTransaction > {
3480
3492
update. updates . iter ( ) . filter_map ( |update| {
3481
3493
match update {
3494
+ // Provided for forward compatibility; old updates won't contain the full transaction
3482
3495
& ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { commitment_txid,
3483
3496
ref htlc_outputs, commitment_number, their_per_commitment_point,
3484
3497
feerate_per_kw : Some ( feerate_per_kw) ,
3485
3498
to_broadcaster_value_sat : Some ( to_broadcaster_value) ,
3486
- to_countersignatory_value_sat : Some ( to_countersignatory_value) } => {
3499
+ to_countersignatory_value_sat : Some ( to_countersignatory_value) ,
3500
+ commitment_tx : None } => {
3487
3501
3488
3502
let nondust_htlcs = htlc_outputs. iter ( ) . filter_map ( |( htlc, _) | {
3489
3503
htlc. transaction_output_index . map ( |_| ( htlc. clone ( ) , None ) )
@@ -3497,6 +3511,15 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3497
3511
3498
3512
Some ( commitment_tx)
3499
3513
} ,
3514
+ & ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { commitment_txid : _,
3515
+ htlc_outputs : _, commitment_number : _, their_per_commitment_point : _,
3516
+ feerate_per_kw : _,
3517
+ to_broadcaster_value_sat : _,
3518
+ to_countersignatory_value_sat : _,
3519
+ commitment_tx : Some ( ref commitment_tx) } => {
3520
+
3521
+ Some ( commitment_tx. clone ( ) )
3522
+ } ,
3500
3523
_ => None ,
3501
3524
}
3502
3525
} ) . collect ( )
@@ -5079,6 +5102,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
5079
5102
let mut spendable_txids_confirmed = Some ( Vec :: new ( ) ) ;
5080
5103
let mut counterparty_fulfilled_htlcs = Some ( new_hash_map ( ) ) ;
5081
5104
let mut initial_counterparty_commitment_info = None ;
5105
+ let mut initial_counterparty_commitment_tx = None ;
5082
5106
let mut balances_empty_height = None ;
5083
5107
let mut channel_id = None ;
5084
5108
let mut holder_pays_commitment_tx_fee = None ;
@@ -5099,6 +5123,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
5099
5123
( 23 , holder_pays_commitment_tx_fee, option) ,
5100
5124
( 25 , payment_preimages_with_info, option) ,
5101
5125
( 27 , first_confirmed_funding_txo, ( default_value, funding_info. 0 ) ) ,
5126
+ ( 29 , initial_counterparty_commitment_tx, option) ,
5102
5127
} ) ;
5103
5128
if let Some ( payment_preimages_with_info) = payment_preimages_with_info {
5104
5129
if payment_preimages_with_info. len ( ) != payment_preimages. len ( ) {
@@ -5195,6 +5220,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
5195
5220
best_block,
5196
5221
counterparty_node_id,
5197
5222
initial_counterparty_commitment_info,
5223
+ initial_counterparty_commitment_tx,
5198
5224
balances_empty_height,
5199
5225
failed_back_htlc_ids : new_hash_set ( ) ,
5200
5226
} ) ) )
0 commit comments