@@ -891,6 +891,12 @@ pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
891
891
892
892
/// The node_id of our counterparty
893
893
counterparty_node_id : Option < PublicKey > ,
894
+
895
+ /// In-memory only HTLC ids used to track upstream HTLCs that have been failed backwards due to
896
+ /// a downstream channel force-close remaining unconfirmed by the time the upstream timeout
897
+ /// expires. This is used to tell us we already generated an event to fail this HTLC back
898
+ /// during a previous block scan.
899
+ failed_back_htlc_ids : Vec < u64 > ,
894
900
}
895
901
896
902
/// Transaction outputs to watch for on-chain spends.
@@ -1231,6 +1237,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
1231
1237
1232
1238
best_block,
1233
1239
counterparty_node_id : Some ( counterparty_node_id) ,
1240
+ failed_back_htlc_ids : Vec :: new ( ) ,
1234
1241
} )
1235
1242
}
1236
1243
@@ -3325,8 +3332,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3325
3332
Some ( source) => source,
3326
3333
None => continue ,
3327
3334
} ;
3328
- let cltv_expiry = match source {
3329
- HTLCSource :: PreviousHopData ( HTLCPreviousHopData { cltv_expiry: Some ( cltv_expiry) , .. } ) => * cltv_expiry,
3335
+ let ( cltv_expiry, htlc_id ) = match source {
3336
+ HTLCSource :: PreviousHopData ( HTLCPreviousHopData { htlc_id , cltv_expiry: Some ( cltv_expiry) , .. } ) if ! self . failed_back_htlc_ids . contains ( htlc_id ) => ( * cltv_expiry, * htlc_id ) ,
3330
3337
_ => continue ,
3331
3338
} ;
3332
3339
if cltv_expiry <= height + TIMEOUT_FAIL_BACK_BUFFER {
@@ -3344,6 +3351,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3344
3351
payment_hash: htlc. payment_hash,
3345
3352
htlc_value_satoshis: Some ( htlc. amount_msat / 1000 ) ,
3346
3353
} ) ) ;
3354
+ self . failed_back_htlc_ids. push( htlc_id) ;
3347
3355
}
3348
3356
}
3349
3357
}
@@ -4243,6 +4251,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
4243
4251
4244
4252
best_block,
4245
4253
counterparty_node_id,
4254
+ failed_back_htlc_ids : Vec :: new ( ) ,
4246
4255
} ) ) )
4247
4256
}
4248
4257
}
0 commit comments