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