@@ -4300,8 +4300,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4300
4300
let mut valid_mpp = true ;
4301
4301
let mut errs = Vec :: new ( ) ;
4302
4302
let mut claimed_any_htlcs = false ;
4303
- let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
4304
- let channel_state = & mut * channel_state_lock;
4303
+ let mut channel_state = Some ( self . channel_state . lock ( ) . unwrap ( ) ) ;
4305
4304
for htlc in sources. iter ( ) {
4306
4305
let chan_id = match self . short_to_chan_info . read ( ) . unwrap ( ) . get ( & htlc. prev_hop . short_channel_id ) {
4307
4306
Some ( ( _cp_id, chan_id) ) => chan_id. clone ( ) ,
@@ -4311,7 +4310,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4311
4310
}
4312
4311
} ;
4313
4312
4314
- if let None = channel_state. by_id . get ( & chan_id) {
4313
+ if let None = channel_state. as_ref ( ) . unwrap ( ) . by_id . get ( & chan_id) {
4315
4314
valid_mpp = false ;
4316
4315
break ;
4317
4316
}
@@ -4349,7 +4348,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4349
4348
}
4350
4349
if valid_mpp {
4351
4350
for htlc in sources. drain ( ..) {
4352
- match self . claim_funds_from_hop ( & mut channel_state_lock, htlc. prev_hop , payment_preimage) {
4351
+ if channel_state. is_none ( ) { channel_state = Some ( self . channel_state . lock ( ) . unwrap ( ) ) ; }
4352
+ match self . claim_funds_from_hop ( channel_state. take ( ) . unwrap ( ) , htlc. prev_hop , payment_preimage) {
4353
4353
ClaimFundsFromHop :: MonitorUpdateFail ( pk, err, _) => {
4354
4354
if let msgs:: ErrorAction :: IgnoreError = err. err . action {
4355
4355
// We got a temporary failure updating monitor, but will claim the
@@ -4358,7 +4358,12 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4358
4358
claimed_any_htlcs = true ;
4359
4359
} else { errs. push ( ( pk, err) ) ; }
4360
4360
} ,
4361
- ClaimFundsFromHop :: PrevHopForceClosed => unreachable ! ( "We already checked for channel existence, we can't fail here!" ) ,
4361
+ ClaimFundsFromHop :: PrevHopForceClosed => {
4362
+ // This should be incredibly rare - we checked that all the channels were
4363
+ // open above, though as we release the lock at each loop iteration it's
4364
+ // still possible. We should still claim the HTLC on-chain through the
4365
+ // closed-channel-update generated in claim_funds_from_hop.
4366
+ } ,
4362
4367
ClaimFundsFromHop :: DuplicateClaim => {
4363
4368
// While we should never get here in most cases, if we do, it likely
4364
4369
// indicates that the HTLC was timed out some time ago and is no longer
@@ -4369,7 +4374,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4369
4374
}
4370
4375
}
4371
4376
}
4372
- mem:: drop ( channel_state_lock ) ;
4377
+ mem:: drop ( channel_state ) ;
4373
4378
if !valid_mpp {
4374
4379
for htlc in sources. drain ( ..) {
4375
4380
let mut htlc_msat_height_data = htlc. value . to_be_bytes ( ) . to_vec ( ) ;
@@ -4396,11 +4401,11 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4396
4401
}
4397
4402
}
4398
4403
4399
- fn claim_funds_from_hop ( & self , channel_state_lock : & mut MutexGuard < ChannelHolder < <K :: Target as KeysInterface >:: Signer > > , prev_hop : HTLCPreviousHopData , payment_preimage : PaymentPreimage ) -> ClaimFundsFromHop {
4404
+ fn claim_funds_from_hop ( & self , mut channel_state_lock : MutexGuard < ChannelHolder < <K :: Target as KeysInterface >:: Signer > > , prev_hop : HTLCPreviousHopData , payment_preimage : PaymentPreimage ) -> ClaimFundsFromHop {
4400
4405
//TODO: Delay the claimed_funds relaying just like we do outbound relay!
4401
4406
4402
4407
let chan_id = prev_hop. outpoint . to_channel_id ( ) ;
4403
- let channel_state = & mut * * channel_state_lock;
4408
+ let channel_state = & mut * channel_state_lock;
4404
4409
if let hash_map:: Entry :: Occupied ( mut chan) = channel_state. by_id . entry ( chan_id) {
4405
4410
match chan. get_mut ( ) . get_update_fulfill_htlc_and_commit ( prev_hop. htlc_id , payment_preimage, & self . logger ) {
4406
4411
Ok ( msgs_monitor_option) => {
@@ -4500,7 +4505,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4500
4505
}
4501
4506
}
4502
4507
4503
- fn claim_funds_internal ( & self , mut channel_state_lock : MutexGuard < ChannelHolder < <K :: Target as KeysInterface >:: Signer > > , source : HTLCSource , payment_preimage : PaymentPreimage , forwarded_htlc_value_msat : Option < u64 > , from_onchain : bool , next_channel_id : [ u8 ; 32 ] ) {
4508
+ fn claim_funds_internal ( & self , channel_state_lock : MutexGuard < ChannelHolder < <K :: Target as KeysInterface >:: Signer > > , source : HTLCSource , payment_preimage : PaymentPreimage , forwarded_htlc_value_msat : Option < u64 > , from_onchain : bool , next_channel_id : [ u8 ; 32 ] ) {
4504
4509
match source {
4505
4510
HTLCSource :: OutboundRoute { session_priv, payment_id, path, .. } => {
4506
4511
mem:: drop ( channel_state_lock) ;
@@ -4547,7 +4552,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4547
4552
} ,
4548
4553
HTLCSource :: PreviousHopData ( hop_data) => {
4549
4554
let prev_outpoint = hop_data. outpoint ;
4550
- let res = self . claim_funds_from_hop ( & mut channel_state_lock, hop_data, payment_preimage) ;
4555
+ let res = self . claim_funds_from_hop ( channel_state_lock, hop_data, payment_preimage) ;
4551
4556
let claimed_htlc = if let ClaimFundsFromHop :: DuplicateClaim = res { false } else { true } ;
4552
4557
let htlc_claim_value_msat = match res {
4553
4558
ClaimFundsFromHop :: MonitorUpdateFail ( _, _, amt_opt) => amt_opt,
@@ -4561,7 +4566,6 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4561
4566
// update to. Instead, we simply document in `PaymentForwarded` that this
4562
4567
// can happen.
4563
4568
}
4564
- mem:: drop ( channel_state_lock) ;
4565
4569
if let ClaimFundsFromHop :: MonitorUpdateFail ( pk, err, _) = res {
4566
4570
let result: Result < ( ) , _ > = Err ( err) ;
4567
4571
let _ = handle_error ! ( self , result, pk) ;
0 commit comments