@@ -2277,7 +2277,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2277
2277
Some ( ( _cp_id, chan_id) ) => Some ( chan_id. clone ( ) ) ,
2278
2278
} ;
2279
2279
let chan_update_opt = if let Some ( forwarding_id) = forwarding_id_opt {
2280
- let chan = channel_state. by_id . get_mut ( & forwarding_id) . unwrap ( ) ;
2280
+ let chan = match channel_state. by_id . get_mut ( & forwarding_id) {
2281
+ None => {
2282
+ // Channel was removed. The short_to_chan_info and by_id maps have
2283
+ // no consistency guarantees.
2284
+ break Some ( ( "Don't have available channel for forwarding as requested." , 0x4000 | 10 , None ) ) ;
2285
+ } ,
2286
+ Some ( chan) => chan
2287
+ } ;
2281
2288
if !chan. should_announce ( ) && !self . default_configuration . accept_forwards_to_priv_channels {
2282
2289
// Note that the behavior here should be identical to the above block - we
2283
2290
// should NOT reveal the existence or non-existence of a private channel if
@@ -2523,7 +2530,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2523
2530
} ,
2524
2531
None => { insert_outbound_payment ! ( ) ; } ,
2525
2532
}
2526
- } else { unreachable ! ( ) ; }
2533
+ } else {
2534
+ return Err ( APIError :: ChannelUnavailable { err : "No channel available with first hop!" . to_owned ( ) } ) ;
2535
+ }
2527
2536
return Ok ( ( ) ) ;
2528
2537
} ;
2529
2538
@@ -3112,9 +3121,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3112
3121
3113
3122
for ( short_chan_id, mut pending_forwards) in channel_state. forward_htlcs . drain ( ) {
3114
3123
if short_chan_id != 0 {
3115
- let forward_chan_id = match self . short_to_chan_info . read ( ) . unwrap ( ) . get ( & short_chan_id) {
3116
- Some ( ( _cp_id, chan_id) ) => chan_id. clone ( ) ,
3117
- None => {
3124
+ macro_rules! fail_pending_forwards {
3125
+ ( ) => {
3118
3126
for forward_info in pending_forwards. drain( ..) {
3119
3127
match forward_info {
3120
3128
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info: PendingHTLCInfo {
@@ -3201,6 +3209,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3201
3209
}
3202
3210
}
3203
3211
}
3212
+ }
3213
+ }
3214
+ let forward_chan_id = match self . short_to_chan_info . read ( ) . unwrap ( ) . get ( & short_chan_id) {
3215
+ Some ( ( _cp_id, chan_id) ) => chan_id. clone ( ) ,
3216
+ None => {
3217
+ fail_pending_forwards ! ( ) ;
3204
3218
continue ;
3205
3219
}
3206
3220
} ;
@@ -3327,7 +3341,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3327
3341
} ) ;
3328
3342
}
3329
3343
} else {
3330
- unreachable ! ( ) ;
3344
+ fail_pending_forwards ! ( ) ;
3345
+ continue ;
3331
3346
}
3332
3347
} else {
3333
3348
for forward_info in pending_forwards. drain ( ..) {
@@ -4266,7 +4281,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4266
4281
return ClaimFundsFromHop :: MonitorUpdateFail ( counterparty_node_id, res, None ) ;
4267
4282
} ,
4268
4283
}
4269
- } else { unreachable ! ( ) ; }
4284
+ } else { return ClaimFundsFromHop :: PrevHopForceClosed }
4270
4285
}
4271
4286
4272
4287
fn finalize_claims ( & self , mut sources : Vec < HTLCSource > ) {
@@ -5177,7 +5192,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
5177
5192
try_chan_entry ! ( self , chan. get_mut( ) . channel_update( & msg) , chan) ;
5178
5193
}
5179
5194
} ,
5180
- hash_map:: Entry :: Vacant ( _) => unreachable ! ( )
5195
+ hash_map:: Entry :: Vacant ( _) => return Ok ( NotifyOption :: SkipPersist )
5181
5196
}
5182
5197
Ok ( NotifyOption :: DoPersist )
5183
5198
}
0 commit comments