@@ -38,7 +38,7 @@ use crate::types::features::ChannelTypeFeatures;
38
38
use crate :: types:: payment:: { PaymentHash , PaymentPreimage } ;
39
39
use crate :: ln:: msgs:: DecodeError ;
40
40
use crate :: ln:: channel_keys:: { DelayedPaymentKey , DelayedPaymentBasepoint , HtlcBasepoint , HtlcKey , RevocationKey , RevocationBasepoint } ;
41
- use crate :: ln:: chan_utils:: { self , CommitmentTransaction , CounterpartyCommitmentSecrets , HTLCOutputInCommitment , HTLCClaim , ChannelTransactionParameters , HolderCommitmentTransaction } ;
41
+ use crate :: ln:: chan_utils:: { self , CommitmentTransaction , CounterpartyCommitmentSecrets , HTLCOutputInCommitment , HTLCClaim , ChannelTransactionParameters , HolderCommitmentTransaction , HTLCOutputData } ;
42
42
use crate :: ln:: channelmanager:: { HTLCSource , SentHTLCId , PaymentClaimDetails } ;
43
43
use crate :: chain;
44
44
use crate :: chain:: { BestBlock , WatchedOutput } ;
@@ -591,11 +591,18 @@ pub(crate) enum ChannelMonitorUpdateStep {
591
591
to_broadcaster_value_sat : Option < u64 > ,
592
592
to_countersignatory_value_sat : Option < u64 > ,
593
593
} ,
594
- LatestCounterpartyCommitmentTX {
594
+ LatestHolderCommitmentTXs {
595
595
// The dust and non-dust htlcs for that commitment
596
- htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < Box < HTLCSource > > ) > ,
596
+ htlc_data : Vec < ( HTLCOutputData , Option < Box < HTLCSource > > ) > ,
597
+ // Contains only the non-dust htlcs
598
+ commitment_txs : Vec < HolderCommitmentTransaction > ,
599
+ claimed_htlcs : Vec < ( SentHTLCId , PaymentPreimage ) > ,
600
+ } ,
601
+ LatestCounterpartyCommitmentTXs {
602
+ // The dust and non-dust htlcs for that commitment
603
+ htlc_data : Vec < ( HTLCOutputData , Option < Box < HTLCSource > > ) > ,
597
604
// Contains only the non-dust htlcs
598
- commitment_tx : CommitmentTransaction ,
605
+ commitment_txs : Vec < CommitmentTransaction > ,
599
606
} ,
600
607
PaymentPreimage {
601
608
payment_preimage : PaymentPreimage ,
@@ -624,7 +631,8 @@ impl ChannelMonitorUpdateStep {
624
631
match self {
625
632
ChannelMonitorUpdateStep :: LatestHolderCommitmentTXInfo { .. } => "LatestHolderCommitmentTXInfo" ,
626
633
ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { .. } => "LatestCounterpartyCommitmentTXInfo" ,
627
- ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTX { .. } => "LatestCounterpartyCommitmentTX" ,
634
+ ChannelMonitorUpdateStep :: LatestHolderCommitmentTXs { .. } => "LatestHolderCommitmentTXs" ,
635
+ ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXs { .. } => "LatestCounterpartyCommitmentTXs" ,
628
636
ChannelMonitorUpdateStep :: PaymentPreimage { .. } => "PaymentPreimage" ,
629
637
ChannelMonitorUpdateStep :: CommitmentSecret { .. } => "CommitmentSecret" ,
630
638
ChannelMonitorUpdateStep :: ChannelForceClosed { .. } => "ChannelForceClosed" ,
@@ -663,9 +671,14 @@ impl_writeable_tlv_based_enum_upgradable!(ChannelMonitorUpdateStep,
663
671
( 5 , ShutdownScript ) => {
664
672
( 0 , scriptpubkey, required) ,
665
673
} ,
666
- ( 6 , LatestCounterpartyCommitmentTX ) => {
667
- ( 0 , htlc_outputs, required_vec) ,
668
- ( 2 , commitment_tx, required) ,
674
+ ( 6 , LatestHolderCommitmentTXs ) => { // Added in 0.2
675
+ ( 1 , htlc_data, required_vec) ,
676
+ ( 3 , commitment_txs, required_vec) ,
677
+ ( 5 , claimed_htlcs, required_vec) ,
678
+ } ,
679
+ ( 8 , LatestCounterpartyCommitmentTXs ) => { // Added in 0.2
680
+ ( 1 , htlc_data, required_vec) ,
681
+ ( 3 , commitment_txs, required_vec) ,
669
682
} ,
670
683
) ;
671
684
@@ -3084,6 +3097,19 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3084
3097
}
3085
3098
}
3086
3099
3100
+ // This is the sibling of `provide_latest_counterparty_commitment_tx`, but updated for a world
3101
+ // in which the HTLC-source table passed from channel does NOT store dust-vs-nondust and
3102
+ // index HTLC data.
3103
+ fn provide_latest_counterparty_commitment_data < L : Deref > (
3104
+ & mut self ,
3105
+ _htlc_data : Vec < ( HTLCOutputData , Option < Box < HTLCSource > > ) > ,
3106
+ _txs : & Vec < CommitmentTransaction > ,
3107
+ _logger : & WithChannelMonitor < L > ,
3108
+ ) where L :: Target : Logger {
3109
+ // TODO(splicing, 0.2): Populate this monitor's data structures
3110
+ todo ! ( ) ;
3111
+ }
3112
+
3087
3113
/// Informs this monitor of the latest holder (ie broadcastable) commitment transaction. The
3088
3114
/// monitor watches for timeouts and may broadcast it if we approach such a timeout. Thus, it
3089
3115
/// is important that any clones of this channel monitor (including remote clones) by kept
@@ -3175,6 +3201,19 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3175
3201
}
3176
3202
}
3177
3203
3204
+ // This is the sibling of `provide_latest_holder_commitment_tx`, but updated for a world
3205
+ // in which the HTLC-source table passed from channel does NOT store dust-vs-nondust and
3206
+ // index HTLC data.
3207
+ fn provide_latest_holder_commitment_data (
3208
+ & mut self ,
3209
+ _htlc_data : Vec < ( HTLCOutputData , Option < Box < HTLCSource > > ) > ,
3210
+ _holder_commitment_txs : Vec < HolderCommitmentTransaction > ,
3211
+ _claimed_htlcs : & [ ( SentHTLCId , PaymentPreimage ) ] ,
3212
+ ) {
3213
+ // TODO(splicing, 0.2): Populate this monitor's data structures
3214
+ todo ! ( ) ;
3215
+ }
3216
+
3178
3217
/// Provides a payment_hash->payment_preimage mapping. Will be automatically pruned when all
3179
3218
/// commitment_tx_infos which contain the payment hash have been revoked.
3180
3219
///
@@ -3392,16 +3431,21 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3392
3431
if self . lockdown_from_offchain { panic ! ( ) ; }
3393
3432
self . provide_latest_holder_commitment_tx ( commitment_tx. clone ( ) , htlc_outputs. clone ( ) , & claimed_htlcs, nondust_htlc_sources. clone ( ) ) ;
3394
3433
}
3395
- // Soon we will drop the `LatestCounterpartyCommitmentTXInfo` variant in favor of `LatestCounterpartyCommitmentTX `.
3434
+ // Soon we will drop the `LatestCounterpartyCommitmentTXInfo` variant in favor of `LatestCounterpartyCommitmentTXs `.
3396
3435
// For now we just add the code to handle the new updates.
3397
- // Next step: in channel, switch channel monitor updates to use the `LatestCounterpartyCommitmentTX ` variant.
3436
+ // Next step: in channel, switch channel monitor updates to use the `LatestCounterpartyCommitmentTXs ` variant.
3398
3437
ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { commitment_txid, htlc_outputs, commitment_number, their_per_commitment_point, .. } => {
3399
3438
log_trace ! ( logger, "Updating ChannelMonitor with latest counterparty commitment transaction info" ) ;
3400
3439
self . provide_latest_counterparty_commitment_tx ( * commitment_txid, htlc_outputs. clone ( ) , * commitment_number, * their_per_commitment_point, logger)
3401
3440
} ,
3402
- ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTX { htlc_outputs, commitment_tx } => {
3403
- log_trace ! ( logger, "Updating ChannelMonitor with latest counterparty commitment transaction info" ) ;
3404
- self . provide_latest_counterparty_commitment_tx ( commitment_tx. trust ( ) . txid ( ) , htlc_outputs. clone ( ) , commitment_tx. commitment_number ( ) , commitment_tx. per_commitment_point ( ) , logger)
3441
+ ChannelMonitorUpdateStep :: LatestHolderCommitmentTXs { htlc_data, commitment_txs, claimed_htlcs } => {
3442
+ log_trace ! ( logger, "Updating ChannelMonitor with latest holder commitment transaction(s)" ) ;
3443
+ if self . lockdown_from_offchain { panic ! ( ) ; }
3444
+ self . provide_latest_holder_commitment_data ( htlc_data. clone ( ) , commitment_txs. clone ( ) , claimed_htlcs)
3445
+ }
3446
+ ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXs { htlc_data, commitment_txs } => {
3447
+ log_trace ! ( logger, "Updating ChannelMonitor with latest counterparty commitment transaction(s)" ) ;
3448
+ self . provide_latest_counterparty_commitment_data ( htlc_data. clone ( ) , commitment_txs, logger)
3405
3449
} ,
3406
3450
ChannelMonitorUpdateStep :: PaymentPreimage { payment_preimage, payment_info } => {
3407
3451
log_trace ! ( logger, "Updating ChannelMonitor with payment preimage" ) ;
@@ -3465,7 +3509,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3465
3509
match update {
3466
3510
ChannelMonitorUpdateStep :: LatestHolderCommitmentTXInfo { .. }
3467
3511
|ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { .. }
3468
- |ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTX { .. }
3512
+ |ChannelMonitorUpdateStep :: LatestHolderCommitmentTXs { .. }
3513
+ |ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXs { .. }
3469
3514
|ChannelMonitorUpdateStep :: ShutdownScript { .. }
3470
3515
|ChannelMonitorUpdateStep :: CommitmentSecret { .. } =>
3471
3516
is_pre_close_update = true ,
@@ -3620,7 +3665,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3620
3665
update. updates . iter ( ) . filter_map ( |update| {
3621
3666
// Soon we will drop the first branch here in favor of the second.
3622
3667
// In preparation, we just add the second branch without deleting the first.
3623
- // Next step: in channel, switch channel monitor updates to use the `LatestCounterpartyCommitmentTX ` variant.
3668
+ // Next step: in channel, switch channel monitor updates to use the `LatestCounterpartyCommitmentTXs ` variant.
3624
3669
match update {
3625
3670
& ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { commitment_txid,
3626
3671
ref htlc_outputs, commitment_number, their_per_commitment_point,
@@ -3638,16 +3683,16 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3638
3683
3639
3684
debug_assert_eq ! ( commitment_tx. trust( ) . txid( ) , commitment_txid) ;
3640
3685
3641
- Some ( commitment_tx)
3686
+ Some ( vec ! [ commitment_tx] )
3642
3687
} ,
3643
- & ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTX {
3644
- htlc_outputs : _, ref commitment_tx ,
3688
+ & ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXs {
3689
+ htlc_data : _, ref commitment_txs ,
3645
3690
} => {
3646
- Some ( commitment_tx . clone ( ) )
3691
+ Some ( commitment_txs . clone ( ) )
3647
3692
} ,
3648
3693
_ => None ,
3649
3694
}
3650
- } ) . collect ( )
3695
+ } ) . flatten ( ) . collect ( )
3651
3696
}
3652
3697
3653
3698
fn sign_to_local_justice_tx (
0 commit comments