Skip to content

Commit ee5f741

Browse files
committed
f - prevent queueing events every new block
1 parent c7519b4 commit ee5f741

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,12 @@ pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
912912
/// Ordering of tuple data: (their_per_commitment_point, feerate_per_kw, to_broadcaster_sats,
913913
/// to_countersignatory_sats)
914914
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>,
915921
}
916922

917923
/// Transaction outputs to watch for on-chain spends.
@@ -1254,6 +1260,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
12541260
best_block,
12551261
counterparty_node_id: Some(counterparty_node_id),
12561262
initial_counterparty_commitment_info: None,
1263+
failed_back_htlc_ids: Vec::new(),
12571264
})
12581265
}
12591266

@@ -3537,8 +3544,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
35373544
Some(source) => source,
35383545
None => continue,
35393546
};
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),
35423549
_ => continue,
35433550
};
35443551
if cltv_expiry <= height + TIMEOUT_FAIL_BACK_BUFFER {
@@ -3557,6 +3564,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
35573564
htlc_value_satoshis: Some(htlc.amount_msat / 1000),
35583565
awaiting_downstream_confirmation: true,
35593566
}));
3567+
self.failed_back_htlc_ids.push(htlc_id);
35603568
}
35613569
}
35623570
}
@@ -4459,6 +4467,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
44594467
best_block,
44604468
counterparty_node_id,
44614469
initial_counterparty_commitment_info,
4470+
failed_back_htlc_ids: Vec::new(),
44624471
})))
44634472
}
44644473
}

0 commit comments

Comments
 (0)