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