@@ -118,9 +118,16 @@ 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_channel_outpoint : OutPoint ,
130+ prev_counterparty_node_id : PublicKey ,
124131 } ,
125132 FailHTLC {
126133 htlc_id : u64 ,
@@ -134,6 +141,12 @@ pub(crate) struct HTLCPreviousHopData {
134141 short_channel_id : u64 ,
135142 htlc_id : u64 ,
136143 incoming_packet_shared_secret : [ u8 ; 32 ] ,
144+
145+ // These fields are consumed by `claim_funds_from_hop()` when updating a
146+ // force-closed backwards channel with a preimage provided by the forward
147+ // channel.
148+ outpoint : OutPoint ,
149+ counterparty_node_id : PublicKey ,
137150}
138151
139152struct ClaimableHTLC {
@@ -1554,9 +1567,12 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
15541567 failed_forwards. reserve ( pending_forwards. len ( ) ) ;
15551568 for forward_info in pending_forwards. drain ( ..) {
15561569 match forward_info {
1557- HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info } => {
1570+ HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info,
1571+ prev_channel_outpoint, prev_counterparty_node_id } => {
15581572 let htlc_source = HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
15591573 short_channel_id : prev_short_channel_id,
1574+ outpoint : prev_channel_outpoint,
1575+ counterparty_node_id : prev_counterparty_node_id,
15601576 htlc_id : prev_htlc_id,
15611577 incoming_packet_shared_secret : forward_info. incoming_shared_secret ,
15621578 } ) ;
@@ -1583,10 +1599,13 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
15831599 HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
15841600 routing : PendingHTLCRouting :: Forward {
15851601 onion_packet, ..
1586- } , incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value } , } => {
1602+ } , incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value } ,
1603+ prev_channel_outpoint, prev_counterparty_node_id } => {
15871604 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) ;
15881605 let htlc_source = HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
15891606 short_channel_id : prev_short_channel_id,
1607+ outpoint : prev_channel_outpoint,
1608+ counterparty_node_id : prev_counterparty_node_id,
15901609 htlc_id : prev_htlc_id,
15911610 incoming_packet_shared_secret : incoming_shared_secret,
15921611 } ) ;
@@ -1701,9 +1720,12 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
17011720 match forward_info {
17021721 HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
17031722 routing : PendingHTLCRouting :: Receive { payment_data, incoming_cltv_expiry } ,
1704- incoming_shared_secret, payment_hash, amt_to_forward, .. } , } => {
1723+ incoming_shared_secret, payment_hash, amt_to_forward, .. } ,
1724+ prev_channel_outpoint, prev_counterparty_node_id } => {
17051725 let prev_hop = HTLCPreviousHopData {
17061726 short_channel_id : prev_short_channel_id,
1727+ outpoint : prev_channel_outpoint,
1728+ counterparty_node_id : prev_counterparty_node_id,
17071729 htlc_id : prev_htlc_id,
17081730 incoming_packet_shared_secret : incoming_shared_secret,
17091731 } ;
@@ -1738,6 +1760,8 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
17381760 ) ;
17391761 failed_forwards. push ( ( HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
17401762 short_channel_id : htlc. prev_hop . short_channel_id ,
1763+ outpoint : prev_channel_outpoint,
1764+ counterparty_node_id : prev_counterparty_node_id,
17411765 htlc_id : htlc. prev_hop . htlc_id ,
17421766 incoming_packet_shared_secret : htlc. prev_hop . incoming_packet_shared_secret ,
17431767 } ) , payment_hash,
@@ -1940,7 +1964,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
19401964 }
19411965 }
19421966 } ,
1943- HTLCSource :: PreviousHopData ( HTLCPreviousHopData { short_channel_id, htlc_id, incoming_packet_shared_secret } ) => {
1967+ HTLCSource :: PreviousHopData ( HTLCPreviousHopData { short_channel_id, htlc_id, incoming_packet_shared_secret, .. } ) => {
19441968 let err_packet = match onion_error {
19451969 HTLCFailReason :: Reason { failure_code, data } => {
19461970 log_trace ! ( self . logger, "Failing HTLC with payment_hash {} backwards from us with code {}" , log_bytes!( payment_hash. 0 ) , failure_code) ;
@@ -2201,7 +2225,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
22012225
22022226 let ( raa, commitment_update, order, pending_forwards, mut pending_failures, needs_broadcast_safe, funding_locked) = channel. monitor_updating_restored ( & self . logger ) ;
22032227 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) ) ;
2228+ htlc_forwards. push ( ( channel. get_short_channel_id ( ) . expect ( "We can't have pending forwards before funding confirmation" ) , funding_txo . clone ( ) , channel . get_counterparty_node_id ( ) , pending_forwards) ) ;
22052229 }
22062230 htlc_failures. append ( & mut pending_failures) ;
22072231
@@ -2685,8 +2709,8 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
26852709 }
26862710
26872711 #[ 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 {
2712+ fn forward_htlcs ( & self , per_source_pending_forwards : & mut [ ( u64 , OutPoint , PublicKey , Vec < ( PendingHTLCInfo , u64 ) > ) ] ) {
2713+ for & mut ( prev_short_channel_id, prev_channel_outpoint , prev_counterparty_node_id , ref mut pending_forwards) in per_source_pending_forwards {
26902714 let mut forward_event = None ;
26912715 if !pending_forwards. is_empty ( ) {
26922716 let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
@@ -2699,10 +2723,12 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
26992723 PendingHTLCRouting :: Receive { .. } => 0 ,
27002724 } ) {
27012725 hash_map:: Entry :: Occupied ( mut entry) => {
2702- entry. get_mut ( ) . push ( HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info } ) ;
2726+ entry. get_mut ( ) . push ( HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_channel_outpoint,
2727+ prev_htlc_id, forward_info, prev_counterparty_node_id } ) ;
27032728 } ,
27042729 hash_map:: Entry :: Vacant ( entry) => {
2705- entry. insert ( vec ! ( HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info } ) ) ;
2730+ entry. insert ( vec ! ( HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_channel_outpoint, prev_htlc_id,
2731+ forward_info, prev_counterparty_node_id } ) ) ;
27062732 }
27072733 }
27082734 }
@@ -2755,18 +2781,19 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
27552781 msg,
27562782 } ) ;
27572783 }
2758- break Ok ( ( pending_forwards, pending_failures, chan. get ( ) . get_short_channel_id ( ) . expect ( "RAA should only work on a short-id-available channel" ) ) )
2784+ 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 ( ) , chan . get ( ) . get_counterparty_node_id ( ) ) )
27592785 } ,
27602786 hash_map:: Entry :: Vacant ( _) => break Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
27612787 }
27622788 } ;
27632789 self . fail_holding_cell_htlcs ( htlcs_to_fail, msg. channel_id ) ;
27642790 match res {
2765- Ok ( ( pending_forwards, mut pending_failures, short_channel_id) ) => {
2791+ Ok ( ( pending_forwards, mut pending_failures, short_channel_id, channel_outpoint,
2792+ counterparty_node_id) ) => {
27662793 for failure in pending_failures. drain ( ..) {
27672794 self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , failure. 0 , & failure. 1 , failure. 2 ) ;
27682795 }
2769- self . forward_htlcs ( & mut [ ( short_channel_id, pending_forwards) ] ) ;
2796+ self . forward_htlcs ( & mut [ ( short_channel_id, channel_outpoint , counterparty_node_id , pending_forwards) ] ) ;
27702797 Ok ( ( ) )
27712798 } ,
27722799 Err ( e) => Err ( e)
@@ -3543,6 +3570,8 @@ impl Readable for PendingHTLCStatus {
35433570
35443571impl_writeable ! ( HTLCPreviousHopData , 0 , {
35453572 short_channel_id,
3573+ outpoint,
3574+ counterparty_node_id,
35463575 htlc_id,
35473576 incoming_packet_shared_secret
35483577} ) ;
@@ -3619,9 +3648,11 @@ impl Readable for HTLCFailReason {
36193648impl Writeable for HTLCForwardInfo {
36203649 fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
36213650 match self {
3622- & HTLCForwardInfo :: AddHTLC { ref prev_short_channel_id, ref prev_htlc_id, ref forward_info } => {
3651+ & HTLCForwardInfo :: AddHTLC { ref prev_short_channel_id, ref prev_channel_outpoint , ref prev_counterparty_node_id , ref prev_htlc_id, ref forward_info } => {
36233652 0u8 . write ( writer) ?;
36243653 prev_short_channel_id. write ( writer) ?;
3654+ prev_channel_outpoint. write ( writer) ?;
3655+ prev_counterparty_node_id. write ( writer) ?;
36253656 prev_htlc_id. write ( writer) ?;
36263657 forward_info. write ( writer) ?;
36273658 } ,
@@ -3640,6 +3671,8 @@ impl Readable for HTLCForwardInfo {
36403671 match <u8 as Readable >:: read ( reader) ? {
36413672 0 => Ok ( HTLCForwardInfo :: AddHTLC {
36423673 prev_short_channel_id : Readable :: read ( reader) ?,
3674+ prev_channel_outpoint : Readable :: read ( reader) ?,
3675+ prev_counterparty_node_id : Readable :: read ( reader) ?,
36433676 prev_htlc_id : Readable :: read ( reader) ?,
36443677 forward_info : Readable :: read ( reader) ?,
36453678 } ) ,
0 commit comments