@@ -2271,7 +2271,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2271
2271
Some ( ( _cp_id, chan_id) ) => Some ( chan_id. clone ( ) ) ,
2272
2272
} ;
2273
2273
let chan_update_opt = if let Some ( forwarding_id) = forwarding_id_opt {
2274
- let chan = channel_state. by_id . get_mut ( & forwarding_id) . unwrap ( ) ;
2274
+ let chan = match channel_state. by_id . get_mut ( & forwarding_id) {
2275
+ None => {
2276
+ // Channel was removed. The short_to_chan_info and by_id maps have
2277
+ // no consistency guarantees.
2278
+ break Some ( ( "Don't have available channel for forwarding as requested." , 0x4000 | 10 , None ) ) ;
2279
+ } ,
2280
+ Some ( chan) => chan
2281
+ } ;
2275
2282
if !chan. should_announce ( ) && !self . default_configuration . accept_forwards_to_priv_channels {
2276
2283
// Note that the behavior here should be identical to the above block - we
2277
2284
// should NOT reveal the existence or non-existence of a private channel if
@@ -2517,7 +2524,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2517
2524
} ,
2518
2525
None => { insert_outbound_payment ! ( ) ; } ,
2519
2526
}
2520
- } else { unreachable ! ( ) ; }
2527
+ } else {
2528
+ return Err ( APIError :: ChannelUnavailable { err : "No channel available with first hop!" . to_owned ( ) } ) ;
2529
+ }
2521
2530
return Ok ( ( ) ) ;
2522
2531
} ;
2523
2532
@@ -3106,9 +3115,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3106
3115
3107
3116
for ( short_chan_id, mut pending_forwards) in channel_state. forward_htlcs . drain ( ) {
3108
3117
if short_chan_id != 0 {
3109
- let forward_chan_id = match self . short_to_chan_info . read ( ) . unwrap ( ) . get ( & short_chan_id) {
3110
- Some ( ( _cp_id, chan_id) ) => chan_id. clone ( ) ,
3111
- None => {
3118
+ macro_rules! fail_pending_forwards {
3119
+ ( ) => {
3112
3120
for forward_info in pending_forwards. drain( ..) {
3113
3121
match forward_info {
3114
3122
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info: PendingHTLCInfo {
@@ -3195,6 +3203,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3195
3203
}
3196
3204
}
3197
3205
}
3206
+ }
3207
+ }
3208
+ let forward_chan_id = match self . short_to_chan_info . read ( ) . unwrap ( ) . get ( & short_chan_id) {
3209
+ Some ( ( _cp_id, chan_id) ) => chan_id. clone ( ) ,
3210
+ None => {
3211
+ fail_pending_forwards ! ( ) ;
3198
3212
continue ;
3199
3213
}
3200
3214
} ;
@@ -3321,7 +3335,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3321
3335
} ) ;
3322
3336
}
3323
3337
} else {
3324
- unreachable ! ( ) ;
3338
+ fail_pending_forwards ! ( ) ;
3339
+ continue ;
3325
3340
}
3326
3341
} else {
3327
3342
for forward_info in pending_forwards. drain ( ..) {
@@ -4250,7 +4265,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4250
4265
return ClaimFundsFromHop :: MonitorUpdateFail ( counterparty_node_id, res, None ) ;
4251
4266
} ,
4252
4267
}
4253
- } else { unreachable ! ( ) ; }
4268
+ } else { return ClaimFundsFromHop :: PrevHopForceClosed }
4254
4269
}
4255
4270
4256
4271
fn finalize_claims ( & self , mut sources : Vec < HTLCSource > ) {
@@ -5160,7 +5175,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
5160
5175
try_chan_entry ! ( self , chan. get_mut( ) . channel_update( & msg) , chan) ;
5161
5176
}
5162
5177
} ,
5163
- hash_map:: Entry :: Vacant ( _) => unreachable ! ( )
5178
+ hash_map:: Entry :: Vacant ( _) => return Ok ( NotifyOption :: SkipPersist )
5164
5179
}
5165
5180
Ok ( NotifyOption :: DoPersist )
5166
5181
}
0 commit comments