@@ -912,6 +912,12 @@ pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
912
912
/// Ordering of tuple data: (their_per_commitment_point, feerate_per_kw, to_broadcaster_sats,
913
913
/// to_countersignatory_sats)
914
914
initial_counterparty_commitment_info : Option < ( PublicKey , u32 , u64 , u64 ) > ,
915
+
916
+ /// In-memory only HTLC ids used to track upstream HTLCs that have been failed backwards due to
917
+ /// a downstream channel force-close remaining unconfirmed by the time the upstream timeout
918
+ /// expires. This is used to tell us we already generated an event to fail this HTLC back
919
+ /// during a previous block scan.
920
+ failed_back_htlc_ids : Vec < u64 > ,
915
921
}
916
922
917
923
/// Transaction outputs to watch for on-chain spends.
@@ -1254,6 +1260,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
1254
1260
best_block,
1255
1261
counterparty_node_id : Some ( counterparty_node_id) ,
1256
1262
initial_counterparty_commitment_info : None ,
1263
+ failed_back_htlc_ids : Vec :: new ( ) ,
1257
1264
} )
1258
1265
}
1259
1266
@@ -3537,8 +3544,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3537
3544
Some ( source) => source,
3538
3545
None => continue ,
3539
3546
} ;
3540
- let cltv_expiry = match source {
3541
- HTLCSource :: PreviousHopData ( HTLCPreviousHopData { cltv_expiry: Some ( cltv_expiry) , .. } ) => * cltv_expiry,
3547
+ let ( cltv_expiry, htlc_id ) = match source {
3548
+ HTLCSource :: PreviousHopData ( HTLCPreviousHopData { htlc_id , cltv_expiry: Some ( cltv_expiry) , .. } ) if ! self . failed_back_htlc_ids . contains ( htlc_id ) => ( * cltv_expiry, * htlc_id ) ,
3542
3549
_ => continue ,
3543
3550
} ;
3544
3551
if cltv_expiry <= height + TIMEOUT_FAIL_BACK_BUFFER {
@@ -3557,6 +3564,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3557
3564
htlc_value_satoshis: Some ( htlc. amount_msat / 1000 ) ,
3558
3565
awaiting_downstream_confirmation: true ,
3559
3566
} ) ) ;
3567
+ self . failed_back_htlc_ids. push( htlc_id) ;
3560
3568
}
3561
3569
}
3562
3570
}
@@ -4459,6 +4467,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
4459
4467
best_block,
4460
4468
counterparty_node_id,
4461
4469
initial_counterparty_commitment_info,
4470
+ failed_back_htlc_ids : Vec :: new ( ) ,
4462
4471
} ) ) )
4463
4472
}
4464
4473
}
0 commit comments