@@ -317,31 +317,30 @@ impl HolderCommitment {
317
317
let delayed_payment_key = & tx_keys. broadcaster_delayed_payment_key ;
318
318
let per_commitment_point = & tx_keys. per_commitment_point ;
319
319
320
- let mut nondust_htlcs = self . tx . nondust_htlcs ( ) . iter ( ) . zip ( self . tx . counterparty_htlc_sigs . iter ( ) ) ;
321
- let mut sources = self . nondust_htlc_sources . iter ( ) ;
322
-
323
- // Use an iterator to write `htlc_outputs` to avoid allocations.
324
- let nondust_htlcs = core:: iter:: from_fn ( move || {
325
- let ( htlc, counterparty_htlc_sig) = if let Some ( nondust_htlc) = nondust_htlcs. next ( ) {
326
- nondust_htlc
327
- } else {
328
- debug_assert ! ( sources. next( ) . is_none( ) ) ;
329
- return None ;
330
- } ;
320
+ debug_assert ! (
321
+ self . htlcs. iter( ) . map( |( htlc, _) | htlc) . zip( self . tx. nondust_htlcs( ) . iter( ) )
322
+ . all( |( htlc_a, htlc_b) | htlc_a == htlc_b)
323
+ ) ;
331
324
332
- let mut source = None ;
333
- if htlc. offered {
334
- source = sources. next ( ) ;
335
- if source. is_none ( ) {
336
- panic ! ( "Every offered non-dust HTLC should have a corresponding source" ) ;
325
+ let mut htlcs = self . htlcs . iter ( ) ;
326
+ let mut counterparty_htlc_sigs = self . tx . counterparty_htlc_sigs . iter ( ) ;
327
+ let htlc_outputs = core:: iter:: from_fn ( move || {
328
+ if let Some ( ( htlc, source) ) = htlcs. next ( ) {
329
+ let mut counterparty_htlc_sig = None ;
330
+ if htlc. transaction_output_index . is_some ( ) {
331
+ counterparty_htlc_sig = Some ( counterparty_htlc_sigs. next ( )
332
+ . expect ( "Every non-dust HTLC must have a counterparty signature" ) ) ;
333
+ } else {
334
+ // Once we see a dust HTLC, we should not expect to see any non-dust ones.
335
+ debug_assert ! ( counterparty_htlc_sigs. next( ) . is_none( ) ) ;
337
336
}
337
+ Some ( ( htlc, counterparty_htlc_sig, source. as_ref ( ) ) )
338
+ } else {
339
+ debug_assert ! ( counterparty_htlc_sigs. next( ) . is_none( ) ) ;
340
+ None
338
341
}
339
- Some ( ( htlc, Some ( counterparty_htlc_sig) , source) )
340
342
} ) ;
341
-
342
- // Dust HTLCs go last.
343
- let dust_htlcs = self . dust_htlcs . iter ( ) . map ( |( htlc, source) | ( htlc, None :: < & Signature > , source. as_ref ( ) ) ) ;
344
- let htlc_outputs = crate :: util:: ser:: IterableOwned ( nondust_htlcs. chain ( dust_htlcs) ) ;
343
+ let htlc_outputs = crate :: util:: ser:: IterableOwned ( htlc_outputs) ;
345
344
346
345
write_tlv_fields ! ( writer, {
347
346
( 0 , txid, required) ,
@@ -572,15 +571,11 @@ pub(crate) enum ChannelMonitorUpdateStep {
572
571
// Update LatestHolderCommitmentTXInfo in channel.rs if adding new fields to this variant.
573
572
LatestHolderCommitmentTXInfo {
574
573
commitment_tx : HolderCommitmentTransaction ,
575
- /// Note that LDK after 0.0.115 supports this only containing dust HTLCs (implying the
576
- /// `Signature` field is never filled in). At that point, non-dust HTLCs are implied by the
577
- /// HTLC fields in `commitment_tx` and the sources passed via `nondust_htlc_sources`.
578
- /// Starting with 0.2, the non-dust HTLC sources will always be provided separately, and
579
- /// `htlc_outputs` will only include dust HTLCs. We still have to track the
580
- /// `Option<Signature>` for backwards compatibility.
574
+ // Includes both dust and non-dust HTLCs. The `Option<Signature>` must be `Some` for
575
+ // non-dust HTLCs due to backwards compatibility, even though they are already tracked
576
+ // within the `HolderCommitmentTransaction` above.
581
577
htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < Signature > , Option < HTLCSource > ) > ,
582
578
claimed_htlcs : Vec < ( SentHTLCId , PaymentPreimage ) > ,
583
- nondust_htlc_sources : Vec < HTLCSource > ,
584
579
} ,
585
580
LatestCounterpartyCommitmentTXInfo {
586
581
commitment_txid : Txid ,
@@ -638,7 +633,6 @@ impl_writeable_tlv_based_enum_upgradable!(ChannelMonitorUpdateStep,
638
633
( 0 , commitment_tx, required) ,
639
634
( 1 , claimed_htlcs, optional_vec) ,
640
635
( 2 , htlc_outputs, required_vec) ,
641
- ( 4 , nondust_htlc_sources, optional_vec) ,
642
636
} ,
643
637
( 1 , LatestCounterpartyCommitmentTXInfo ) => {
644
638
( 0 , commitment_txid, required) ,
@@ -920,74 +914,34 @@ impl<Signer: EcdsaChannelSigner> Clone for ChannelMonitor<Signer> where Signer:
920
914
#[ derive( Clone , PartialEq ) ]
921
915
struct HolderCommitment {
922
916
tx : HolderCommitmentTransaction ,
923
- // These must be sorted in increasing output index order to match the expected order of the
924
- // HTLCs in the `CommitmentTransaction`.
925
- nondust_htlc_sources : Vec < HTLCSource > ,
926
- dust_htlcs : Vec < ( HTLCOutputInCommitment , Option < HTLCSource > ) > ,
917
+ htlcs : Vec < ( HTLCOutputInCommitment , Option < HTLCSource > ) > ,
927
918
}
928
919
929
920
impl TryFrom < ( HolderCommitmentTransaction , HolderSignedTx ) > for HolderCommitment {
930
921
type Error = ( ) ;
931
922
fn try_from ( value : ( HolderCommitmentTransaction , HolderSignedTx ) ) -> Result < Self , Self :: Error > {
932
923
let holder_commitment_tx = value. 0 ;
933
924
let holder_signed_tx = value. 1 ;
934
-
935
- // HolderSignedTx tracks all HTLCs included in the commitment (dust included). For
936
- // `HolderCommitment`, we'll need to extract the dust HTLCs and their sources, and non-dust
937
- // HTLC sources, separately. All offered, non-dust HTLCs must have a source available.
938
-
939
- let mut missing_nondust_source = false ;
940
- let mut nondust_htlc_sources = Vec :: with_capacity ( holder_commitment_tx. nondust_htlcs ( ) . len ( ) ) ;
941
- let dust_htlcs = holder_signed_tx. htlc_outputs . into_iter ( ) . filter_map ( |( htlc, _, source) | {
942
- // Filter our non-dust HTLCs, while at the same time pushing their sources into
943
- // `nondust_htlc_sources`.
944
- if htlc. transaction_output_index . is_none ( ) {
945
- return Some ( ( htlc, source) )
946
- }
947
- if htlc. offered {
948
- if let Some ( source) = source {
949
- nondust_htlc_sources. push ( source) ;
950
- } else {
951
- missing_nondust_source = true ;
952
- }
953
- }
954
- None
955
- } ) . collect ( ) ;
956
- if missing_nondust_source {
957
- return Err ( ( ) ) ;
958
- }
959
-
960
925
Ok ( Self {
961
926
tx : holder_commitment_tx,
962
- nondust_htlc_sources,
963
- dust_htlcs,
927
+ htlcs : holder_signed_tx. htlc_outputs . into_iter ( )
928
+ . map ( |( htlc, _, source) | ( htlc, source) )
929
+ . collect ( ) ,
964
930
} )
965
931
}
966
932
}
967
933
968
934
impl HolderCommitment {
969
935
fn has_htlcs ( & self ) -> bool {
970
- self . tx . nondust_htlcs ( ) . len ( ) > 0 || self . dust_htlcs . len ( ) > 0
936
+ ! self . htlcs . is_empty ( )
971
937
}
972
938
973
939
fn htlcs ( & self ) -> impl Iterator < Item = & HTLCOutputInCommitment > {
974
- self . tx . nondust_htlcs ( ) . iter ( ) . chain ( self . dust_htlcs . iter ( ) . map ( |( htlc, _) | htlc) )
940
+ self . htlcs . iter ( ) . map ( |( htlc, _) | htlc)
975
941
}
976
942
977
943
fn htlcs_with_sources ( & self ) -> impl Iterator < Item = ( & HTLCOutputInCommitment , Option < & HTLCSource > ) > {
978
- let mut sources = self . nondust_htlc_sources . iter ( ) ;
979
- let nondust_htlcs = self . tx . nondust_htlcs ( ) . iter ( ) . map ( move |htlc| {
980
- let mut source = None ;
981
- if htlc. offered && htlc. transaction_output_index . is_some ( ) {
982
- source = sources. next ( ) ;
983
- if source. is_none ( ) {
984
- panic ! ( "Every offered non-dust HTLC should have a corresponding source" ) ;
985
- }
986
- }
987
- ( htlc, source)
988
- } ) ;
989
- let dust_htlcs = self . dust_htlcs . iter ( ) . map ( |( htlc, source) | ( htlc, source. as_ref ( ) ) ) ;
990
- nondust_htlcs. chain ( dust_htlcs)
944
+ self . htlcs . iter ( ) . map ( |( htlc, source) | ( htlc, source. as_ref ( ) ) )
991
945
}
992
946
}
993
947
@@ -1554,8 +1508,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1554
1508
current_holder_commitment : HolderCommitment {
1555
1509
tx : initial_holder_commitment_tx,
1556
1510
// There are never any HTLCs in the initial commitment transactions
1557
- nondust_htlc_sources : Vec :: new ( ) ,
1558
- dust_htlcs : Vec :: new ( ) ,
1511
+ htlcs : Vec :: new ( ) ,
1559
1512
} ,
1560
1513
prev_holder_commitment : None ,
1561
1514
} ,
@@ -1680,7 +1633,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1680
1633
& self , holder_commitment_tx : HolderCommitmentTransaction ,
1681
1634
htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < Signature > , Option < HTLCSource > ) > ,
1682
1635
) {
1683
- self . inner . lock ( ) . unwrap ( ) . provide_latest_holder_commitment_tx ( holder_commitment_tx, htlc_outputs, & Vec :: new ( ) , Vec :: new ( ) )
1636
+ self . inner . lock ( ) . unwrap ( ) . provide_latest_holder_commitment_tx ( holder_commitment_tx, htlc_outputs, & Vec :: new ( ) )
1684
1637
}
1685
1638
1686
1639
/// This is used to provide payment preimage(s) out-of-band during startup without updating the
@@ -3092,72 +3045,13 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3092
3045
fn provide_latest_holder_commitment_tx (
3093
3046
& mut self , holder_commitment_tx : HolderCommitmentTransaction ,
3094
3047
htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < Signature > , Option < HTLCSource > ) > ,
3095
- claimed_htlcs : & [ ( SentHTLCId , PaymentPreimage ) ] , mut nondust_htlc_sources : Vec < HTLCSource > ,
3048
+ claimed_htlcs : & [ ( SentHTLCId , PaymentPreimage ) ] ,
3096
3049
) {
3097
- let dust_htlcs: Vec < _ > = if htlc_outputs. iter ( ) . any ( |( _, s, _) | s. is_some ( ) ) {
3098
- // If we have non-dust HTLCs in htlc_outputs, ensure they match the HTLCs in the
3099
- // `holder_commitment_tx`. In the future, we'll no longer provide the redundant data
3100
- // and just pass in source data via `nondust_htlc_sources`.
3101
- debug_assert_eq ! ( htlc_outputs. iter( ) . filter( |( _, s, _) | s. is_some( ) ) . count( ) , holder_commitment_tx. trust( ) . nondust_htlcs( ) . len( ) ) ;
3102
- for ( a, b) in htlc_outputs. iter ( ) . filter ( |( _, s, _) | s. is_some ( ) ) . map ( |( h, _, _) | h) . zip ( holder_commitment_tx. trust ( ) . nondust_htlcs ( ) . iter ( ) ) {
3103
- debug_assert_eq ! ( a, b) ;
3104
- }
3105
- debug_assert_eq ! ( htlc_outputs. iter( ) . filter( |( _, s, _) | s. is_some( ) ) . count( ) , holder_commitment_tx. counterparty_htlc_sigs. len( ) ) ;
3106
- for ( a, b) in htlc_outputs. iter ( ) . filter_map ( |( _, s, _) | s. as_ref ( ) ) . zip ( holder_commitment_tx. counterparty_htlc_sigs . iter ( ) ) {
3107
- debug_assert_eq ! ( a, b) ;
3108
- }
3109
-
3110
- // Backfill the non-dust HTLC sources.
3111
- debug_assert ! ( nondust_htlc_sources. is_empty( ) ) ;
3112
- nondust_htlc_sources. reserve_exact ( holder_commitment_tx. nondust_htlcs ( ) . len ( ) ) ;
3113
- let dust_htlcs = htlc_outputs. into_iter ( ) . filter_map ( |( htlc, _, source) | {
3114
- // Filter our non-dust HTLCs, while at the same time pushing their sources into
3115
- // `nondust_htlc_sources`.
3116
- if htlc. transaction_output_index . is_none ( ) {
3117
- return Some ( ( htlc, source) ) ;
3118
- }
3119
- if htlc. offered {
3120
- nondust_htlc_sources. push ( source. expect ( "Outbound HTLCs should have a source" ) ) ;
3121
- }
3122
- None
3123
- } ) . collect ( ) ;
3124
-
3125
- dust_htlcs
3126
- } else {
3127
- // If we don't have any non-dust HTLCs in htlc_outputs, assume they were all passed via
3128
- // `nondust_htlc_sources`, building up the final htlc_outputs by combining
3129
- // `nondust_htlc_sources` and the `holder_commitment_tx`
3130
- {
3131
- let mut prev = -1 ;
3132
- for htlc in holder_commitment_tx. trust ( ) . nondust_htlcs ( ) . iter ( ) {
3133
- assert ! ( htlc. transaction_output_index. unwrap( ) as i32 > prev) ;
3134
- prev = htlc. transaction_output_index . unwrap ( ) as i32 ;
3135
- }
3136
- }
3137
-
3138
- debug_assert ! ( htlc_outputs. iter( ) . all( |( htlc, _, _) | htlc. transaction_output_index. is_none( ) ) ) ;
3139
- debug_assert ! ( htlc_outputs. iter( ) . all( |( _, sig_opt, _) | sig_opt. is_none( ) ) ) ;
3140
- debug_assert_eq ! ( holder_commitment_tx. trust( ) . nondust_htlcs( ) . len( ) , holder_commitment_tx. counterparty_htlc_sigs. len( ) ) ;
3141
-
3142
- let mut sources = nondust_htlc_sources. iter ( ) ;
3143
- for htlc in holder_commitment_tx. trust ( ) . nondust_htlcs ( ) . iter ( ) {
3144
- if htlc. offered {
3145
- let source = sources. next ( ) . expect ( "Non-dust HTLC sources didn't match commitment tx" ) ;
3146
- assert ! ( source. possibly_matches_output( htlc) ) ;
3147
- }
3148
- }
3149
- assert ! ( sources. next( ) . is_none( ) , "All HTLC sources should have been exhausted" ) ;
3150
-
3151
- // This only includes dust HTLCs as checked above.
3152
- htlc_outputs. into_iter ( ) . map ( |( htlc, _, source) | ( htlc, source) ) . collect ( )
3153
- } ;
3154
-
3155
3050
self . current_holder_commitment_number = holder_commitment_tx. trust ( ) . commitment_number ( ) ;
3156
3051
self . onchain_tx_handler . provide_latest_holder_tx ( holder_commitment_tx. clone ( ) ) ;
3157
3052
let mut holder_commitment = HolderCommitment {
3158
3053
tx : holder_commitment_tx,
3159
- nondust_htlc_sources,
3160
- dust_htlcs,
3054
+ htlcs : htlc_outputs. into_iter ( ) . map ( |( htlc, _, source) | ( htlc, source) ) . collect ( ) ,
3161
3055
} ;
3162
3056
mem:: swap ( & mut holder_commitment, & mut self . funding . current_holder_commitment ) ;
3163
3057
self . funding . prev_holder_commitment = Some ( holder_commitment) ;
@@ -3387,10 +3281,10 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3387
3281
let bounded_fee_estimator = LowerBoundedFeeEstimator :: new ( & * * fee_estimator) ;
3388
3282
for update in updates. updates . iter ( ) {
3389
3283
match update {
3390
- ChannelMonitorUpdateStep :: LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs, claimed_htlcs, nondust_htlc_sources } => {
3284
+ ChannelMonitorUpdateStep :: LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs, claimed_htlcs } => {
3391
3285
log_trace ! ( logger, "Updating ChannelMonitor with latest holder commitment transaction info" ) ;
3392
3286
if self . lockdown_from_offchain { panic ! ( ) ; }
3393
- self . provide_latest_holder_commitment_tx ( commitment_tx. clone ( ) , htlc_outputs. clone ( ) , & claimed_htlcs, nondust_htlc_sources . clone ( ) ) ;
3287
+ self . provide_latest_holder_commitment_tx ( commitment_tx. clone ( ) , htlc_outputs. clone ( ) , & claimed_htlcs) ;
3394
3288
}
3395
3289
// Soon we will drop the `LatestCounterpartyCommitmentTXInfo` variant in favor of `LatestCounterpartyCommitmentTX`.
3396
3290
// For now we just add the code to handle the new updates.
0 commit comments