@@ -6962,7 +6962,16 @@ where
69626962 UpdateFulfillCommitFetch::DuplicateClaim {} => {
69636963 let (action_opt, raa_blocker_opt) = completion_action(None, true);
69646964 if let Some(raa_blocker) = raa_blocker_opt {
6965- debug_assert!(peer_state.actions_blocking_raa_monitor_updates.get(&chan_id).unwrap().contains(&raa_blocker));
6965+ // If we're making a claim during startup, its a replay of a
6966+ // payment claim from a `ChannelMonitor`. In some cases (MPP or
6967+ // if the HTLC was only recently removed) we make such claims
6968+ // after an HTLC has been removed from a channel entirely, and
6969+ // thus the RAA blocker has long since completed.
6970+ //
6971+ // In any other case, the RAA blocker must still be present and
6972+ // blocking RAAs.
6973+ debug_assert!(during_init ||
6974+ peer_state.actions_blocking_raa_monitor_updates.get(&chan_id).unwrap().contains(&raa_blocker));
69666975 }
69676976 let action = if let Some(action) = action_opt {
69686977 action
@@ -6974,38 +6983,41 @@ where
69746983
69756984 log_trace!(logger, "Completing monitor update completion action for channel {} as claim was redundant: {:?}",
69766985 chan_id, action);
6977- let (node_id, _funding_outpoint, channel_id, blocker) =
69786986 if let MonitorUpdateCompletionAction::FreeOtherChannelImmediately {
69796987 downstream_counterparty_node_id: node_id,
6980- downstream_funding_outpoint: funding_outpoint ,
6988+ downstream_funding_outpoint: _ ,
69816989 blocking_action: blocker, downstream_channel_id: channel_id,
69826990 } = action {
6983- (node_id, funding_outpoint, channel_id, blocker)
6991+ if let Some(peer_state_mtx) = per_peer_state.get(&node_id) {
6992+ let mut peer_state = peer_state_mtx.lock().unwrap();
6993+ if let Some(blockers) = peer_state
6994+ .actions_blocking_raa_monitor_updates
6995+ .get_mut(&channel_id)
6996+ {
6997+ let mut found_blocker = false;
6998+ blockers.retain(|iter| {
6999+ // Note that we could actually be blocked, in
7000+ // which case we need to only remove the one
7001+ // blocker which was added duplicatively.
7002+ let first_blocker = !found_blocker;
7003+ if *iter == blocker { found_blocker = true; }
7004+ *iter != blocker || !first_blocker
7005+ });
7006+ debug_assert!(found_blocker);
7007+ }
7008+ } else {
7009+ debug_assert!(false);
7010+ }
7011+ } else if matches!(action, MonitorUpdateCompletionAction::PaymentClaimed { .. }) {
7012+ debug_assert!(during_init,
7013+ "Duplicate claims should always either be for forwarded payments(freeing another channel immediately) or during init (for claim replay)");
7014+ mem::drop(per_peer_state);
7015+ self.handle_monitor_update_completion_actions([action]);
69847016 } else {
69857017 debug_assert!(false,
6986- "Duplicate claims should always free another channel immediately");
7018+ "Duplicate claims should always either be for forwarded payments(freeing another channel immediately) or during init (for claim replay) ");
69877019 return;
69887020 };
6989- if let Some(peer_state_mtx) = per_peer_state.get(&node_id) {
6990- let mut peer_state = peer_state_mtx.lock().unwrap();
6991- if let Some(blockers) = peer_state
6992- .actions_blocking_raa_monitor_updates
6993- .get_mut(&channel_id)
6994- {
6995- let mut found_blocker = false;
6996- blockers.retain(|iter| {
6997- // Note that we could actually be blocked, in
6998- // which case we need to only remove the one
6999- // blocker which was added duplicatively.
7000- let first_blocker = !found_blocker;
7001- if *iter == blocker { found_blocker = true; }
7002- *iter != blocker || !first_blocker
7003- });
7004- debug_assert!(found_blocker);
7005- }
7006- } else {
7007- debug_assert!(false);
7008- }
70097021 }
70107022 }
70117023 }
0 commit comments