Skip to content

Commit fd70e58

Browse files
committed
f handle monitor to use not always being the last
1 parent c6305f3 commit fd70e58

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,13 +1910,15 @@ macro_rules! handle_new_monitor_update {
19101910
let update_id = $update.update_id;
19111911
let in_flight_updates = $peer_state.in_flight_monitor_updates.entry($funding_txo)
19121912
.or_insert_with(Vec::new);
1913-
if !in_flight_updates.contains(&$update) {
1914-
// During startup, we push monitor updates as background events through to here in
1915-
// order to replay updates that were in-flight when we shut down. Thus, we have to
1916-
// filter for uniqueness here.
1917-
in_flight_updates.push($update);
1918-
}
1919-
let update_res = $self.chain_monitor.update_channel($funding_txo, in_flight_updates.last().unwrap());
1913+
// During startup, we push monitor updates as background events through to here in
1914+
// order to replay updates that were in-flight when we shut down. Thus, we have to
1915+
// filter for uniqueness here.
1916+
let idx = in_flight_updates.iter().position(|upd| upd == &$update)
1917+
.unwrap_or_else(|| {
1918+
in_flight_updates.push($update);
1919+
in_flight_updates.len() - 1
1920+
});
1921+
let update_res = $self.chain_monitor.update_channel($funding_txo, &in_flight_updates[idx]);
19201922
handle_new_monitor_update!($self, update_res, $peer_state_lock, $peer_state,
19211923
$per_peer_state_lock, $chan, _internal, $remove,
19221924
{

0 commit comments

Comments
 (0)