@@ -306,6 +306,7 @@ pub struct CounterpartyForwardingInfo {
306306enum UpdateFulfillFetch {
307307 NewClaim {
308308 monitor_update : ChannelMonitorUpdate ,
309+ htlc_value_msat : u64 ,
309310 msg : Option < msgs:: UpdateFulfillHTLC > ,
310311 } ,
311312 DuplicateClaim { } ,
@@ -319,6 +320,8 @@ pub enum UpdateFulfillCommitFetch {
319320 NewClaim {
320321 /// The ChannelMonitorUpdate which places the new payment preimage in the channel monitor
321322 monitor_update : ChannelMonitorUpdate ,
323+ /// The value of the HTLC which was claimed, in msat.
324+ htlc_value_msat : u64 ,
322325 /// The update_fulfill message and commitment_signed message (if the claim was not placed
323326 /// in the holding cell).
324327 msgs : Option < ( msgs:: UpdateFulfillHTLC , msgs:: CommitmentSigned ) > ,
@@ -336,6 +339,9 @@ pub enum UpdateFulfillCommitFetch {
336339// Holder designates channel data owned for the benefice of the user client.
337340// Counterparty designates channel data owned by the another channel participant entity.
338341pub ( super ) struct Channel < Signer : Sign > {
342+ #[ cfg( any( test, feature = "_test_utils" ) ) ]
343+ pub ( crate ) config : ChannelConfig ,
344+ #[ cfg( not( any( test, feature = "_test_utils" ) ) ) ]
339345 config : ChannelConfig ,
340346
341347 user_id : u64 ,
@@ -1275,6 +1281,7 @@ impl<Signer: Sign> Channel<Signer> {
12751281 // these, but for now we just have to treat them as normal.
12761282
12771283 let mut pending_idx = core:: usize:: MAX ;
1284+ let mut htlc_value_msat = 0 ;
12781285 for ( idx, htlc) in self . pending_inbound_htlcs . iter ( ) . enumerate ( ) {
12791286 if htlc. htlc_id == htlc_id_arg {
12801287 assert_eq ! ( htlc. payment_hash, payment_hash_calc) ;
@@ -1294,6 +1301,7 @@ impl<Signer: Sign> Channel<Signer> {
12941301 }
12951302 }
12961303 pending_idx = idx;
1304+ htlc_value_msat = htlc. amount_msat ;
12971305 break ;
12981306 }
12991307 }
@@ -1335,7 +1343,7 @@ impl<Signer: Sign> Channel<Signer> {
13351343 // TODO: We may actually be able to switch to a fulfill here, though its
13361344 // rare enough it may not be worth the complexity burden.
13371345 debug_assert ! ( false , "Tried to fulfill an HTLC that was already failed" ) ;
1338- return UpdateFulfillFetch :: NewClaim { monitor_update, msg : None } ;
1346+ return UpdateFulfillFetch :: NewClaim { monitor_update, htlc_value_msat , msg : None } ;
13391347 }
13401348 } ,
13411349 _ => { }
@@ -1347,7 +1355,7 @@ impl<Signer: Sign> Channel<Signer> {
13471355 } ) ;
13481356 #[ cfg( any( test, feature = "fuzztarget" ) ) ]
13491357 self . historical_inbound_htlc_fulfills . insert ( htlc_id_arg) ;
1350- return UpdateFulfillFetch :: NewClaim { monitor_update, msg : None } ;
1358+ return UpdateFulfillFetch :: NewClaim { monitor_update, htlc_value_msat , msg : None } ;
13511359 }
13521360 #[ cfg( any( test, feature = "fuzztarget" ) ) ]
13531361 self . historical_inbound_htlc_fulfills . insert ( htlc_id_arg) ;
@@ -1357,14 +1365,15 @@ impl<Signer: Sign> Channel<Signer> {
13571365 if let InboundHTLCState :: Committed = htlc. state {
13581366 } else {
13591367 debug_assert ! ( false , "Have an inbound HTLC we tried to claim before it was fully committed to" ) ;
1360- return UpdateFulfillFetch :: NewClaim { monitor_update, msg : None } ;
1368+ return UpdateFulfillFetch :: NewClaim { monitor_update, htlc_value_msat , msg : None } ;
13611369 }
13621370 log_trace ! ( logger, "Upgrading HTLC {} to LocalRemoved with a Fulfill in channel {}!" , log_bytes!( htlc. payment_hash. 0 ) , log_bytes!( self . channel_id) ) ;
13631371 htlc. state = InboundHTLCState :: LocalRemoved ( InboundHTLCRemovalReason :: Fulfill ( payment_preimage_arg. clone ( ) ) ) ;
13641372 }
13651373
13661374 UpdateFulfillFetch :: NewClaim {
13671375 monitor_update,
1376+ htlc_value_msat,
13681377 msg : Some ( msgs:: UpdateFulfillHTLC {
13691378 channel_id : self . channel_id ( ) ,
13701379 htlc_id : htlc_id_arg,
@@ -1375,7 +1384,7 @@ impl<Signer: Sign> Channel<Signer> {
13751384
13761385 pub fn get_update_fulfill_htlc_and_commit < L : Deref > ( & mut self , htlc_id : u64 , payment_preimage : PaymentPreimage , logger : & L ) -> Result < UpdateFulfillCommitFetch , ( ChannelError , ChannelMonitorUpdate ) > where L :: Target : Logger {
13771386 match self . get_update_fulfill_htlc ( htlc_id, payment_preimage, logger) {
1378- UpdateFulfillFetch :: NewClaim { mut monitor_update, msg : Some ( update_fulfill_htlc) } => {
1387+ UpdateFulfillFetch :: NewClaim { mut monitor_update, htlc_value_msat , msg : Some ( update_fulfill_htlc) } => {
13791388 let ( commitment, mut additional_update) = match self . send_commitment_no_status_check ( logger) {
13801389 Err ( e) => return Err ( ( e, monitor_update) ) ,
13811390 Ok ( res) => res
@@ -1384,9 +1393,10 @@ impl<Signer: Sign> Channel<Signer> {
13841393 // strictly increasing by one, so decrement it here.
13851394 self . latest_monitor_update_id = monitor_update. update_id ;
13861395 monitor_update. updates . append ( & mut additional_update. updates ) ;
1387- Ok ( UpdateFulfillCommitFetch :: NewClaim { monitor_update, msgs : Some ( ( update_fulfill_htlc, commitment) ) } )
1396+ Ok ( UpdateFulfillCommitFetch :: NewClaim { monitor_update, htlc_value_msat , msgs : Some ( ( update_fulfill_htlc, commitment) ) } )
13881397 } ,
1389- UpdateFulfillFetch :: NewClaim { monitor_update, msg : None } => Ok ( UpdateFulfillCommitFetch :: NewClaim { monitor_update, msgs : None } ) ,
1398+ UpdateFulfillFetch :: NewClaim { monitor_update, htlc_value_msat, msg : None } =>
1399+ Ok ( UpdateFulfillCommitFetch :: NewClaim { monitor_update, htlc_value_msat, msgs : None } ) ,
13901400 UpdateFulfillFetch :: DuplicateClaim { } => Ok ( UpdateFulfillCommitFetch :: DuplicateClaim { } ) ,
13911401 }
13921402 }
@@ -2163,7 +2173,7 @@ impl<Signer: Sign> Channel<Signer> {
21632173
21642174 /// Marks an outbound HTLC which we have received update_fail/fulfill/malformed
21652175 #[ inline]
2166- fn mark_outbound_htlc_removed ( & mut self , htlc_id : u64 , check_preimage : Option < PaymentHash > , fail_reason : Option < HTLCFailReason > ) -> Result < & HTLCSource , ChannelError > {
2176+ fn mark_outbound_htlc_removed ( & mut self , htlc_id : u64 , check_preimage : Option < PaymentHash > , fail_reason : Option < HTLCFailReason > ) -> Result < & OutboundHTLCOutput , ChannelError > {
21672177 for htlc in self . pending_outbound_htlcs . iter_mut ( ) {
21682178 if htlc. htlc_id == htlc_id {
21692179 match check_preimage {
@@ -2182,13 +2192,13 @@ impl<Signer: Sign> Channel<Signer> {
21822192 OutboundHTLCState :: AwaitingRemoteRevokeToRemove ( _) | OutboundHTLCState :: AwaitingRemovedRemoteRevoke ( _) | OutboundHTLCState :: RemoteRemoved ( _) =>
21832193 return Err ( ChannelError :: Close ( format ! ( "Remote tried to fulfill/fail HTLC ({}) that they'd already fulfilled/failed" , htlc_id) ) ) ,
21842194 }
2185- return Ok ( & htlc. source ) ;
2195+ return Ok ( htlc) ;
21862196 }
21872197 }
21882198 Err ( ChannelError :: Close ( "Remote tried to fulfill/fail an HTLC we couldn't find" . to_owned ( ) ) )
21892199 }
21902200
2191- pub fn update_fulfill_htlc ( & mut self , msg : & msgs:: UpdateFulfillHTLC ) -> Result < HTLCSource , ChannelError > {
2201+ pub fn update_fulfill_htlc ( & mut self , msg : & msgs:: UpdateFulfillHTLC ) -> Result < ( HTLCSource , u64 ) , ChannelError > {
21922202 if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
21932203 return Err ( ChannelError :: Close ( "Got fulfill HTLC message when channel was not in an operational state" . to_owned ( ) ) ) ;
21942204 }
@@ -2197,7 +2207,7 @@ impl<Signer: Sign> Channel<Signer> {
21972207 }
21982208
21992209 let payment_hash = PaymentHash ( Sha256 :: hash ( & msg. payment_preimage . 0 [ ..] ) . into_inner ( ) ) ;
2200- self . mark_outbound_htlc_removed ( msg. htlc_id , Some ( payment_hash) , None ) . map ( |source| source. clone ( ) )
2210+ self . mark_outbound_htlc_removed ( msg. htlc_id , Some ( payment_hash) , None ) . map ( |htlc| ( htlc . source . clone ( ) , htlc . amount_msat ) )
22012211 }
22022212
22032213 pub fn update_fail_htlc ( & mut self , msg : & msgs:: UpdateFailHTLC , fail_reason : HTLCFailReason ) -> Result < ( ) , ChannelError > {
@@ -2496,7 +2506,7 @@ impl<Signer: Sign> Channel<Signer> {
24962506 // in it hitting the holding cell again and we cannot change the state of a
24972507 // holding cell HTLC from fulfill to anything else.
24982508 let ( update_fulfill_msg_option, mut additional_monitor_update) =
2499- if let UpdateFulfillFetch :: NewClaim { msg, monitor_update } = self . get_update_fulfill_htlc ( htlc_id, * payment_preimage, logger) {
2509+ if let UpdateFulfillFetch :: NewClaim { msg, monitor_update, .. } = self . get_update_fulfill_htlc ( htlc_id, * payment_preimage, logger) {
25002510 ( msg, monitor_update)
25012511 } else { unreachable ! ( ) } ;
25022512 update_fulfill_htlcs. push ( update_fulfill_msg_option. unwrap ( ) ) ;
0 commit comments