@@ -55,15 +55,19 @@ use std::time::Duration;
55
55
// forward the HTLC with information it will give back to us when it does so, or if it should Fail
56
56
// the HTLC with the relevant message for the Channel to handle giving to the remote peer.
57
57
//
58
- // When a Channel forwards an HTLC to its peer, it will give us back the PendingForwardHTLCInfo
59
- // which we will use to construct an outbound HTLC, with a relevant HTLCSource::PreviousHopData
60
- // filled in to indicate where it came from (which we can use to either fail-backwards or fulfill
61
- // the HTLC backwards along the relevant path).
58
+ // Once said HTLC is committed in the Channel, if the PendingHTLCStatus indicated Forward, the
59
+ // Channel will return the PendingHTLCInfo back to us, and we will create an HTLCForwardInfo
60
+ // with it to track where it came from (in case of onwards-forward error), waiting a random delay
61
+ // before we forward it.
62
+ //
63
+ // We will then use HTLCForwardInfo's PendingHTLCInfo to construct an outbound HTLC, with a
64
+ // relevant HTLCSource::PreviousHopData filled in to indicate where it came from (which we can use
65
+ // to either fail-backwards or fulfill the HTLC backwards along the relevant path).
62
66
// Alternatively, we can fill an outbound HTLC with a HTLCSource::OutboundRoute indicating this is
63
67
// our payment, which we can use to decode errors or inform the user that the payment was sent.
64
- /// Stores the info we will need to send when we want to forward an HTLC onwards
68
+
65
69
#[ derive( Clone ) ] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
66
- pub ( super ) struct PendingForwardHTLCInfo {
70
+ pub ( super ) struct PendingHTLCInfo {
67
71
onion_packet : Option < msgs:: OnionPacket > ,
68
72
incoming_shared_secret : [ u8 ; 32 ] ,
69
73
payment_hash : PaymentHash ,
@@ -81,10 +85,22 @@ pub(super) enum HTLCFailureMsg {
81
85
/// Stores whether we can't forward an HTLC or relevant forwarding info
82
86
#[ derive( Clone ) ] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
83
87
pub ( super ) enum PendingHTLCStatus {
84
- Forward ( PendingForwardHTLCInfo ) ,
88
+ Forward ( PendingHTLCInfo ) ,
85
89
Fail ( HTLCFailureMsg ) ,
86
90
}
87
91
92
+ pub ( super ) enum HTLCForwardInfo {
93
+ AddHTLC {
94
+ prev_short_channel_id : u64 ,
95
+ prev_htlc_id : u64 ,
96
+ forward_info : PendingHTLCInfo ,
97
+ } ,
98
+ FailHTLC {
99
+ htlc_id : u64 ,
100
+ err_packet : msgs:: OnionErrorPacket ,
101
+ } ,
102
+ }
103
+
88
104
/// Tracks the inbound corresponding to an outbound HTLC
89
105
#[ derive( Clone , PartialEq ) ]
90
106
pub ( super ) struct HTLCPreviousHopData {
@@ -229,18 +245,6 @@ impl MsgHandleErrInternal {
229
245
/// second to 30 seconds, but people expect lightning to be, you know, kinda fast, sadly.
230
246
const MIN_HTLC_RELAY_HOLDING_CELL_MILLIS : u64 = 100 ;
231
247
232
- pub ( super ) enum HTLCForwardInfo {
233
- AddHTLC {
234
- prev_short_channel_id : u64 ,
235
- prev_htlc_id : u64 ,
236
- forward_info : PendingForwardHTLCInfo ,
237
- } ,
238
- FailHTLC {
239
- htlc_id : u64 ,
240
- err_packet : msgs:: OnionErrorPacket ,
241
- } ,
242
- }
243
-
244
248
/// For events which result in both a RevokeAndACK and a CommitmentUpdate, by default they should
245
249
/// be sent in the order they appear in the return value, however sometimes the order needs to be
246
250
/// variable at runtime (eg Channel::channel_reestablish needs to re-send messages in the order
@@ -260,7 +264,7 @@ pub(super) struct ChannelHolder<ChanSigner: ChannelKeys> {
260
264
/// short channel id -> forward infos. Key of 0 means payments received
261
265
/// Note that while this is held in the same mutex as the channels themselves, no consistency
262
266
/// guarantees are made about the existence of a channel with the short id here, nor the short
263
- /// ids in the PendingForwardHTLCInfo !
267
+ /// ids in the PendingHTLCInfo !
264
268
pub ( super ) forward_htlcs : HashMap < u64 , Vec < HTLCForwardInfo > > ,
265
269
/// payment_hash -> Vec<(amount_received, htlc_source)> for tracking things that were to us and
266
270
/// can be failed/claimed by the user
@@ -569,7 +573,7 @@ macro_rules! handle_monitor_err {
569
573
} else if $resend_commitment { "commitment" }
570
574
else if $resend_raa { "RAA" }
571
575
else { "nothing" } ,
572
- ( & $failed_forwards as & Vec <( PendingForwardHTLCInfo , u64 ) >) . len( ) ,
576
+ ( & $failed_forwards as & Vec <( PendingHTLCInfo , u64 ) >) . len( ) ,
573
577
( & $failed_fails as & Vec <( HTLCSource , PaymentHash , HTLCFailReason ) >) . len( ) ) ;
574
578
if !$resend_commitment {
575
579
debug_assert!( $action_type == RAACommitmentOrder :: RevokeAndACKFirst || !$resend_raa) ;
@@ -986,7 +990,7 @@ impl<ChanSigner: ChannelKeys> ChannelManager<ChanSigner> {
986
990
// instead we stay symmetric with the forwarding case, only responding (after a
987
991
// delay) once they've send us a commitment_signed!
988
992
989
- PendingHTLCStatus :: Forward ( PendingForwardHTLCInfo {
993
+ PendingHTLCStatus :: Forward ( PendingHTLCInfo {
990
994
onion_packet : None ,
991
995
payment_hash : msg. payment_hash . clone ( ) ,
992
996
short_channel_id : 0 ,
@@ -1036,7 +1040,7 @@ impl<ChanSigner: ChannelKeys> ChannelManager<ChanSigner> {
1036
1040
} ,
1037
1041
} ;
1038
1042
1039
- PendingHTLCStatus :: Forward ( PendingForwardHTLCInfo {
1043
+ PendingHTLCStatus :: Forward ( PendingHTLCInfo {
1040
1044
onion_packet : Some ( outgoing_packet) ,
1041
1045
payment_hash : msg. payment_hash . clone ( ) ,
1042
1046
short_channel_id : short_channel_id,
@@ -1047,7 +1051,7 @@ impl<ChanSigner: ChannelKeys> ChannelManager<ChanSigner> {
1047
1051
} ;
1048
1052
1049
1053
channel_state = Some ( self . channel_state . lock ( ) . unwrap ( ) ) ;
1050
- if let & PendingHTLCStatus :: Forward ( PendingForwardHTLCInfo { ref onion_packet, ref short_channel_id, ref amt_to_forward, ref outgoing_cltv_value, .. } ) = & pending_forward_info {
1054
+ if let & PendingHTLCStatus :: Forward ( PendingHTLCInfo { ref onion_packet, ref short_channel_id, ref amt_to_forward, ref outgoing_cltv_value, .. } ) = & pending_forward_info {
1051
1055
if onion_packet. is_some ( ) { // If short_channel_id is 0 here, we'll reject them in the body here
1052
1056
let id_option = channel_state. as_ref ( ) . unwrap ( ) . short_to_id . get ( & short_channel_id) . cloned ( ) ;
1053
1057
let forwarding_id = match id_option {
@@ -2200,7 +2204,7 @@ impl<ChanSigner: ChannelKeys> ChannelManager<ChanSigner> {
2200
2204
// If the update_add is completely bogus, the call will Err and we will close,
2201
2205
// but if we've sent a shutdown and they haven't acknowledged it yet, we just
2202
2206
// want to reject the new HTLC and fail it backwards instead of forwarding.
2203
- if let PendingHTLCStatus :: Forward ( PendingForwardHTLCInfo { incoming_shared_secret, .. } ) = pending_forward_info {
2207
+ if let PendingHTLCStatus :: Forward ( PendingHTLCInfo { incoming_shared_secret, .. } ) = pending_forward_info {
2204
2208
let chan_update = self . get_channel_update ( chan. get ( ) ) ;
2205
2209
pending_forward_info = PendingHTLCStatus :: Fail ( HTLCFailureMsg :: Relay ( msgs:: UpdateFailHTLC {
2206
2210
channel_id : msg. channel_id ,
@@ -2330,7 +2334,7 @@ impl<ChanSigner: ChannelKeys> ChannelManager<ChanSigner> {
2330
2334
}
2331
2335
2332
2336
#[ inline]
2333
- fn forward_htlcs ( & self , per_source_pending_forwards : & mut [ ( u64 , Vec < ( PendingForwardHTLCInfo , u64 ) > ) ] ) {
2337
+ fn forward_htlcs ( & self , per_source_pending_forwards : & mut [ ( u64 , Vec < ( PendingHTLCInfo , u64 ) > ) ] ) {
2334
2338
for & mut ( prev_short_channel_id, ref mut pending_forwards) in per_source_pending_forwards {
2335
2339
let mut forward_event = None ;
2336
2340
if !pending_forwards. is_empty ( ) {
@@ -3041,7 +3045,7 @@ impl<ChanSigner: ChannelKeys> ChannelMessageHandler for ChannelManager<ChanSigne
3041
3045
const SERIALIZATION_VERSION : u8 = 1 ;
3042
3046
const MIN_SERIALIZATION_VERSION : u8 = 1 ;
3043
3047
3044
- impl Writeable for PendingForwardHTLCInfo {
3048
+ impl Writeable for PendingHTLCInfo {
3045
3049
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
3046
3050
self . onion_packet . write ( writer) ?;
3047
3051
self . incoming_shared_secret . write ( writer) ?;
@@ -3053,9 +3057,9 @@ impl Writeable for PendingForwardHTLCInfo {
3053
3057
}
3054
3058
}
3055
3059
3056
- impl < R : :: std:: io:: Read > Readable < R > for PendingForwardHTLCInfo {
3057
- fn read ( reader : & mut R ) -> Result < PendingForwardHTLCInfo , DecodeError > {
3058
- Ok ( PendingForwardHTLCInfo {
3060
+ impl < R : :: std:: io:: Read > Readable < R > for PendingHTLCInfo {
3061
+ fn read ( reader : & mut R ) -> Result < PendingHTLCInfo , DecodeError > {
3062
+ Ok ( PendingHTLCInfo {
3059
3063
onion_packet : Readable :: read ( reader) ?,
3060
3064
incoming_shared_secret : Readable :: read ( reader) ?,
3061
3065
payment_hash : Readable :: read ( reader) ?,
0 commit comments