Skip to content

Commit c09903b

Browse files
f - add duplicate funding txid protection
1 parent 6a748ce commit c09903b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4539,8 +4539,18 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
45394539
},
45404540
hash_map::Entry::Vacant(e) => {
45414541
let mut id_to_peer = self.id_to_peer.lock().unwrap();
4542-
if id_to_peer.insert(funding_msg.channel_id, *counterparty_node_id).is_some() {
4543-
panic!("id_to_peer map already contained funding txid, which shouldn't be possible");
4542+
match id_to_peer.entry(chan.channel_id()) {
4543+
hash_map::Entry::Occupied(_) => {
4544+
return Err(MsgHandleErrInternal::send_err_msg_no_close(
4545+
"Funding txid already exists with for another peer (or likely the
4546+
same peer using a different id). The counterparty must have sent a
4547+
txid in the FundingCreated msgs for a tx with a different
4548+
script_pubkey than the one agreed upon".to_owned(),
4549+
funding_msg.channel_id))
4550+
},
4551+
hash_map::Entry::Vacant(i_e) => {
4552+
i_e.insert(chan.get_counterparty_node_id());
4553+
}
45444554
}
45454555
channel_state.pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
45464556
node_id: counterparty_node_id.clone(),

0 commit comments

Comments
 (0)