@@ -303,14 +303,6 @@ struct ReceiveError {
303303 msg : & ' static str ,
304304}
305305
306- /// Return value for claim_funds_from_hop
307- enum ClaimFundsFromHop {
308- PrevHopForceClosed ,
309- MonitorUpdateFail ( PublicKey , MsgHandleErrInternal , Option < u64 > ) ,
310- Success ( u64 ) ,
311- DuplicateClaim ,
312- }
313-
314306type ShutdownResult = ( Option < ( OutPoint , ChannelMonitorUpdate ) > , Vec < ( HTLCSource , PaymentHash , PublicKey , [ u8 ; 32 ] ) > ) ;
315307
316308/// Error type returned across the channel_state mutex boundary. When an Err is generated for a
@@ -4351,29 +4343,15 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
43514343 if valid_mpp {
43524344 for htlc in sources. drain ( ..) {
43534345 if channel_state. is_none ( ) { channel_state = Some ( self . channel_state . lock ( ) . unwrap ( ) ) ; }
4354- match self . claim_funds_from_hop ( channel_state. take ( ) . unwrap ( ) , htlc. prev_hop , payment_preimage,
4346+ if let Err ( ( pk, err) ) = self . claim_funds_from_hop ( channel_state. take ( ) . unwrap ( ) , htlc. prev_hop ,
4347+ payment_preimage,
43554348 |_| Some ( MonitorUpdateCompletionAction :: PaymentClaimed { payment_hash } ) )
43564349 {
4357- ClaimFundsFromHop :: MonitorUpdateFail ( pk, err, _) => {
4358- if let msgs:: ErrorAction :: IgnoreError = err. err . action {
4359- // We got a temporary failure updating monitor, but will claim the
4360- // HTLC when the monitor updating is restored (or on chain).
4361- log_error ! ( self . logger, "Temporary failure claiming HTLC, treating as success: {}" , err. err. err) ;
4362- } else { errs. push ( ( pk, err) ) ; }
4363- } ,
4364- ClaimFundsFromHop :: PrevHopForceClosed => {
4365- // This should be incredibly rare - we checked that all the channels were
4366- // open above, though as we release the lock at each loop iteration it's
4367- // still possible. We should still claim the HTLC on-chain through the
4368- // closed-channel-update generated in claim_funds_from_hop.
4369- } ,
4370- ClaimFundsFromHop :: DuplicateClaim => {
4371- // While we should never get here in most cases, if we do, it likely
4372- // indicates that the HTLC was timed out some time ago and is no longer
4373- // available to be claimed. Thus, it does not make sense to set
4374- // `claimed_any_htlcs`.
4375- } ,
4376- ClaimFundsFromHop :: Success ( _) => { } ,
4350+ if let msgs:: ErrorAction :: IgnoreError = err. err . action {
4351+ // We got a temporary failure updating monitor, but will claim the
4352+ // HTLC when the monitor updating is restored (or on chain).
4353+ log_error ! ( self . logger, "Temporary failure claiming HTLC, treating as success: {}" , err. err. err) ;
4354+ } else { errs. push ( ( pk, err) ) ; }
43774355 }
43784356 }
43794357 }
@@ -4400,7 +4378,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44004378 fn claim_funds_from_hop < ComplFunc : FnOnce ( Option < u64 > ) -> Option < MonitorUpdateCompletionAction > > ( & self ,
44014379 mut channel_state_lock : MutexGuard < ChannelHolder < <K :: Target as KeysInterface >:: Signer > > ,
44024380 prev_hop : HTLCPreviousHopData , payment_preimage : PaymentPreimage , completion_action : ComplFunc )
4403- -> ClaimFundsFromHop {
4381+ -> Result < ( ) , ( PublicKey , MsgHandleErrInternal ) > {
44044382 //TODO: Delay the claimed_funds relaying just like we do outbound relay!
44054383
44064384 let chan_id = prev_hop. outpoint . to_channel_id ( ) ;
@@ -4419,9 +4397,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44194397 let err = handle_monitor_update_res ! ( self , e, chan, RAACommitmentOrder :: CommitmentFirst , false , msgs. is_some( ) ) . unwrap_err ( ) ;
44204398 mem:: drop ( channel_state_lock) ;
44214399 self . handle_monitor_update_completion_actions ( completion_action ( Some ( htlc_value_msat) ) ) ;
4422- return ClaimFundsFromHop :: MonitorUpdateFail (
4423- counterparty_node_id, err, Some ( htlc_value_msat)
4424- ) ;
4400+ return Err ( ( counterparty_node_id, err) ) ;
44254401 }
44264402 }
44274403 if let Some ( ( msg, commitment_signed) ) = msgs {
@@ -4441,9 +4417,9 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44414417 }
44424418 mem:: drop ( channel_state_lock) ;
44434419 self . handle_monitor_update_completion_actions ( completion_action ( Some ( htlc_value_msat) ) ) ;
4444- return ClaimFundsFromHop :: Success ( htlc_value_msat ) ;
4420+ Ok ( ( ) )
44454421 } else {
4446- return ClaimFundsFromHop :: DuplicateClaim ;
4422+ Ok ( ( ) )
44474423 }
44484424 } ,
44494425 Err ( ( e, monitor_update) ) => {
@@ -4461,7 +4437,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44614437 }
44624438 mem:: drop ( channel_state_lock) ;
44634439 self . handle_monitor_update_completion_actions ( completion_action ( None ) ) ;
4464- return ClaimFundsFromHop :: MonitorUpdateFail ( counterparty_node_id, res, None ) ;
4440+ Err ( ( counterparty_node_id, res) )
44654441 } ,
44664442 }
44674443 } else {
@@ -4489,7 +4465,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44894465 // generally always allowed to be duplicative (and it's specifically noted in
44904466 // `PaymentForwarded`).
44914467 self . handle_monitor_update_completion_actions ( completion_action ( None ) ) ;
4492- return ClaimFundsFromHop :: PrevHopForceClosed
4468+ Ok ( ( ) )
44934469 }
44944470 }
44954471
@@ -4581,7 +4557,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
45814557 } } )
45824558 } else { None }
45834559 } ) ;
4584- if let ClaimFundsFromHop :: MonitorUpdateFail ( pk, err, _ ) = res {
4560+ if let Err ( ( pk, err) ) = res {
45854561 let result: Result < ( ) , _ > = Err ( err) ;
45864562 let _ = handle_error ! ( self , result, pk) ;
45874563 }
0 commit comments