@@ -118,9 +118,15 @@ 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_funding_outpoint : OutPoint ,
124
130
} ,
125
131
FailHTLC {
126
132
htlc_id : u64 ,
@@ -134,6 +140,10 @@ pub(crate) struct HTLCPreviousHopData {
134
140
short_channel_id : u64 ,
135
141
htlc_id : u64 ,
136
142
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 ,
137
147
}
138
148
139
149
struct ClaimableHTLC {
@@ -1554,9 +1564,11 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
1554
1564
failed_forwards. reserve ( pending_forwards. len ( ) ) ;
1555
1565
for forward_info in pending_forwards. drain ( ..) {
1556
1566
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 } => {
1558
1569
let htlc_source = HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
1559
1570
short_channel_id : prev_short_channel_id,
1571
+ outpoint : prev_funding_outpoint,
1560
1572
htlc_id : prev_htlc_id,
1561
1573
incoming_packet_shared_secret : forward_info. incoming_shared_secret ,
1562
1574
} ) ;
@@ -1583,10 +1595,12 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
1583
1595
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
1584
1596
routing : PendingHTLCRouting :: Forward {
1585
1597
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 } => {
1587
1600
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
1601
let htlc_source = HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
1589
1602
short_channel_id : prev_short_channel_id,
1603
+ outpoint : prev_funding_outpoint,
1590
1604
htlc_id : prev_htlc_id,
1591
1605
incoming_packet_shared_secret : incoming_shared_secret,
1592
1606
} ) ;
@@ -1701,9 +1715,11 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
1701
1715
match forward_info {
1702
1716
HTLCForwardInfo :: AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info : PendingHTLCInfo {
1703
1717
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 } => {
1705
1720
let prev_hop = HTLCPreviousHopData {
1706
1721
short_channel_id : prev_short_channel_id,
1722
+ outpoint : prev_funding_outpoint,
1707
1723
htlc_id : prev_htlc_id,
1708
1724
incoming_packet_shared_secret : incoming_shared_secret,
1709
1725
} ;
@@ -1738,6 +1754,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
1738
1754
) ;
1739
1755
failed_forwards. push ( ( HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
1740
1756
short_channel_id : htlc. prev_hop . short_channel_id ,
1757
+ outpoint : prev_funding_outpoint,
1741
1758
htlc_id : htlc. prev_hop . htlc_id ,
1742
1759
incoming_packet_shared_secret : htlc. prev_hop . incoming_packet_shared_secret ,
1743
1760
} ) , payment_hash,
@@ -1940,7 +1957,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
1940
1957
}
1941
1958
}
1942
1959
} ,
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, .. } ) => {
1944
1961
let err_packet = match onion_error {
1945
1962
HTLCFailReason :: Reason { failure_code, data } => {
1946
1963
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>
2201
2218
2202
2219
let ( raa, commitment_update, order, pending_forwards, mut pending_failures, needs_broadcast_safe, funding_locked) = channel. monitor_updating_restored ( & self . logger ) ;
2203
2220
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) ) ;
2205
2222
}
2206
2223
htlc_failures. append ( & mut pending_failures) ;
2207
2224
@@ -2685,8 +2702,8 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
2685
2702
}
2686
2703
2687
2704
#[ 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 {
2690
2707
let mut forward_event = None ;
2691
2708
if !pending_forwards. is_empty ( ) {
2692
2709
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>
2699
2716
PendingHTLCRouting :: Receive { .. } => 0 ,
2700
2717
} ) {
2701
2718
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 } ) ;
2703
2721
} ,
2704
2722
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 } ) ) ;
2706
2725
}
2707
2726
}
2708
2727
}
@@ -2755,18 +2774,18 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
2755
2774
msg,
2756
2775
} ) ;
2757
2776
}
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 ( ) ) )
2759
2778
} ,
2760
2779
hash_map:: Entry :: Vacant ( _) => break Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
2761
2780
}
2762
2781
} ;
2763
2782
self . fail_holding_cell_htlcs ( htlcs_to_fail, msg. channel_id ) ;
2764
2783
match res {
2765
- Ok ( ( pending_forwards, mut pending_failures, short_channel_id) ) => {
2784
+ Ok ( ( pending_forwards, mut pending_failures, short_channel_id, channel_outpoint ) ) => {
2766
2785
for failure in pending_failures. drain ( ..) {
2767
2786
self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , failure. 0 , & failure. 1 , failure. 2 ) ;
2768
2787
}
2769
- self . forward_htlcs ( & mut [ ( short_channel_id, pending_forwards) ] ) ;
2788
+ self . forward_htlcs ( & mut [ ( short_channel_id, channel_outpoint , pending_forwards) ] ) ;
2770
2789
Ok ( ( ) )
2771
2790
} ,
2772
2791
Err ( e) => Err ( e)
@@ -3543,6 +3562,7 @@ impl Readable for PendingHTLCStatus {
3543
3562
3544
3563
impl_writeable ! ( HTLCPreviousHopData , 0 , {
3545
3564
short_channel_id,
3565
+ outpoint,
3546
3566
htlc_id,
3547
3567
incoming_packet_shared_secret
3548
3568
} ) ;
@@ -3619,9 +3639,10 @@ impl Readable for HTLCFailReason {
3619
3639
impl Writeable for HTLCForwardInfo {
3620
3640
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
3621
3641
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 } => {
3623
3643
0u8 . write ( writer) ?;
3624
3644
prev_short_channel_id. write ( writer) ?;
3645
+ prev_funding_outpoint. write ( writer) ?;
3625
3646
prev_htlc_id. write ( writer) ?;
3626
3647
forward_info. write ( writer) ?;
3627
3648
} ,
@@ -3640,6 +3661,7 @@ impl Readable for HTLCForwardInfo {
3640
3661
match <u8 as Readable >:: read ( reader) ? {
3641
3662
0 => Ok ( HTLCForwardInfo :: AddHTLC {
3642
3663
prev_short_channel_id : Readable :: read ( reader) ?,
3664
+ prev_funding_outpoint : Readable :: read ( reader) ?,
3643
3665
prev_htlc_id : Readable :: read ( reader) ?,
3644
3666
forward_info : Readable :: read ( reader) ?,
3645
3667
} ) ,
0 commit comments