From 28e67db327e23aa6d5c5f04fa1878bef04f53b55 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 26 Sep 2018 11:02:38 -0400 Subject: [PATCH] Handle temporary_channel_id collision in fuzztarget mode --- src/ln/channelmanager.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ln/channelmanager.rs b/src/ln/channelmanager.rs index ba535d007..402ac97b3 100644 --- a/src/ln/channelmanager.rs +++ b/src/ln/channelmanager.rs @@ -365,9 +365,15 @@ impl ChannelManager { let channel = Channel::new_outbound(&*self.fee_estimator, chan_keys, their_network_key, channel_value_satoshis, push_msat, self.announce_channels_publicly, user_id, Arc::clone(&self.logger))?; let res = channel.get_open_channel(self.genesis_hash.clone(), &*self.fee_estimator); let mut channel_state = self.channel_state.lock().unwrap(); - match channel_state.by_id.insert(channel.channel_id(), channel) { - Some(_) => panic!("RNG is bad???"), - None => {} + match channel_state.by_id.entry(channel.channel_id()) { + hash_map::Entry::Occupied(_) => { + if cfg!(feature = "fuzztarget") { + return Err(APIError::APIMisuseError { err: "Fuzzy bad RNG" }); + } else { + panic!("RNG is bad???"); + } + }, + hash_map::Entry::Vacant(entry) => { entry.insert(channel); } } let mut events = self.pending_events.lock().unwrap(); -- 2.39.5