@@ -1232,7 +1232,7 @@ impl<Signer: Sign> Channel<Signer> {
12321232 make_funding_redeemscript ( & self . get_holder_pubkeys ( ) . funding_pubkey , self . counterparty_funding_pubkey ( ) )
12331233 }
12341234
1235- fn get_update_fulfill_htlc < L : Deref > ( & mut self , htlc_id_arg : u64 , payment_preimage_arg : PaymentPreimage , logger : & L ) -> ( Option < msgs:: UpdateFulfillHTLC > , Option < ChannelMonitorUpdate > ) where L :: Target : Logger {
1235+ fn get_update_fulfill_htlc < L : Deref > ( & mut self , htlc_id_arg : u64 , payment_preimage_arg : PaymentPreimage , logger : & L ) -> Option < ( Option < msgs:: UpdateFulfillHTLC > , ChannelMonitorUpdate ) > where L :: Target : Logger {
12361236 // Either ChannelFunded got set (which means it won't be unset) or there is no way any
12371237 // caller thought we could have something claimed (cause we wouldn't have accepted in an
12381238 // incoming HTLC anyway). If we got to ShutdownComplete, callers aren't allowed to call us,
@@ -1260,7 +1260,7 @@ impl<Signer: Sign> Channel<Signer> {
12601260 log_warn ! ( logger, "Have preimage and want to fulfill HTLC with payment hash {} we already failed against channel {}" , log_bytes!( htlc. payment_hash. 0 ) , log_bytes!( self . channel_id( ) ) ) ;
12611261 debug_assert ! ( false , "Tried to fulfill an HTLC that was already failed" ) ;
12621262 }
1263- return ( None , None ) ;
1263+ return None ;
12641264 } ,
12651265 _ => {
12661266 debug_assert ! ( false , "Have an inbound HTLC we tried to claim before it was fully committed to" ) ;
@@ -1276,7 +1276,7 @@ impl<Signer: Sign> Channel<Signer> {
12761276 // If we failed to find an HTLC to fulfill, make sure it was previously fulfilled and
12771277 // this is simply a duplicate claim, not previously failed and we lost funds.
12781278 debug_assert ! ( self . historical_inbound_htlc_fulfills. contains( & htlc_id_arg) ) ;
1279- return ( None , None ) ;
1279+ return None ;
12801280 }
12811281
12821282 // Now update local state:
@@ -1300,7 +1300,7 @@ impl<Signer: Sign> Channel<Signer> {
13001300 self . latest_monitor_update_id -= 1 ;
13011301 #[ cfg( any( test, feature = "fuzztarget" ) ) ]
13021302 debug_assert ! ( self . historical_inbound_htlc_fulfills. contains( & htlc_id_arg) ) ;
1303- return ( None , None ) ;
1303+ return None ;
13041304 }
13051305 } ,
13061306 & HTLCUpdateAwaitingACK :: FailHTLC { htlc_id, .. } => {
@@ -1309,7 +1309,7 @@ impl<Signer: Sign> Channel<Signer> {
13091309 // TODO: We may actually be able to switch to a fulfill here, though its
13101310 // rare enough it may not be worth the complexity burden.
13111311 debug_assert ! ( false , "Tried to fulfill an HTLC that was already failed" ) ;
1312- return ( None , Some ( monitor_update) ) ;
1312+ return Some ( ( None , monitor_update) ) ;
13131313 }
13141314 } ,
13151315 _ => { }
@@ -1321,7 +1321,7 @@ impl<Signer: Sign> Channel<Signer> {
13211321 } ) ;
13221322 #[ cfg( any( test, feature = "fuzztarget" ) ) ]
13231323 self . historical_inbound_htlc_fulfills . insert ( htlc_id_arg) ;
1324- return ( None , Some ( monitor_update) ) ;
1324+ return Some ( ( None , monitor_update) ) ;
13251325 }
13261326 #[ cfg( any( test, feature = "fuzztarget" ) ) ]
13271327 self . historical_inbound_htlc_fulfills . insert ( htlc_id_arg) ;
@@ -1331,36 +1331,31 @@ impl<Signer: Sign> Channel<Signer> {
13311331 if let InboundHTLCState :: Committed = htlc. state {
13321332 } else {
13331333 debug_assert ! ( false , "Have an inbound HTLC we tried to claim before it was fully committed to" ) ;
1334- return ( None , Some ( monitor_update) ) ;
1334+ return Some ( ( None , monitor_update) ) ;
13351335 }
13361336 log_trace ! ( logger, "Upgrading HTLC {} to LocalRemoved with a Fulfill in channel {}!" , log_bytes!( htlc. payment_hash. 0 ) , log_bytes!( self . channel_id) ) ;
13371337 htlc. state = InboundHTLCState :: LocalRemoved ( InboundHTLCRemovalReason :: Fulfill ( payment_preimage_arg. clone ( ) ) ) ;
13381338 }
13391339
1340- ( Some ( msgs:: UpdateFulfillHTLC {
1340+ Some ( ( Some ( msgs:: UpdateFulfillHTLC {
13411341 channel_id : self . channel_id ( ) ,
13421342 htlc_id : htlc_id_arg,
13431343 payment_preimage : payment_preimage_arg,
1344- } ) , Some ( monitor_update) )
1344+ } ) , monitor_update) )
13451345 }
13461346
1347- pub fn get_update_fulfill_htlc_and_commit < L : Deref > ( & mut self , htlc_id : u64 , payment_preimage : PaymentPreimage , logger : & L ) -> Result < ( Option < ( msgs:: UpdateFulfillHTLC , msgs:: CommitmentSigned ) > , Option < ChannelMonitorUpdate > ) , ChannelError > where L :: Target : Logger {
1347+ pub fn get_update_fulfill_htlc_and_commit < L : Deref > ( & mut self , htlc_id : u64 , payment_preimage : PaymentPreimage , logger : & L ) -> Result < Option < ( Option < ( msgs:: UpdateFulfillHTLC , msgs:: CommitmentSigned ) > , ChannelMonitorUpdate ) > , ChannelError > where L :: Target : Logger {
13481348 match self . get_update_fulfill_htlc ( htlc_id, payment_preimage, logger) {
1349- ( Some ( update_fulfill_htlc) , Some ( mut monitor_update) ) => {
1349+ Some ( ( Some ( update_fulfill_htlc) , mut monitor_update) ) => {
13501350 let ( commitment, mut additional_update) = self . send_commitment_no_status_check ( logger) ?;
13511351 // send_commitment_no_status_check may bump latest_monitor_id but we want them to be
13521352 // strictly increasing by one, so decrement it here.
13531353 self . latest_monitor_update_id = monitor_update. update_id ;
13541354 monitor_update. updates . append ( & mut additional_update. updates ) ;
1355- Ok ( ( Some ( ( update_fulfill_htlc, commitment) ) , Some ( monitor_update) ) )
1356- } ,
1357- ( Some ( _) , None ) => {
1358- // If we generated a claim message, we absolutely should have generated a
1359- // ChannelMonitorUpdate, otherwise we are going to probably lose funds.
1360- unreachable ! ( ) ;
1355+ Ok ( Some ( ( Some ( ( update_fulfill_htlc, commitment) ) , monitor_update) ) )
13611356 } ,
1362- ( None , Some ( monitor_update) ) => Ok ( ( None , Some ( monitor_update) ) ) ,
1363- ( None , None ) => Ok ( ( None , None ) )
1357+ Some ( ( None , monitor_update) ) => Ok ( Some ( ( None , monitor_update) ) ) ,
1358+ None => Ok ( None )
13641359 }
13651360 }
13661361
@@ -2468,11 +2463,9 @@ impl<Signer: Sign> Channel<Signer> {
24682463 // not fail - any in between attempts to claim the HTLC will have resulted
24692464 // in it hitting the holding cell again and we cannot change the state of a
24702465 // holding cell HTLC from fulfill to anything else.
2471- let ( update_fulfill_msg_option, additional_monitor_update_opt ) = self . get_update_fulfill_htlc ( htlc_id, * payment_preimage, logger) ;
2466+ let ( update_fulfill_msg_option, mut additional_monitor_update ) = self . get_update_fulfill_htlc ( htlc_id, * payment_preimage, logger) . unwrap ( ) ;
24722467 update_fulfill_htlcs. push ( update_fulfill_msg_option. unwrap ( ) ) ;
2473- if let Some ( mut additional_monitor_update) = additional_monitor_update_opt {
2474- monitor_update. updates . append ( & mut additional_monitor_update. updates ) ;
2475- }
2468+ monitor_update. updates . append ( & mut additional_monitor_update. updates ) ;
24762469 } ,
24772470 & HTLCUpdateAwaitingACK :: FailHTLC { htlc_id, ref err_packet } => {
24782471 match self . get_update_fail_htlc ( htlc_id, err_packet. clone ( ) , logger) {
0 commit comments