@@ -309,6 +309,9 @@ pub struct CounterpartyForwardingInfo {
309309// Holder designates channel data owned for the benefice of the user client.
310310// Counterparty designates channel data owned by the another channel participant entity.
311311pub ( super ) struct Channel < Signer : Sign > {
312+ #[ cfg( any( test, feature = "_test_utils" ) ) ]
313+ pub ( crate ) config : ChannelConfig ,
314+ #[ cfg( not( any( test, feature = "_test_utils" ) ) ) ]
312315 config : ChannelConfig ,
313316
314317 user_id : u64 ,
@@ -1231,7 +1234,7 @@ impl<Signer: Sign> Channel<Signer> {
12311234 make_funding_redeemscript ( & self . get_holder_pubkeys ( ) . funding_pubkey , self . counterparty_funding_pubkey ( ) )
12321235 }
12331236
1234- 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 {
1237+ fn get_update_fulfill_htlc < L : Deref > ( & mut self , htlc_id_arg : u64 , payment_preimage_arg : PaymentPreimage , logger : & L ) -> ( Option < msgs:: UpdateFulfillHTLC > , Option < ( ChannelMonitorUpdate , u64 ) > ) where L :: Target : Logger {
12351238 // Either ChannelFunded got set (which means it won't be unset) or there is no way any
12361239 // caller thought we could have something claimed (cause we wouldn't have accepted in an
12371240 // incoming HTLC anyway). If we got to ShutdownComplete, callers aren't allowed to call us,
@@ -1248,6 +1251,7 @@ impl<Signer: Sign> Channel<Signer> {
12481251 // these, but for now we just have to treat them as normal.
12491252
12501253 let mut pending_idx = core:: usize:: MAX ;
1254+ let mut htlc_value_msat = 0 ;
12511255 for ( idx, htlc) in self . pending_inbound_htlcs . iter ( ) . enumerate ( ) {
12521256 if htlc. htlc_id == htlc_id_arg {
12531257 assert_eq ! ( htlc. payment_hash, payment_hash_calc) ;
@@ -1267,6 +1271,7 @@ impl<Signer: Sign> Channel<Signer> {
12671271 }
12681272 }
12691273 pending_idx = idx;
1274+ htlc_value_msat = htlc. amount_msat ;
12701275 break ;
12711276 }
12721277 }
@@ -1308,7 +1313,7 @@ impl<Signer: Sign> Channel<Signer> {
13081313 // TODO: We may actually be able to switch to a fulfill here, though its
13091314 // rare enough it may not be worth the complexity burden.
13101315 debug_assert ! ( false , "Tried to fulfill an HTLC that was already failed" ) ;
1311- return ( None , Some ( monitor_update) ) ;
1316+ return ( None , Some ( ( monitor_update, htlc_value_msat ) ) ) ;
13121317 }
13131318 } ,
13141319 _ => { }
@@ -1320,7 +1325,7 @@ impl<Signer: Sign> Channel<Signer> {
13201325 } ) ;
13211326 #[ cfg( any( test, feature = "fuzztarget" ) ) ]
13221327 self . historical_inbound_htlc_fulfills . insert ( htlc_id_arg) ;
1323- return ( None , Some ( monitor_update) ) ;
1328+ return ( None , Some ( ( monitor_update, htlc_value_msat ) ) ) ;
13241329 }
13251330 #[ cfg( any( test, feature = "fuzztarget" ) ) ]
13261331 self . historical_inbound_htlc_fulfills . insert ( htlc_id_arg) ;
@@ -1330,7 +1335,7 @@ impl<Signer: Sign> Channel<Signer> {
13301335 if let InboundHTLCState :: Committed = htlc. state {
13311336 } else {
13321337 debug_assert ! ( false , "Have an inbound HTLC we tried to claim before it was fully committed to" ) ;
1333- return ( None , Some ( monitor_update) ) ;
1338+ return ( None , Some ( ( monitor_update, htlc_value_msat ) ) ) ;
13341339 }
13351340 log_trace ! ( logger, "Upgrading HTLC {} to LocalRemoved with a Fulfill in channel {}!" , log_bytes!( htlc. payment_hash. 0 ) , log_bytes!( self . channel_id) ) ;
13361341 htlc. state = InboundHTLCState :: LocalRemoved ( InboundHTLCRemovalReason :: Fulfill ( payment_preimage_arg. clone ( ) ) ) ;
@@ -1340,12 +1345,14 @@ impl<Signer: Sign> Channel<Signer> {
13401345 channel_id : self . channel_id ( ) ,
13411346 htlc_id : htlc_id_arg,
13421347 payment_preimage : payment_preimage_arg,
1343- } ) , Some ( monitor_update) )
1348+ } ) , Some ( ( monitor_update, htlc_value_msat ) ) )
13441349 }
13451350
1346- 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 , ChannelMonitorUpdate ) > where L :: Target : Logger {
1351+ pub fn get_update_fulfill_htlc_and_commit < L : Deref > ( & mut self , htlc_id : u64 , payment_preimage : PaymentPreimage , logger : & L )
1352+ -> Result < ( Option < ( msgs:: UpdateFulfillHTLC , msgs:: CommitmentSigned ) > , Option < ( ChannelMonitorUpdate , u64 ) > ) ,
1353+ ( ChannelError , ChannelMonitorUpdate ) > where L :: Target : Logger {
13471354 match self . get_update_fulfill_htlc ( htlc_id, payment_preimage, logger) {
1348- ( Some ( update_fulfill_htlc) , Some ( mut monitor_update) ) => {
1355+ ( Some ( update_fulfill_htlc) , Some ( ( mut monitor_update, htlc_value_msat ) ) ) => {
13491356 let ( commitment, mut additional_update) = match self . send_commitment_no_status_check ( logger) {
13501357 Err ( e) => return Err ( ( e, monitor_update) ) ,
13511358 Ok ( res) => res
@@ -1354,14 +1361,14 @@ impl<Signer: Sign> Channel<Signer> {
13541361 // strictly increasing by one, so decrement it here.
13551362 self . latest_monitor_update_id = monitor_update. update_id ;
13561363 monitor_update. updates . append ( & mut additional_update. updates ) ;
1357- Ok ( ( Some ( ( update_fulfill_htlc, commitment) ) , Some ( monitor_update) ) )
1364+ Ok ( ( Some ( ( update_fulfill_htlc, commitment) ) , Some ( ( monitor_update, htlc_value_msat ) ) ) )
13581365 } ,
13591366 ( Some ( _) , None ) => {
13601367 // If we generated a claim message, we absolutely should have generated a
13611368 // ChannelMonitorUpdate, otherwise we are going to probably lose funds.
13621369 unreachable ! ( ) ;
13631370 } ,
1364- ( None , Some ( monitor_update ) ) => Ok ( ( None , Some ( monitor_update ) ) ) ,
1371+ ( None , Some ( monitor_and_value ) ) => Ok ( ( None , Some ( monitor_and_value ) ) ) ,
13651372 ( None , None ) => Ok ( ( None , None ) )
13661373 }
13671374 }
@@ -2138,7 +2145,7 @@ impl<Signer: Sign> Channel<Signer> {
21382145
21392146 /// Marks an outbound HTLC which we have received update_fail/fulfill/malformed
21402147 #[ inline]
2141- fn mark_outbound_htlc_removed ( & mut self , htlc_id : u64 , check_preimage : Option < PaymentHash > , fail_reason : Option < HTLCFailReason > ) -> Result < & HTLCSource , ChannelError > {
2148+ fn mark_outbound_htlc_removed ( & mut self , htlc_id : u64 , check_preimage : Option < PaymentHash > , fail_reason : Option < HTLCFailReason > ) -> Result < & OutboundHTLCOutput , ChannelError > {
21422149 for htlc in self . pending_outbound_htlcs . iter_mut ( ) {
21432150 if htlc. htlc_id == htlc_id {
21442151 match check_preimage {
@@ -2157,13 +2164,13 @@ impl<Signer: Sign> Channel<Signer> {
21572164 OutboundHTLCState :: AwaitingRemoteRevokeToRemove ( _) | OutboundHTLCState :: AwaitingRemovedRemoteRevoke ( _) | OutboundHTLCState :: RemoteRemoved ( _) =>
21582165 return Err ( ChannelError :: Close ( format ! ( "Remote tried to fulfill/fail HTLC ({}) that they'd already fulfilled/failed" , htlc_id) ) ) ,
21592166 }
2160- return Ok ( & htlc. source ) ;
2167+ return Ok ( htlc) ;
21612168 }
21622169 }
21632170 Err ( ChannelError :: Close ( "Remote tried to fulfill/fail an HTLC we couldn't find" . to_owned ( ) ) )
21642171 }
21652172
2166- pub fn update_fulfill_htlc ( & mut self , msg : & msgs:: UpdateFulfillHTLC ) -> Result < HTLCSource , ChannelError > {
2173+ pub fn update_fulfill_htlc ( & mut self , msg : & msgs:: UpdateFulfillHTLC ) -> Result < ( HTLCSource , u64 ) , ChannelError > {
21672174 if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
21682175 return Err ( ChannelError :: Close ( "Got fulfill HTLC message when channel was not in an operational state" . to_owned ( ) ) ) ;
21692176 }
@@ -2172,7 +2179,7 @@ impl<Signer: Sign> Channel<Signer> {
21722179 }
21732180
21742181 let payment_hash = PaymentHash ( Sha256 :: hash ( & msg. payment_preimage . 0 [ ..] ) . into_inner ( ) ) ;
2175- self . mark_outbound_htlc_removed ( msg. htlc_id , Some ( payment_hash) , None ) . map ( |source| source. clone ( ) )
2182+ self . mark_outbound_htlc_removed ( msg. htlc_id , Some ( payment_hash) , None ) . map ( |htlc| ( htlc . source . clone ( ) , htlc . amount_msat ) )
21762183 }
21772184
21782185 pub fn update_fail_htlc ( & mut self , msg : & msgs:: UpdateFailHTLC , fail_reason : HTLCFailReason ) -> Result < ( ) , ChannelError > {
@@ -2467,7 +2474,7 @@ impl<Signer: Sign> Channel<Signer> {
24672474 & HTLCUpdateAwaitingACK :: ClaimHTLC { ref payment_preimage, htlc_id, .. } => {
24682475 let ( update_fulfill_msg_option, additional_monitor_update_opt) = self . get_update_fulfill_htlc ( htlc_id, * payment_preimage, logger) ;
24692476 update_fulfill_htlcs. push ( update_fulfill_msg_option. unwrap ( ) ) ;
2470- if let Some ( mut additional_monitor_update) = additional_monitor_update_opt {
2477+ if let Some ( ( mut additional_monitor_update, _ ) ) = additional_monitor_update_opt {
24712478 monitor_update. updates . append ( & mut additional_monitor_update. updates ) ;
24722479 }
24732480 } ,
0 commit comments