@@ -2274,7 +2274,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2274
2274
Some ( ( _cp_id, chan_id) ) => Some ( chan_id. clone ( ) ) ,
2275
2275
} ;
2276
2276
let chan_update_opt = if let Some ( forwarding_id) = forwarding_id_opt {
2277
- let chan = channel_state. by_id . get_mut ( & forwarding_id) . unwrap ( ) ;
2277
+ let chan = match channel_state. by_id . get_mut ( & forwarding_id) {
2278
+ None => {
2279
+ // Channel was removed. The short_to_chan_info and by_id maps have
2280
+ // no consistency guarantees.
2281
+ break Some ( ( "Don't have available channel for forwarding as requested." , 0x4000 | 10 , None ) ) ;
2282
+ } ,
2283
+ Some ( chan) => chan
2284
+ } ;
2278
2285
if !chan. should_announce ( ) && !self . default_configuration . accept_forwards_to_priv_channels {
2279
2286
// Note that the behavior here should be identical to the above block - we
2280
2287
// should NOT reveal the existence or non-existence of a private channel if
@@ -2520,7 +2527,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2520
2527
} ,
2521
2528
None => { insert_outbound_payment ! ( ) ; } ,
2522
2529
}
2523
- } else { unreachable ! ( ) ; }
2530
+ } else {
2531
+ return Err ( APIError :: ChannelUnavailable { err : "No channel available with first hop!" . to_owned ( ) } ) ;
2532
+ }
2524
2533
return Ok ( ( ) ) ;
2525
2534
} ;
2526
2535
@@ -3109,9 +3118,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3109
3118
3110
3119
for ( short_chan_id, mut pending_forwards) in channel_state. forward_htlcs . drain ( ) {
3111
3120
if short_chan_id != 0 {
3112
- let forward_chan_id = match self . short_to_chan_info . read ( ) . unwrap ( ) . get ( & short_chan_id) {
3113
- Some ( ( _cp_id, chan_id) ) => chan_id. clone ( ) ,
3114
- None => {
3121
+ macro_rules! fail_pending_forwards {
3122
+ ( ) => {
3115
3123
for forward_info in pending_forwards. drain( ..) {
3116
3124
match forward_info {
3117
3125
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info: PendingHTLCInfo {
@@ -3198,6 +3206,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3198
3206
}
3199
3207
}
3200
3208
}
3209
+ }
3210
+ }
3211
+ let forward_chan_id = match self . short_to_chan_info . read ( ) . unwrap ( ) . get ( & short_chan_id) {
3212
+ Some ( ( _cp_id, chan_id) ) => chan_id. clone ( ) ,
3213
+ None => {
3214
+ fail_pending_forwards ! ( ) ;
3201
3215
continue ;
3202
3216
}
3203
3217
} ;
@@ -3324,7 +3338,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3324
3338
} ) ;
3325
3339
}
3326
3340
} else {
3327
- unreachable ! ( ) ;
3341
+ fail_pending_forwards ! ( ) ;
3342
+ continue ;
3328
3343
}
3329
3344
} else {
3330
3345
for forward_info in pending_forwards. drain ( ..) {
@@ -4263,7 +4278,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4263
4278
return ClaimFundsFromHop :: MonitorUpdateFail ( counterparty_node_id, res, None ) ;
4264
4279
} ,
4265
4280
}
4266
- } else { unreachable ! ( ) ; }
4281
+ } else { return ClaimFundsFromHop :: PrevHopForceClosed }
4267
4282
}
4268
4283
4269
4284
fn finalize_claims ( & self , mut sources : Vec < HTLCSource > ) {
@@ -5174,7 +5189,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
5174
5189
try_chan_entry ! ( self , chan. get_mut( ) . channel_update( & msg) , chan) ;
5175
5190
}
5176
5191
} ,
5177
- hash_map:: Entry :: Vacant ( _) => unreachable ! ( )
5192
+ hash_map:: Entry :: Vacant ( _) => return Ok ( NotifyOption :: SkipPersist )
5178
5193
}
5179
5194
Ok ( NotifyOption :: DoPersist )
5180
5195
}
0 commit comments