@@ -2304,7 +2304,14 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
2304
2304
Some ( ( _cp_id, chan_id) ) => Some ( chan_id. clone ( ) ) ,
2305
2305
} ;
2306
2306
let chan_update_opt = if let Some ( forwarding_id) = forwarding_id_opt {
2307
- let chan = channel_state. by_id . get_mut ( & forwarding_id) . unwrap ( ) ;
2307
+ let chan = match channel_state. by_id . get_mut ( & forwarding_id) {
2308
+ None => {
2309
+ // Channel was removed. The short_to_chan_info and by_id maps have
2310
+ // no consistency guarantees.
2311
+ break Some ( ( "Don't have available channel for forwarding as requested." , 0x4000 | 10 , None ) ) ;
2312
+ } ,
2313
+ Some ( chan) => chan
2314
+ } ;
2308
2315
if !chan. should_announce ( ) && !self . default_configuration . accept_forwards_to_priv_channels {
2309
2316
// Note that the behavior here should be identical to the above block - we
2310
2317
// should NOT reveal the existence or non-existence of a private channel if
@@ -2561,7 +2568,9 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
2561
2568
} ,
2562
2569
None => { insert_outbound_payment ! ( ) ; } ,
2563
2570
}
2564
- } else { unreachable ! ( ) ; }
2571
+ } else {
2572
+ return Err ( APIError :: ChannelUnavailable { err : "No channel available with first hop!" . to_owned ( ) } ) ;
2573
+ }
2565
2574
return Ok ( ( ) ) ;
2566
2575
} ;
2567
2576
@@ -3068,9 +3077,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3068
3077
let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
3069
3078
let channel_state = & mut * channel_state_lock;
3070
3079
if short_chan_id != 0 {
3071
- let forward_chan_id = match self . short_to_chan_info . read ( ) . unwrap ( ) . get ( & short_chan_id) {
3072
- Some ( ( _cp_id, chan_id) ) => chan_id. clone ( ) ,
3073
- None => {
3080
+ macro_rules! fail_pending_forwards {
3081
+ ( ) => {
3074
3082
for forward_info in pending_forwards. drain( ..) {
3075
3083
match forward_info {
3076
3084
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info: PendingHTLCInfo {
@@ -3157,6 +3165,12 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3157
3165
}
3158
3166
}
3159
3167
}
3168
+ }
3169
+ }
3170
+ let forward_chan_id = match self . short_to_chan_info . read ( ) . unwrap ( ) . get ( & short_chan_id) {
3171
+ Some ( ( _cp_id, chan_id) ) => chan_id. clone ( ) ,
3172
+ None => {
3173
+ fail_pending_forwards ! ( ) ;
3160
3174
continue ;
3161
3175
}
3162
3176
} ;
@@ -3286,7 +3300,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3286
3300
} ) ;
3287
3301
}
3288
3302
} else {
3289
- unreachable ! ( ) ;
3303
+ fail_pending_forwards ! ( ) ;
3304
+ continue ;
3290
3305
}
3291
3306
} else {
3292
3307
for forward_info in pending_forwards. drain ( ..) {
@@ -4204,7 +4219,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4204
4219
return ClaimFundsFromHop :: MonitorUpdateFail ( counterparty_node_id, res, None ) ;
4205
4220
} ,
4206
4221
}
4207
- } else { unreachable ! ( ) ; }
4222
+ } else { return ClaimFundsFromHop :: PrevHopForceClosed }
4208
4223
}
4209
4224
4210
4225
fn finalize_claims ( & self , mut sources : Vec < HTLCSource > ) {
@@ -5124,7 +5139,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5124
5139
try_chan_entry ! ( self , chan. get_mut( ) . channel_update( & msg) , chan) ;
5125
5140
}
5126
5141
} ,
5127
- hash_map:: Entry :: Vacant ( _) => unreachable ! ( )
5142
+ hash_map:: Entry :: Vacant ( _) => return Ok ( NotifyOption :: SkipPersist )
5128
5143
}
5129
5144
Ok ( NotifyOption :: DoPersist )
5130
5145
}
0 commit comments