Skip to content

Commit f1364ba

Browse files
committed
f: codex review
1 parent 25c9ca3 commit f1364ba

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

lightning/src/chain/chainmonitor.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,9 +1274,10 @@ where
12741274
///
12751275
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
12761276
pub fn flush(&self, count: usize, logger: &L) {
1277-
if count > 0 {
1278-
log_info!(logger, "Flushing up to {} monitor operations", count);
1277+
if count == 0 {
1278+
return;
12791279
}
1280+
log_info!(logger, "Flushing up to {} monitor operations", count);
12801281
for _ in 0..count {
12811282
let mut queue = self.pending_ops.lock().unwrap();
12821283
let op = match queue.pop_front() {
@@ -1334,6 +1335,10 @@ where
13341335
},
13351336
}
13361337
}
1338+
1339+
// A flushed monitor update may have generated new events, so assume we have
1340+
// some and wake the event processor.
1341+
self.event_notifier.notify();
13371342
}
13381343
}
13391344

lightning/src/chain/channelmonitor.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,8 +1378,8 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
13781378
/// In-memory only HTLC ids used to track upstream HTLCs that have been failed backwards due to
13791379
/// a downstream channel force-close remaining unconfirmed by the time the upstream timeout
13801380
/// expires. This is used to tell us we already generated an event to fail this HTLC back
1381-
/// during a previous block scan.
1382-
failed_back_htlc_ids: HashSet<SentHTLCId>,
1381+
/// during a previous block scan. Not serialized.
1382+
pub(crate) failed_back_htlc_ids: HashSet<SentHTLCId>,
13831383

13841384
// The auxiliary HTLC data associated with a holder commitment transaction. This includes
13851385
// non-dust HTLC sources, along with dust HTLCs and their sources. Note that this assumes any
@@ -4451,6 +4451,10 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
44514451
}
44524452
let htlc_value_satoshis = Some(amount_msat / 1000);
44534453
let logger = WithContext::from(logger, None, None, Some(payment_hash));
4454+
// Defensively mark the HTLC as failed back so the expiry-based failure
4455+
// path in `block_connected` doesn't generate a duplicate `HTLCUpdate`
4456+
// event for the same source.
4457+
self.failed_back_htlc_ids.insert(SentHTLCId::from_source(source));
44544458
if let Some(confirmed_txid) = self.funding_spend_confirmed {
44554459
// Funding spend already confirmed past ANTI_REORG_DELAY: resolve immediately.
44564460
log_trace!(

lightning/src/util/test_utils.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,12 +713,18 @@ impl<'a> chain::Watch<TestChannelSigner> for TestChainMonitor<'a> {
713713
)
714714
.unwrap()
715715
.1;
716+
// failed_back_htlc_ids is an in-memory-only dedup guard that is intentionally not
717+
// serialized. Copy it to the deserialized monitor for the comparison, then clear
718+
// it so it doesn't leak into the rest of the test.
719+
let failed_back = monitor.inner.lock().unwrap().failed_back_htlc_ids.clone();
720+
new_monitor.inner.lock().unwrap().failed_back_htlc_ids = failed_back;
716721
if let Some(chan_id) = self.expect_monitor_round_trip_fail.lock().unwrap().take() {
717722
assert_eq!(chan_id, channel_id);
718723
assert!(new_monitor != *monitor);
719724
} else {
720725
assert!(new_monitor == *monitor);
721726
}
727+
new_monitor.inner.lock().unwrap().failed_back_htlc_ids.clear();
722728
self.added_monitors.lock().unwrap().push((channel_id, new_monitor));
723729
update_res
724730
}

0 commit comments

Comments
 (0)