Skip to content

Commit ab43fcd

Browse files
f - Add id_to_peer map, remove unnecessary variables
1 parent e2c3704 commit ab43fcd

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,18 +2777,16 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
27772777
node_id: chan.get_counterparty_node_id(),
27782778
msg,
27792779
});
2780-
let chan_id = chan.channel_id();
2781-
match channel_state.by_id.entry(chan_id) {
2780+
match channel_state.by_id.entry(chan.channel_id()) {
27822781
hash_map::Entry::Occupied(_) => {
27832782
panic!("Generated duplicate funding txid?");
27842783
},
27852784
hash_map::Entry::Vacant(e) => {
2786-
let counterparty_node_id = chan.get_counterparty_node_id();
2787-
e.insert(chan);
27882785
let mut id_to_peer = self.id_to_peer.lock().unwrap();
2789-
if id_to_peer.insert(chan_id, counterparty_node_id).is_some() {
2786+
if id_to_peer.insert(chan.channel_id(), chan.get_counterparty_node_id()).is_some() {
27902787
panic!("id_to_peer map already contained funding txid, which shouldn't be possible");
27912788
}
2789+
e.insert(chan);
27922790
}
27932791
}
27942792
Ok(())
@@ -4435,12 +4433,15 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
44354433
}
44364434
let mut channel_state_lock = self.channel_state.lock().unwrap();
44374435
let channel_state = &mut *channel_state_lock;
4438-
let channel_id = funding_msg.channel_id;
4439-
match channel_state.by_id.entry(channel_id) {
4436+
match channel_state.by_id.entry(funding_msg.channel_id) {
44404437
hash_map::Entry::Occupied(_) => {
4441-
return Err(MsgHandleErrInternal::send_err_msg_no_close("Already had channel with the new channel_id".to_owned(), channel_id))
4438+
return Err(MsgHandleErrInternal::send_err_msg_no_close("Already had channel with the new channel_id".to_owned(), funding_msg.channel_id))
44424439
},
44434440
hash_map::Entry::Vacant(e) => {
4441+
let mut id_to_peer = self.id_to_peer.lock().unwrap();
4442+
if id_to_peer.insert(funding_msg.channel_id, *counterparty_node_id).is_some() {
4443+
panic!("id_to_peer map already contained funding txid, which shouldn't be possible");
4444+
}
44444445
channel_state.pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
44454446
node_id: counterparty_node_id.clone(),
44464447
msg: funding_msg,
@@ -4449,10 +4450,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
44494450
send_channel_ready!(channel_state.short_to_chan_info, channel_state.pending_msg_events, chan, msg);
44504451
}
44514452
e.insert(chan);
4452-
let mut id_to_peer = self.id_to_peer.lock().unwrap();
4453-
if id_to_peer.insert(channel_id, *counterparty_node_id).is_some() {
4454-
panic!("id_to_peer map already contained funding txid, which shouldn't be possible");
4455-
}
44564453
}
44574454
}
44584455
Ok(())

0 commit comments

Comments
 (0)