@@ -365,9 +365,15 @@ impl ChannelManager {
365
365
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 ) ) ?;
366
366
let res = channel. get_open_channel ( self . genesis_hash . clone ( ) , & * self . fee_estimator ) ;
367
367
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) ; }
371
377
}
372
378
373
379
let mut events = self . pending_events . lock ( ) . unwrap ( ) ;
@@ -2456,9 +2462,11 @@ mod tests {
2456
2462
}
2457
2463
impl Drop for Node {
2458
2464
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
+ }
2462
2470
}
2463
2471
}
2464
2472
0 commit comments