@@ -365,9 +365,15 @@ impl ChannelManager {
365365 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 ) ) ?;
366366 let res = channel. get_open_channel ( self . genesis_hash . clone ( ) , & * self . fee_estimator ) ;
367367 let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
368- match channel_state. by_id . insert ( channel. channel_id ( ) , channel) {
369- Some ( _) => panic ! ( "RNG is bad???" ) ,
370- None => { }
368+ match channel_state. by_id . entry ( channel. channel_id ( ) ) {
369+ hash_map:: Entry :: Occupied ( _) => {
370+ if cfg ! ( feature = "fuzztarget" ) {
371+ return Err ( APIError :: APIMisuseError { err : "Fuzzy bad RNG" } ) ;
372+ } else {
373+ panic ! ( "RNG is bad???" ) ;
374+ }
375+ } ,
376+ hash_map:: Entry :: Vacant ( entry) => { entry. insert ( channel) ; }
371377 }
372378
373379 let mut events = self . pending_events . lock ( ) . unwrap ( ) ;
@@ -2456,9 +2462,11 @@ mod tests {
24562462 }
24572463 impl Drop for Node {
24582464 fn drop ( & mut self ) {
2459- // Check that we processed all pending events
2460- assert_eq ! ( self . node. get_and_clear_pending_events( ) . len( ) , 0 ) ;
2461- assert_eq ! ( self . chan_monitor. added_monitors. lock( ) . unwrap( ) . len( ) , 0 ) ;
2465+ if !:: std:: thread:: panicking ( ) {
2466+ // Check that we processed all pending events
2467+ assert_eq ! ( self . node. get_and_clear_pending_events( ) . len( ) , 0 ) ;
2468+ assert_eq ! ( self . chan_monitor. added_monitors. lock( ) . unwrap( ) . len( ) , 0 ) ;
2469+ }
24622470 }
24632471 }
24642472
0 commit comments