Skip to content

Commit

Permalink
f one more case
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Dec 14, 2023
1 parent f72b79e commit 4930c19
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6236,25 +6236,27 @@ where

let funded_channel_id = chan.context.channel_id();

macro_rules! fail_chan { ($err: expr) => { {
// Note that at this point we've filled in the funding outpoint on our
// channel, but its actually in conflict with another channel. Thus, if
// we call `convert_chan_phase_err` immediately (thus calling
// `update_maps_on_chan_removal`), we'll remove the existing channel
// from `id_to_peer`. Thus, we must first unset the funding outpoint on
// the channel.
let err = ChannelError::Close($err.to_owned());
chan.unset_funding_info(msg.temporary_channel_id);
return Err(convert_chan_phase_err!(self, err, &mut ChannelPhase::Funded(chan), &funded_channel_id).1);
} } }

match peer_state.channel_by_id.entry(funded_channel_id) {
hash_map::Entry::Occupied(_) => {
let err = ChannelError::Close("Already had channel with the new channel_id".to_owned());
// Note that at this point we've filled in the funding outpoint on our
// channel, but its actually in conflict with another channel. Thus, if
// we call `convert_chan_phase_err` immediately (thus calling
// `update_maps_on_chan_removal`), we'll remove the existing channel
// from `id_to_peer`. Thus, we must first unset the funding outpoint on
// the channel.
chan.unset_funding_info(msg.temporary_channel_id);
return Err(convert_chan_phase_err!(self, err, &mut ChannelPhase::Funded(chan), &funded_channel_id).1);
fail_chan!(err);
},
hash_map::Entry::Vacant(e) => {
let mut outpoint_to_peer_lock = self.outpoint_to_peer.lock().unwrap();
match outpoint_to_peer_lock.entry(monitor.get_funding_txo().0) {
hash_map::Entry::Occupied(_) => {
return Err(MsgHandleErrInternal::send_err_msg_no_close(
"The funding_created message had the same funding_txid as an existing channel - funding is not possible".to_owned(),
chan.context.channel_id()))
fail_chan!("The funding_created message had the same funding_txid as an existing channel - funding is not possible");
},
hash_map::Entry::Vacant(i_e) => {
let monitor_res = self.chain_monitor.watch_channel(monitor.get_funding_txo().0, monitor);
Expand Down Expand Up @@ -6283,15 +6285,7 @@ where
} else {
let logger = WithChannelContext::from(&self.logger, &chan.context);
log_error!(logger, "Persisting initial ChannelMonitor failed, implying the funding outpoint was duplicated");
let err = ChannelError::Close("Duplicate funding outpoint".to_owned());
// Note that at this point we've filled in the funding outpoint on our
// channel, but its actually in conflict with another channel. Thus, if
// we call `convert_chan_phase_err` immediately (thus calling
// `update_maps_on_chan_removal`), we'll remove the existing channel
// from `id_to_peer`. Thus, we must first unset the funding outpoint on
// the channel.
chan.unset_funding_info(msg.temporary_channel_id);
return Err(convert_chan_phase_err!(self, err, &mut ChannelPhase::Funded(chan), &funded_channel_id).1);
fail_chan!("Duplicate funding outpoint");
}
}
}
Expand Down

0 comments on commit 4930c19

Please sign in to comment.