Skip to content

Commit f35e75c

Browse files
committed
f - prevent queueing events every new block
1 parent 54611fe commit f35e75c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lightning/src/chain/channelmonitor.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,12 @@ pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
891891

892892
/// The node_id of our counterparty
893893
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>,
894900
}
895901

896902
/// Transaction outputs to watch for on-chain spends.
@@ -1231,6 +1237,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
12311237

12321238
best_block,
12331239
counterparty_node_id: Some(counterparty_node_id),
1240+
failed_back_htlc_ids: Vec::new(),
12341241
})
12351242
}
12361243

@@ -3325,8 +3332,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
33253332
Some(source) => source,
33263333
None => continue,
33273334
};
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),
33303337
_ => continue,
33313338
};
33323339
if cltv_expiry <= height + TIMEOUT_FAIL_BACK_BUFFER {
@@ -3344,6 +3351,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
33443351
payment_hash: htlc.payment_hash,
33453352
htlc_value_satoshis: Some(htlc.amount_msat / 1000),
33463353
}));
3354+
self.failed_back_htlc_ids.push(htlc_id);
33473355
}
33483356
}
33493357
}
@@ -4243,6 +4251,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
42434251

42444252
best_block,
42454253
counterparty_node_id,
4254+
failed_back_htlc_ids: Vec::new(),
42464255
})))
42474256
}
42484257
}

lightning/src/ln/channelmanager.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub(super) enum HTLCForwardInfo {
192192
pub(crate) struct HTLCPreviousHopData {
193193
// Note that this may be an outbound SCID alias for the associated channel.
194194
short_channel_id: u64,
195-
htlc_id: u64,
195+
pub(crate) htlc_id: u64,
196196
incoming_packet_shared_secret: [u8; 32],
197197
phantom_shared_secret: Option<[u8; 32]>,
198198

0 commit comments

Comments
 (0)