@@ -8157,49 +8157,29 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8157
8157
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
8158
8158
let peer_state = &mut *peer_state_lock;
8159
8159
match peer_state.channel_by_id.entry(msg.channel_id) {
8160
- hash_map::Entry::Occupied(chan_entry) => {
8161
- if chan_entry.get().is_unfunded_outbound_v1() {
8162
- let chan = if let Ok(chan) = chan_entry.remove().into_unfunded_outbound_v1() { chan } else { unreachable!() };
8163
- let logger = WithContext::from(
8164
- &self.logger,
8165
- Some(chan.context.get_counterparty_node_id()),
8166
- Some(chan.context.channel_id()),
8167
- None
8168
- );
8169
- let res =
8170
- chan.funding_signed(&msg, best_block, &self.signer_provider, &&logger);
8171
- match res {
8172
- Ok((mut chan, monitor)) => {
8173
- if let Ok(persist_status) = self.chain_monitor.watch_channel(chan.context.get_funding_txo().unwrap(), monitor) {
8174
- // We really should be able to insert here without doing a second
8175
- // lookup, but sadly rust stdlib doesn't currently allow keeping
8176
- // the original Entry around with the value removed.
8177
- let chan = peer_state.channel_by_id.entry(msg.channel_id).or_insert(Channel::from(chan));
8178
- if let Some(funded_chan) = chan.as_funded_mut() {
8179
- handle_new_monitor_update!(self, persist_status, peer_state_lock, peer_state, per_peer_state, funded_chan, INITIAL_MONITOR);
8180
- } else { unreachable!(); }
8181
- Ok(())
8182
- } else {
8183
- let e = ChannelError::close("Channel funding outpoint was a duplicate".to_owned());
8160
+ hash_map::Entry::Occupied(mut chan_entry) => {
8161
+ let chan = chan_entry.get_mut();
8162
+ match chan
8163
+ .funding_signed(&msg, best_block, &self.signer_provider, &self.logger)
8164
+ .and_then(|(funded_chan, monitor)| {
8165
+ self.chain_monitor
8166
+ .watch_channel(funded_chan.context.get_funding_txo().unwrap(), monitor)
8167
+ .map_err(|()| {
8184
8168
// We weren't able to watch the channel to begin with, so no
8185
8169
// updates should be made on it. Previously, full_stack_target
8186
8170
// found an (unreachable) panic when the monitor update contained
8187
8171
// within `shutdown_finish` was applied.
8188
- chan.unset_funding_info(msg.channel_id);
8189
- return Err(convert_channel_err!(self, peer_state, e, chan, &msg.channel_id, FUNDED_CHANNEL).1);
8190
- }
8191
- },
8192
- Err((mut chan, e)) => {
8193
- debug_assert!(matches!(e, ChannelError::Close(_)),
8194
- "We don't have a channel anymore, so the error better have expected close");
8195
- // We've already removed this outbound channel from the map in
8196
- // `PeerState` above so at this point we just need to clean up any
8197
- // lingering entries concerning this channel as it is safe to do so.
8198
- return Err(convert_channel_err!(self, peer_state, e, chan.context, &msg.channel_id, UNFUNDED_CHANNEL).1);
8199
- }
8200
- }
8201
- } else {
8202
- return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id));
8172
+ funded_chan.unset_funding_info(msg.channel_id);
8173
+ ChannelError::close("Channel funding outpoint was a duplicate".to_owned())
8174
+ })
8175
+ .map(|persist_status| (funded_chan, persist_status))
8176
+ })
8177
+ {
8178
+ Ok((funded_chan, persist_status)) => {
8179
+ handle_new_monitor_update!(self, persist_status, peer_state_lock, peer_state, per_peer_state, funded_chan, INITIAL_MONITOR);
8180
+ Ok(())
8181
+ },
8182
+ Err(e) => try_channel_entry!(self, peer_state, Err(e), chan_entry),
8203
8183
}
8204
8184
},
8205
8185
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
0 commit comments