@@ -38,7 +38,7 @@ use crate::types::features::ChannelTypeFeatures;
3838use crate :: types:: payment:: { PaymentHash , PaymentPreimage } ;
3939use crate :: ln:: msgs:: DecodeError ;
4040use 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 } ;
4242use crate :: ln:: channelmanager:: { HTLCSource , SentHTLCId , PaymentClaimDetails } ;
4343use crate :: chain;
4444use crate :: chain:: { BestBlock , WatchedOutput } ;
@@ -591,11 +591,16 @@ pub(crate) enum ChannelMonitorUpdateStep {
591591 to_broadcaster_value_sat : Option < u64 > ,
592592 to_countersignatory_value_sat : Option < u64 > ,
593593 } ,
594- LatestCounterpartyCommitmentTX {
594+ LatestHolderCommitmentTXs {
595+ htlc_data : Vec < ( HTLCOutputData , Option < HTLCSource > ) > ,
596+ commitment_txs : Vec < HolderCommitmentTransaction > ,
597+ claimed_htlcs : Vec < ( SentHTLCId , PaymentPreimage ) > ,
598+ } ,
599+ LatestCounterpartyCommitmentTXs {
595600 // The dust and non-dust htlcs for that commitment
596- htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < Box < HTLCSource > > ) > ,
601+ htlc_data : Vec < ( HTLCOutputData , Option < Box < HTLCSource > > ) > ,
597602 // Contains only the non-dust htlcs
598- commitment_tx : CommitmentTransaction ,
603+ commitment_txs : Vec < CommitmentTransaction > ,
599604 } ,
600605 PaymentPreimage {
601606 payment_preimage : PaymentPreimage ,
@@ -624,7 +629,8 @@ impl ChannelMonitorUpdateStep {
624629 match self {
625630 ChannelMonitorUpdateStep :: LatestHolderCommitmentTXInfo { .. } => "LatestHolderCommitmentTXInfo" ,
626631 ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { .. } => "LatestCounterpartyCommitmentTXInfo" ,
627- ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTX { .. } => "LatestCounterpartyCommitmentTX" ,
632+ ChannelMonitorUpdateStep :: LatestHolderCommitmentTXs { .. } => "LatestHolderCommitmentTXs" ,
633+ ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXs { .. } => "LatestCounterpartyCommitmentTXs" ,
628634 ChannelMonitorUpdateStep :: PaymentPreimage { .. } => "PaymentPreimage" ,
629635 ChannelMonitorUpdateStep :: CommitmentSecret { .. } => "CommitmentSecret" ,
630636 ChannelMonitorUpdateStep :: ChannelForceClosed { .. } => "ChannelForceClosed" ,
@@ -663,9 +669,14 @@ impl_writeable_tlv_based_enum_upgradable!(ChannelMonitorUpdateStep,
663669 ( 5 , ShutdownScript ) => {
664670 ( 0 , scriptpubkey, required) ,
665671 } ,
666- ( 6 , LatestCounterpartyCommitmentTX ) => {
667- ( 0 , htlc_outputs, required_vec) ,
668- ( 2 , commitment_tx, required) ,
672+ ( 6 , LatestHolderCommitmentTXs ) => {
673+ ( 0 , htlc_data, required_vec) ,
674+ ( 2 , commitment_txs, required_vec) ,
675+ ( 4 , claimed_htlcs, required_vec) ,
676+ } ,
677+ ( 7 , LatestCounterpartyCommitmentTXs ) => {
678+ ( 0 , htlc_data, required_vec) ,
679+ ( 2 , commitment_txs, required_vec) ,
669680 } ,
670681) ;
671682
@@ -3084,6 +3095,19 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
30843095 }
30853096 }
30863097
3098+ // This is the sibling of `provide_latest_counterparty_commitment_tx`, but updated for a world
3099+ // in which the HTLC-source table passed from channel does NOT store dust-vs-nondust and
3100+ // index HTLC data.
3101+ fn provide_latest_counterparty_commitment_data < L : Deref > (
3102+ & mut self ,
3103+ _htlc_data : Vec < ( HTLCOutputData , Option < Box < HTLCSource > > ) > ,
3104+ _txs : & Vec < CommitmentTransaction > ,
3105+ _logger : & WithChannelMonitor < L > ,
3106+ ) where L :: Target : Logger {
3107+ // TODO(splicing, 0.2): Populate this monitor's data structures
3108+ todo ! ( ) ;
3109+ }
3110+
30873111 /// Informs this monitor of the latest holder (ie broadcastable) commitment transaction. The
30883112 /// monitor watches for timeouts and may broadcast it if we approach such a timeout. Thus, it
30893113 /// is important that any clones of this channel monitor (including remote clones) by kept
@@ -3175,6 +3199,19 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
31753199 }
31763200 }
31773201
3202+ // This is the sibling of `provide_latest_holder_commitment_tx`, but updated for a world
3203+ // in which the HTLC-source table passed from channel does NOT store dust-vs-nondust and
3204+ // index HTLC data.
3205+ fn provide_latest_holder_commitment_data (
3206+ & mut self ,
3207+ _htlc_data : Vec < ( HTLCOutputData , Option < HTLCSource > ) > ,
3208+ _holder_commitment_txs : Vec < HolderCommitmentTransaction > ,
3209+ _claimed_htlcs : & [ ( SentHTLCId , PaymentPreimage ) ] ,
3210+ ) {
3211+ // TODO(splicing, 0.2): Populate this monitor's data structures
3212+ todo ! ( ) ;
3213+ }
3214+
31783215 /// Provides a payment_hash->payment_preimage mapping. Will be automatically pruned when all
31793216 /// commitment_tx_infos which contain the payment hash have been revoked.
31803217 ///
@@ -3392,16 +3429,21 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
33923429 if self . lockdown_from_offchain { panic ! ( ) ; }
33933430 self . provide_latest_holder_commitment_tx ( commitment_tx. clone ( ) , htlc_outputs. clone ( ) , & claimed_htlcs, nondust_htlc_sources. clone ( ) ) ;
33943431 }
3395- // Soon we will drop the `LatestCounterpartyCommitmentTXInfo` variant in favor of `LatestCounterpartyCommitmentTX `.
3432+ // Soon we will drop the `LatestCounterpartyCommitmentTXInfo` variant in favor of `LatestCounterpartyCommitmentTXs `.
33963433 // 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.
3434+ // Next step: in channel, switch channel monitor updates to use the `LatestCounterpartyCommitmentTXs ` variant.
33983435 ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { commitment_txid, htlc_outputs, commitment_number, their_per_commitment_point, .. } => {
33993436 log_trace ! ( logger, "Updating ChannelMonitor with latest counterparty commitment transaction info" ) ;
34003437 self . provide_latest_counterparty_commitment_tx ( * commitment_txid, htlc_outputs. clone ( ) , * commitment_number, * their_per_commitment_point, logger)
34013438 } ,
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)
3439+ ChannelMonitorUpdateStep :: LatestHolderCommitmentTXs { htlc_data, commitment_txs, claimed_htlcs } => {
3440+ log_trace ! ( logger, "Updating ChannelMonitor with latest holder commitment transaction(s)" ) ;
3441+ if self . lockdown_from_offchain { panic ! ( ) ; }
3442+ self . provide_latest_holder_commitment_data ( htlc_data. clone ( ) , commitment_txs. clone ( ) , claimed_htlcs)
3443+ }
3444+ ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXs { htlc_data, commitment_txs } => {
3445+ log_trace ! ( logger, "Updating ChannelMonitor with latest counterparty commitment transaction(s)" ) ;
3446+ self . provide_latest_counterparty_commitment_data ( htlc_data. clone ( ) , commitment_txs, logger)
34053447 } ,
34063448 ChannelMonitorUpdateStep :: PaymentPreimage { payment_preimage, payment_info } => {
34073449 log_trace ! ( logger, "Updating ChannelMonitor with payment preimage" ) ;
@@ -3465,7 +3507,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
34653507 match update {
34663508 ChannelMonitorUpdateStep :: LatestHolderCommitmentTXInfo { .. }
34673509 |ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { .. }
3468- |ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTX { .. }
3510+ |ChannelMonitorUpdateStep :: LatestHolderCommitmentTXs { .. }
3511+ |ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXs { .. }
34693512 |ChannelMonitorUpdateStep :: ShutdownScript { .. }
34703513 |ChannelMonitorUpdateStep :: CommitmentSecret { .. } =>
34713514 is_pre_close_update = true ,
@@ -3620,7 +3663,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
36203663 update. updates . iter ( ) . filter_map ( |update| {
36213664 // Soon we will drop the first branch here in favor of the second.
36223665 // 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.
3666+ // Next step: in channel, switch channel monitor updates to use the `LatestCounterpartyCommitmentTXs ` variant.
36243667 match update {
36253668 & ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { commitment_txid,
36263669 ref htlc_outputs, commitment_number, their_per_commitment_point,
@@ -3638,16 +3681,16 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
36383681
36393682 debug_assert_eq ! ( commitment_tx. trust( ) . txid( ) , commitment_txid) ;
36403683
3641- Some ( commitment_tx)
3684+ Some ( vec ! [ commitment_tx] )
36423685 } ,
3643- & ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTX {
3644- htlc_outputs : _, ref commitment_tx ,
3686+ & ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXs {
3687+ htlc_data : _, ref commitment_txs ,
36453688 } => {
3646- Some ( commitment_tx . clone ( ) )
3689+ Some ( commitment_txs . clone ( ) )
36473690 } ,
36483691 _ => None ,
36493692 }
3650- } ) . collect ( )
3693+ } ) . flatten ( ) . collect ( )
36513694 }
36523695
36533696 fn sign_to_local_justice_tx (
0 commit comments