Skip to content

Commit 140b76f

Browse files
committed
Always require a PeerState for the CP when claiming an HTLC
Now that we track the latest `ChannelMonitorUpdate::update_id` for each closed channel in `PeerState::closed_channel_monitor_update_ids`, we should always have a `PeerState` entry for the channel counterparty any time we go to claim an HTLC on a channel, even if its closed. Here we make this a hard assertion as we'll need to access that `PeerState` in the coming commits to track in-flight updates against closed channels.
1 parent b96b19a commit 140b76f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7089,10 +7089,14 @@ where
70897089
let per_peer_state = self.per_peer_state.read().unwrap();
70907090
let chan_id = prev_hop.channel_id;
70917091

7092+
const MISSING_MON_ERROR: &'static str =
7093+
"If we're going to claim an HTLC against a channel, we should always have *some* state for the channel, even if just the latest ChannelMonitor update_id. This failure indicates we need to claim an HTLC from a channel for which we did not have a ChannelMonitor at startup and didn't create one while running.";
7094+
70927095
let peer_state_opt = prev_hop.counterparty_node_id.as_ref().map(
70937096
|counterparty_node_id| per_peer_state.get(counterparty_node_id)
70947097
.map(|peer_mutex| peer_mutex.lock().unwrap())
7095-
).unwrap_or(None);
7098+
.expect(MISSING_MON_ERROR)
7099+
);
70967100

70977101
if peer_state_opt.is_some() {
70987102
let mut peer_state_lock = peer_state_opt.unwrap();

0 commit comments

Comments
 (0)