@@ -2299,7 +2299,14 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
2299
2299
Some ( ( _cp_id, chan_id) ) => Some ( chan_id. clone ( ) ) ,
2300
2300
} ;
2301
2301
let chan_update_opt = if let Some ( forwarding_id) = forwarding_id_opt {
2302
- let chan = channel_state. by_id . get_mut ( & forwarding_id) . unwrap ( ) ;
2302
+ let chan = match channel_state. by_id . get_mut ( & forwarding_id) {
2303
+ None => {
2304
+ // Channel was removed. The short_to_chan_info and by_id maps have
2305
+ // no consistency guarantees.
2306
+ break Some ( ( "Don't have available channel for forwarding as requested." , 0x4000 | 10 , None ) ) ;
2307
+ } ,
2308
+ Some ( chan) => chan
2309
+ } ;
2303
2310
if !chan. should_announce ( ) && !self . default_configuration . accept_forwards_to_priv_channels {
2304
2311
// Note that the behavior here should be identical to the above block - we
2305
2312
// should NOT reveal the existence or non-existence of a private channel if
@@ -2555,7 +2562,12 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
2555
2562
} ,
2556
2563
None => { insert_outbound_payment ! ( ) ; } ,
2557
2564
}
2558
- } else { unreachable ! ( ) ; }
2565
+ } else {
2566
+ // The channel was likely removed after we fetched the id from the
2567
+ // `short_to_chan_info` map, but before we successfully locked the `by_id` map.
2568
+ // This can occur as no consistency guarantees exists between the two maps.
2569
+ return Err ( APIError :: ChannelUnavailable { err : "No channel available with first hop!" . to_owned ( ) } ) ;
2570
+ }
2559
2571
return Ok ( ( ) ) ;
2560
2572
} ;
2561
2573
@@ -3062,9 +3074,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3062
3074
let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
3063
3075
let channel_state = & mut * channel_state_lock;
3064
3076
if short_chan_id != 0 {
3065
- let forward_chan_id = match self . short_to_chan_info . read ( ) . unwrap ( ) . get ( & short_chan_id) {
3066
- Some ( ( _cp_id, chan_id) ) => chan_id. clone ( ) ,
3067
- None => {
3077
+ macro_rules! forwarding_channel_not_found {
3078
+ ( ) => {
3068
3079
for forward_info in pending_forwards. drain( ..) {
3069
3080
match forward_info {
3070
3081
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info: PendingHTLCInfo {
@@ -3151,6 +3162,12 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3151
3162
}
3152
3163
}
3153
3164
}
3165
+ }
3166
+ }
3167
+ let forward_chan_id = match self . short_to_chan_info . read ( ) . unwrap ( ) . get ( & short_chan_id) {
3168
+ Some ( ( _cp_id, chan_id) ) => chan_id. clone ( ) ,
3169
+ None => {
3170
+ forwarding_channel_not_found ! ( ) ;
3154
3171
continue ;
3155
3172
}
3156
3173
} ;
@@ -3280,7 +3297,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3280
3297
} ) ;
3281
3298
}
3282
3299
} else {
3283
- unreachable ! ( ) ;
3300
+ forwarding_channel_not_found ! ( ) ;
3301
+ continue ;
3284
3302
}
3285
3303
} else {
3286
3304
for forward_info in pending_forwards. drain ( ..) {
@@ -4198,7 +4216,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4198
4216
return ClaimFundsFromHop :: MonitorUpdateFail ( counterparty_node_id, res, None ) ;
4199
4217
} ,
4200
4218
}
4201
- } else { unreachable ! ( ) ; }
4219
+ } else { return ClaimFundsFromHop :: PrevHopForceClosed }
4202
4220
}
4203
4221
4204
4222
fn finalize_claims ( & self , mut sources : Vec < HTLCSource > ) {
@@ -5118,7 +5136,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5118
5136
try_chan_entry ! ( self , chan. get_mut( ) . channel_update( & msg) , chan) ;
5119
5137
}
5120
5138
} ,
5121
- hash_map:: Entry :: Vacant ( _) => unreachable ! ( )
5139
+ hash_map:: Entry :: Vacant ( _) => return Ok ( NotifyOption :: SkipPersist )
5122
5140
}
5123
5141
Ok ( NotifyOption :: DoPersist )
5124
5142
}
0 commit comments