@@ -118,9 +118,16 @@ pub(super) enum PendingHTLCStatus {
118
118
119
119
pub ( super ) enum HTLCForwardInfo {
120
120
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.
121
127
prev_short_channel_id : u64 ,
122
128
prev_htlc_id : u64 ,
123
- forward_info : PendingHTLCInfo ,
129
+ prev_channel_outpoint : OutPoint ,
130
+ prev_counterparty_node_id : PublicKey ,
124
131
} ,
125
132
FailHTLC {
126
133
htlc_id : u64 ,
@@ -134,6 +141,12 @@ pub(crate) struct HTLCPreviousHopData {
134
141
short_channel_id : u64 ,
135
142
htlc_id : u64 ,
136
143
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 ,
137
150
}
138
151
139
152
struct ClaimableHTLC {
@@ -1554,9 +1567,12 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
1554
1567
failed_forwards. reserve ( pending_forwards. len ( ) ) ;
1555
1568
for forward_info in pending_forwards. drain ( ..) {
1556
1569
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 } => {
1558
1572
let htlc_source = HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
1559
1573
short_channel_id : prev_short_channel_id,
1574
+ outpoint : prev_channel_outpoint,
1575
+ counterparty_node_id : prev_counterparty_node_id,
1560
1576
htlc_id : prev_htlc_id,
1561
1577
incoming_packet_shared_secret : forward_info. incoming_shared_secret ,
1562
1578
} ) ;
@@ -1583,10 +1599,13 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
1583
1599
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
1584
1600
routing : PendingHTLCRouting :: Forward {
1585
1601
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 } => {
1587
1604
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) ;
1588
1605
let htlc_source = HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
1589
1606
short_channel_id : prev_short_channel_id,
1607
+ outpoint : prev_channel_outpoint,
1608
+ counterparty_node_id : prev_counterparty_node_id,
1590
1609
htlc_id : prev_htlc_id,
1591
1610
incoming_packet_shared_secret : incoming_shared_secret,
1592
1611
} ) ;
@@ -1701,9 +1720,12 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
1701
1720
match forward_info {
1702
1721
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
1703
1722
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 } => {
1705
1725
let prev_hop = HTLCPreviousHopData {
1706
1726
short_channel_id : prev_short_channel_id,
1727
+ outpoint : prev_channel_outpoint,
1728
+ counterparty_node_id : prev_counterparty_node_id,
1707
1729
htlc_id : prev_htlc_id,
1708
1730
incoming_packet_shared_secret : incoming_shared_secret,
1709
1731
} ;
@@ -1738,6 +1760,8 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
1738
1760
) ;
1739
1761
failed_forwards. push ( ( HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
1740
1762
short_channel_id : htlc. prev_hop . short_channel_id ,
1763
+ outpoint : prev_channel_outpoint,
1764
+ counterparty_node_id : prev_counterparty_node_id,
1741
1765
htlc_id : htlc. prev_hop . htlc_id ,
1742
1766
incoming_packet_shared_secret : htlc. prev_hop . incoming_packet_shared_secret ,
1743
1767
} ) , payment_hash,
@@ -1940,7 +1964,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
1940
1964
}
1941
1965
}
1942
1966
} ,
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, .. } ) => {
1944
1968
let err_packet = match onion_error {
1945
1969
HTLCFailReason :: Reason { failure_code, data } => {
1946
1970
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>
2201
2225
2202
2226
let ( raa, commitment_update, order, pending_forwards, mut pending_failures, needs_broadcast_safe, funding_locked) = channel. monitor_updating_restored ( & self . logger ) ;
2203
2227
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) ) ;
2205
2229
}
2206
2230
htlc_failures. append ( & mut pending_failures) ;
2207
2231
@@ -2685,8 +2709,8 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
2685
2709
}
2686
2710
2687
2711
#[ 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 {
2690
2714
let mut forward_event = None ;
2691
2715
if !pending_forwards. is_empty ( ) {
2692
2716
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>
2699
2723
PendingHTLCRouting :: Receive { .. } => 0 ,
2700
2724
} ) {
2701
2725
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 } ) ;
2703
2728
} ,
2704
2729
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 } ) ) ;
2706
2732
}
2707
2733
}
2708
2734
}
@@ -2755,18 +2781,19 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
2755
2781
msg,
2756
2782
} ) ;
2757
2783
}
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 ( ) ) )
2759
2785
} ,
2760
2786
hash_map:: Entry :: Vacant ( _) => break Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
2761
2787
}
2762
2788
} ;
2763
2789
self . fail_holding_cell_htlcs ( htlcs_to_fail, msg. channel_id ) ;
2764
2790
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) ) => {
2766
2793
for failure in pending_failures. drain ( ..) {
2767
2794
self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , failure. 0 , & failure. 1 , failure. 2 ) ;
2768
2795
}
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) ] ) ;
2770
2797
Ok ( ( ) )
2771
2798
} ,
2772
2799
Err ( e) => Err ( e)
@@ -3543,6 +3570,8 @@ impl Readable for PendingHTLCStatus {
3543
3570
3544
3571
impl_writeable ! ( HTLCPreviousHopData , 0 , {
3545
3572
short_channel_id,
3573
+ outpoint,
3574
+ counterparty_node_id,
3546
3575
htlc_id,
3547
3576
incoming_packet_shared_secret
3548
3577
} ) ;
@@ -3619,9 +3648,11 @@ impl Readable for HTLCFailReason {
3619
3648
impl Writeable for HTLCForwardInfo {
3620
3649
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
3621
3650
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 } => {
3623
3652
0u8 . write ( writer) ?;
3624
3653
prev_short_channel_id. write ( writer) ?;
3654
+ prev_channel_outpoint. write ( writer) ?;
3655
+ prev_counterparty_node_id. write ( writer) ?;
3625
3656
prev_htlc_id. write ( writer) ?;
3626
3657
forward_info. write ( writer) ?;
3627
3658
} ,
@@ -3640,6 +3671,8 @@ impl Readable for HTLCForwardInfo {
3640
3671
match <u8 as Readable >:: read ( reader) ? {
3641
3672
0 => Ok ( HTLCForwardInfo :: AddHTLC {
3642
3673
prev_short_channel_id : Readable :: read ( reader) ?,
3674
+ prev_channel_outpoint : Readable :: read ( reader) ?,
3675
+ prev_counterparty_node_id : Readable :: read ( reader) ?,
3643
3676
prev_htlc_id : Readable :: read ( reader) ?,
3644
3677
forward_info : Readable :: read ( reader) ?,
3645
3678
} ) ,
0 commit comments