@@ -118,9 +118,15 @@ pub(super) enum PendingHTLCStatus {
118118
119119pub ( super ) enum HTLCForwardInfo {
120120 AddHTLC {
121+ forward_info : PendingHTLCInfo ,
122+
123+ // These fields are produced in `forward_htlcs()` and consumed in
124+ // `process_pending_htlc_forwards()` for constructing the
125+ // `HTLCSource::PreviousHopData` for failed and forwarded
126+ // HTLCs.
121127 prev_short_channel_id : u64 ,
122128 prev_htlc_id : u64 ,
123- forward_info : PendingHTLCInfo ,
129+ prev_funding_outpoint : OutPoint ,
124130 } ,
125131 FailHTLC {
126132 htlc_id : u64 ,
@@ -134,6 +140,10 @@ pub(crate) struct HTLCPreviousHopData {
134140 short_channel_id : u64 ,
135141 htlc_id : u64 ,
136142 incoming_packet_shared_secret : [ u8 ; 32 ] ,
143+
144+ // This field is consumed by `claim_funds_from_hop()` when updating a force-closed backwards
145+ // channel with a preimage provided by the forward channel.
146+ outpoint : OutPoint ,
137147}
138148
139149struct ClaimableHTLC {
@@ -1554,9 +1564,11 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
15541564 failed_forwards. reserve ( pending_forwards. len ( ) ) ;
15551565 for forward_info in pending_forwards. drain ( ..) {
15561566 match forward_info {
1557- HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info } => {
1567+ HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info,
1568+ prev_funding_outpoint } => {
15581569 let htlc_source = HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
15591570 short_channel_id : prev_short_channel_id,
1571+ outpoint : prev_funding_outpoint,
15601572 htlc_id : prev_htlc_id,
15611573 incoming_packet_shared_secret : forward_info. incoming_shared_secret ,
15621574 } ) ;
@@ -1583,10 +1595,12 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
15831595 HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
15841596 routing : PendingHTLCRouting :: Forward {
15851597 onion_packet, ..
1586- } , incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value } , } => {
1598+ } , incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value } ,
1599+ prev_funding_outpoint } => {
15871600 log_trace ! ( self . logger, "Adding HTLC from short id {} with payment_hash {} to channel with short id {} after delay" , log_bytes!( payment_hash. 0 ) , prev_short_channel_id, short_chan_id) ;
15881601 let htlc_source = HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
15891602 short_channel_id : prev_short_channel_id,
1603+ outpoint : prev_funding_outpoint,
15901604 htlc_id : prev_htlc_id,
15911605 incoming_packet_shared_secret : incoming_shared_secret,
15921606 } ) ;
@@ -1701,9 +1715,11 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
17011715 match forward_info {
17021716 HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
17031717 routing : PendingHTLCRouting :: Receive { payment_data, incoming_cltv_expiry } ,
1704- incoming_shared_secret, payment_hash, amt_to_forward, .. } , } => {
1718+ incoming_shared_secret, payment_hash, amt_to_forward, .. } ,
1719+ prev_funding_outpoint } => {
17051720 let prev_hop = HTLCPreviousHopData {
17061721 short_channel_id : prev_short_channel_id,
1722+ outpoint : prev_funding_outpoint,
17071723 htlc_id : prev_htlc_id,
17081724 incoming_packet_shared_secret : incoming_shared_secret,
17091725 } ;
@@ -1738,6 +1754,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
17381754 ) ;
17391755 failed_forwards. push ( ( HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
17401756 short_channel_id : htlc. prev_hop . short_channel_id ,
1757+ outpoint : prev_funding_outpoint,
17411758 htlc_id : htlc. prev_hop . htlc_id ,
17421759 incoming_packet_shared_secret : htlc. prev_hop . incoming_packet_shared_secret ,
17431760 } ) , payment_hash,
@@ -1940,7 +1957,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
19401957 }
19411958 }
19421959 } ,
1943- HTLCSource :: PreviousHopData ( HTLCPreviousHopData { short_channel_id, htlc_id, incoming_packet_shared_secret } ) => {
1960+ HTLCSource :: PreviousHopData ( HTLCPreviousHopData { short_channel_id, htlc_id, incoming_packet_shared_secret, .. } ) => {
19441961 let err_packet = match onion_error {
19451962 HTLCFailReason :: Reason { failure_code, data } => {
19461963 log_trace ! ( self . logger, "Failing HTLC with payment_hash {} backwards from us with code {}" , log_bytes!( payment_hash. 0 ) , failure_code) ;
@@ -2201,7 +2218,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
22012218
22022219 let ( raa, commitment_update, order, pending_forwards, mut pending_failures, needs_broadcast_safe, funding_locked) = channel. monitor_updating_restored ( & self . logger ) ;
22032220 if !pending_forwards. is_empty ( ) {
2204- htlc_forwards. push ( ( channel. get_short_channel_id ( ) . expect ( "We can't have pending forwards before funding confirmation" ) , pending_forwards) ) ;
2221+ htlc_forwards. push ( ( channel. get_short_channel_id ( ) . expect ( "We can't have pending forwards before funding confirmation" ) , funding_txo . clone ( ) , pending_forwards) ) ;
22052222 }
22062223 htlc_failures. append ( & mut pending_failures) ;
22072224
@@ -2685,8 +2702,8 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
26852702 }
26862703
26872704 #[ inline]
2688- fn forward_htlcs ( & self , per_source_pending_forwards : & mut [ ( u64 , Vec < ( PendingHTLCInfo , u64 ) > ) ] ) {
2689- for & mut ( prev_short_channel_id, ref mut pending_forwards) in per_source_pending_forwards {
2705+ fn forward_htlcs ( & self , per_source_pending_forwards : & mut [ ( u64 , OutPoint , Vec < ( PendingHTLCInfo , u64 ) > ) ] ) {
2706+ for & mut ( prev_short_channel_id, prev_funding_outpoint , ref mut pending_forwards) in per_source_pending_forwards {
26902707 let mut forward_event = None ;
26912708 if !pending_forwards. is_empty ( ) {
26922709 let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
@@ -2699,10 +2716,12 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
26992716 PendingHTLCRouting :: Receive { .. } => 0 ,
27002717 } ) {
27012718 hash_map:: Entry :: Occupied ( mut entry) => {
2702- entry. get_mut ( ) . push ( HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info } ) ;
2719+ entry. get_mut ( ) . push ( HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_funding_outpoint,
2720+ prev_htlc_id, forward_info } ) ;
27032721 } ,
27042722 hash_map:: Entry :: Vacant ( entry) => {
2705- entry. insert ( vec ! ( HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info } ) ) ;
2723+ entry. insert ( vec ! ( HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_funding_outpoint,
2724+ prev_htlc_id, forward_info } ) ) ;
27062725 }
27072726 }
27082727 }
@@ -2755,18 +2774,18 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
27552774 msg,
27562775 } ) ;
27572776 }
2758- break Ok ( ( pending_forwards, pending_failures, chan. get ( ) . get_short_channel_id ( ) . expect ( "RAA should only work on a short-id-available channel" ) ) )
2777+ break Ok ( ( pending_forwards, pending_failures, chan. get ( ) . get_short_channel_id ( ) . expect ( "RAA should only work on a short-id-available channel" ) , chan . get ( ) . get_funding_txo ( ) . unwrap ( ) ) )
27592778 } ,
27602779 hash_map:: Entry :: Vacant ( _) => break Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
27612780 }
27622781 } ;
27632782 self . fail_holding_cell_htlcs ( htlcs_to_fail, msg. channel_id ) ;
27642783 match res {
2765- Ok ( ( pending_forwards, mut pending_failures, short_channel_id) ) => {
2784+ Ok ( ( pending_forwards, mut pending_failures, short_channel_id, channel_outpoint ) ) => {
27662785 for failure in pending_failures. drain ( ..) {
27672786 self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , failure. 0 , & failure. 1 , failure. 2 ) ;
27682787 }
2769- self . forward_htlcs ( & mut [ ( short_channel_id, pending_forwards) ] ) ;
2788+ self . forward_htlcs ( & mut [ ( short_channel_id, channel_outpoint , pending_forwards) ] ) ;
27702789 Ok ( ( ) )
27712790 } ,
27722791 Err ( e) => Err ( e)
@@ -3543,6 +3562,7 @@ impl Readable for PendingHTLCStatus {
35433562
35443563impl_writeable ! ( HTLCPreviousHopData , 0 , {
35453564 short_channel_id,
3565+ outpoint,
35463566 htlc_id,
35473567 incoming_packet_shared_secret
35483568} ) ;
@@ -3619,9 +3639,10 @@ impl Readable for HTLCFailReason {
36193639impl Writeable for HTLCForwardInfo {
36203640 fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
36213641 match self {
3622- & HTLCForwardInfo :: AddHTLC { ref prev_short_channel_id, ref prev_htlc_id, ref forward_info } => {
3642+ & HTLCForwardInfo :: AddHTLC { ref prev_short_channel_id, ref prev_funding_outpoint , ref prev_htlc_id, ref forward_info } => {
36233643 0u8 . write ( writer) ?;
36243644 prev_short_channel_id. write ( writer) ?;
3645+ prev_funding_outpoint. write ( writer) ?;
36253646 prev_htlc_id. write ( writer) ?;
36263647 forward_info. write ( writer) ?;
36273648 } ,
@@ -3640,6 +3661,7 @@ impl Readable for HTLCForwardInfo {
36403661 match <u8 as Readable >:: read ( reader) ? {
36413662 0 => Ok ( HTLCForwardInfo :: AddHTLC {
36423663 prev_short_channel_id : Readable :: read ( reader) ?,
3664+ prev_funding_outpoint : Readable :: read ( reader) ?,
36433665 prev_htlc_id : Readable :: read ( reader) ?,
36443666 forward_info : Readable :: read ( reader) ?,
36453667 } ) ,
0 commit comments