@@ -57,15 +57,19 @@ use std::ops::Deref;
57
57
// forward the HTLC with information it will give back to us when it does so, or if it should Fail
58
58
// the HTLC with the relevant message for the Channel to handle giving to the remote peer.
59
59
//
60
- // When a Channel forwards an HTLC to its peer, it will give us back the PendingForwardHTLCInfo
61
- // which we will use to construct an outbound HTLC, with a relevant HTLCSource::PreviousHopData
62
- // filled in to indicate where it came from (which we can use to either fail-backwards or fulfill
63
- // the HTLC backwards along the relevant path).
60
+ // Once said HTLC is committed in the Channel, if the PendingHTLCStatus indicated Forward, the
61
+ // Channel will return the PendingHTLCInfo back to us, and we will create an HTLCForwardInfo
62
+ // with it to track where it came from (in case of onwards-forward error), waiting a random delay
63
+ // before we forward it.
64
+ //
65
+ // We will then use HTLCForwardInfo's PendingHTLCInfo to construct an outbound HTLC, with a
66
+ // relevant HTLCSource::PreviousHopData filled in to indicate where it came from (which we can use
67
+ // to either fail-backwards or fulfill the HTLC backwards along the relevant path).
64
68
// Alternatively, we can fill an outbound HTLC with a HTLCSource::OutboundRoute indicating this is
65
69
// our payment, which we can use to decode errors or inform the user that the payment was sent.
66
- /// Stores the info we will need to send when we want to forward an HTLC onwards
70
+
67
71
#[ derive( Clone ) ] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
68
- pub ( super ) struct PendingForwardHTLCInfo {
72
+ pub ( super ) struct PendingHTLCInfo {
69
73
onion_packet : Option < msgs:: OnionPacket > ,
70
74
incoming_shared_secret : [ u8 ; 32 ] ,
71
75
payment_hash : PaymentHash ,
@@ -83,10 +87,22 @@ pub(super) enum HTLCFailureMsg {
83
87
/// Stores whether we can't forward an HTLC or relevant forwarding info
84
88
#[ derive( Clone ) ] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
85
89
pub ( super ) enum PendingHTLCStatus {
86
- Forward ( PendingForwardHTLCInfo ) ,
90
+ Forward ( PendingHTLCInfo ) ,
87
91
Fail ( HTLCFailureMsg ) ,
88
92
}
89
93
94
+ pub ( super ) enum HTLCForwardInfo {
95
+ AddHTLC {
96
+ prev_short_channel_id : u64 ,
97
+ prev_htlc_id : u64 ,
98
+ forward_info : PendingHTLCInfo ,
99
+ } ,
100
+ FailHTLC {
101
+ htlc_id : u64 ,
102
+ err_packet : msgs:: OnionErrorPacket ,
103
+ } ,
104
+ }
105
+
90
106
/// Tracks the inbound corresponding to an outbound HTLC
91
107
#[ derive( Clone , PartialEq ) ]
92
108
pub ( super ) struct HTLCPreviousHopData {
@@ -231,18 +247,6 @@ impl MsgHandleErrInternal {
231
247
/// second to 30 seconds, but people expect lightning to be, you know, kinda fast, sadly.
232
248
const MIN_HTLC_RELAY_HOLDING_CELL_MILLIS : u64 = 100 ;
233
249
234
- pub ( super ) enum HTLCForwardInfo {
235
- AddHTLC {
236
- prev_short_channel_id : u64 ,
237
- prev_htlc_id : u64 ,
238
- forward_info : PendingForwardHTLCInfo ,
239
- } ,
240
- FailHTLC {
241
- htlc_id : u64 ,
242
- err_packet : msgs:: OnionErrorPacket ,
243
- } ,
244
- }
245
-
246
250
/// For events which result in both a RevokeAndACK and a CommitmentUpdate, by default they should
247
251
/// be sent in the order they appear in the return value, however sometimes the order needs to be
248
252
/// variable at runtime (eg Channel::channel_reestablish needs to re-send messages in the order
@@ -262,7 +266,7 @@ pub(super) struct ChannelHolder<ChanSigner: ChannelKeys> {
262
266
/// short channel id -> forward infos. Key of 0 means payments received
263
267
/// Note that while this is held in the same mutex as the channels themselves, no consistency
264
268
/// guarantees are made about the existence of a channel with the short id here, nor the short
265
- /// ids in the PendingForwardHTLCInfo !
269
+ /// ids in the PendingHTLCInfo !
266
270
pub ( super ) forward_htlcs : HashMap < u64 , Vec < HTLCForwardInfo > > ,
267
271
/// payment_hash -> Vec<(amount_received, htlc_source)> for tracking things that were to us and
268
272
/// can be failed/claimed by the user
@@ -571,7 +575,7 @@ macro_rules! handle_monitor_err {
571
575
} else if $resend_commitment { "commitment" }
572
576
else if $resend_raa { "RAA" }
573
577
else { "nothing" } ,
574
- ( & $failed_forwards as & Vec <( PendingForwardHTLCInfo , u64 ) >) . len( ) ,
578
+ ( & $failed_forwards as & Vec <( PendingHTLCInfo , u64 ) >) . len( ) ,
575
579
( & $failed_fails as & Vec <( HTLCSource , PaymentHash , HTLCFailReason ) >) . len( ) ) ;
576
580
if !$resend_commitment {
577
581
debug_assert!( $action_type == RAACommitmentOrder :: RevokeAndACKFirst || !$resend_raa) ;
@@ -963,7 +967,7 @@ impl<ChanSigner: ChannelKeys, M: Deref> ChannelManager<ChanSigner, M> where M::T
963
967
// instead we stay symmetric with the forwarding case, only responding (after a
964
968
// delay) once they've send us a commitment_signed!
965
969
966
- PendingHTLCStatus :: Forward ( PendingForwardHTLCInfo {
970
+ PendingHTLCStatus :: Forward ( PendingHTLCInfo {
967
971
onion_packet : None ,
968
972
payment_hash : msg. payment_hash . clone ( ) ,
969
973
short_channel_id : 0 ,
@@ -1015,7 +1019,7 @@ impl<ChanSigner: ChannelKeys, M: Deref> ChannelManager<ChanSigner, M> where M::T
1015
1019
} ,
1016
1020
} ;
1017
1021
1018
- PendingHTLCStatus :: Forward ( PendingForwardHTLCInfo {
1022
+ PendingHTLCStatus :: Forward ( PendingHTLCInfo {
1019
1023
onion_packet : Some ( outgoing_packet) ,
1020
1024
payment_hash : msg. payment_hash . clone ( ) ,
1021
1025
short_channel_id : short_channel_id,
@@ -1026,7 +1030,7 @@ impl<ChanSigner: ChannelKeys, M: Deref> ChannelManager<ChanSigner, M> where M::T
1026
1030
} ;
1027
1031
1028
1032
channel_state = Some ( self . channel_state . lock ( ) . unwrap ( ) ) ;
1029
- if let & PendingHTLCStatus :: Forward ( PendingForwardHTLCInfo { ref onion_packet, ref short_channel_id, ref amt_to_forward, ref outgoing_cltv_value, .. } ) = & pending_forward_info {
1033
+ if let & PendingHTLCStatus :: Forward ( PendingHTLCInfo { ref onion_packet, ref short_channel_id, ref amt_to_forward, ref outgoing_cltv_value, .. } ) = & pending_forward_info {
1030
1034
if onion_packet. is_some ( ) { // If short_channel_id is 0 here, we'll reject them in the body here
1031
1035
let id_option = channel_state. as_ref ( ) . unwrap ( ) . short_to_id . get ( & short_channel_id) . cloned ( ) ;
1032
1036
let forwarding_id = match id_option {
@@ -2152,7 +2156,7 @@ impl<ChanSigner: ChannelKeys, M: Deref> ChannelManager<ChanSigner, M> where M::T
2152
2156
// If the update_add is completely bogus, the call will Err and we will close,
2153
2157
// but if we've sent a shutdown and they haven't acknowledged it yet, we just
2154
2158
// want to reject the new HTLC and fail it backwards instead of forwarding.
2155
- if let PendingHTLCStatus :: Forward ( PendingForwardHTLCInfo { incoming_shared_secret, .. } ) = pending_forward_info {
2159
+ if let PendingHTLCStatus :: Forward ( PendingHTLCInfo { incoming_shared_secret, .. } ) = pending_forward_info {
2156
2160
let chan_update = self . get_channel_update ( chan. get ( ) ) ;
2157
2161
pending_forward_info = PendingHTLCStatus :: Fail ( HTLCFailureMsg :: Relay ( msgs:: UpdateFailHTLC {
2158
2162
channel_id : msg. channel_id ,
@@ -2283,7 +2287,7 @@ impl<ChanSigner: ChannelKeys, M: Deref> ChannelManager<ChanSigner, M> where M::T
2283
2287
}
2284
2288
2285
2289
#[ inline]
2286
- fn forward_htlcs ( & self , per_source_pending_forwards : & mut [ ( u64 , Vec < ( PendingForwardHTLCInfo , u64 ) > ) ] ) {
2290
+ fn forward_htlcs ( & self , per_source_pending_forwards : & mut [ ( u64 , Vec < ( PendingHTLCInfo , u64 ) > ) ] ) {
2287
2291
for & mut ( prev_short_channel_id, ref mut pending_forwards) in per_source_pending_forwards {
2288
2292
let mut forward_event = None ;
2289
2293
if !pending_forwards. is_empty ( ) {
@@ -2998,7 +3002,7 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send> ChannelMessageHandler for
2998
3002
const SERIALIZATION_VERSION : u8 = 1 ;
2999
3003
const MIN_SERIALIZATION_VERSION : u8 = 1 ;
3000
3004
3001
- impl Writeable for PendingForwardHTLCInfo {
3005
+ impl Writeable for PendingHTLCInfo {
3002
3006
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
3003
3007
self . onion_packet . write ( writer) ?;
3004
3008
self . incoming_shared_secret . write ( writer) ?;
@@ -3010,9 +3014,9 @@ impl Writeable for PendingForwardHTLCInfo {
3010
3014
}
3011
3015
}
3012
3016
3013
- impl < R : :: std:: io:: Read > Readable < R > for PendingForwardHTLCInfo {
3014
- fn read ( reader : & mut R ) -> Result < PendingForwardHTLCInfo , DecodeError > {
3015
- Ok ( PendingForwardHTLCInfo {
3017
+ impl < R : :: std:: io:: Read > Readable < R > for PendingHTLCInfo {
3018
+ fn read ( reader : & mut R ) -> Result < PendingHTLCInfo , DecodeError > {
3019
+ Ok ( PendingHTLCInfo {
3016
3020
onion_packet : Readable :: read ( reader) ?,
3017
3021
incoming_shared_secret : Readable :: read ( reader) ?,
3018
3022
payment_hash : Readable :: read ( reader) ?,
0 commit comments