Skip to content

Commit ae15ba8

Browse files
Persist whether an HTLC is blinded in HTLCPreviousHopData.
Useful so we know to fail blinded intro node HTLCs back with an invalid_onion_blinding error per BOLT 4. Another variant will be added to the new Blinded enum when we support receiving/forwarding as a non-intro node.
1 parent b645237 commit ae15ba8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ pub(super) enum HTLCForwardInfo {
225225
},
226226
}
227227

228+
// Used for failing blinded HTLCs backwards correctly.
229+
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
230+
enum BlindedFailure {
231+
FromIntroductionNode,
232+
// Another variant will be added here for non-intro nodes.
233+
}
234+
228235
/// Tracks the inbound corresponding to an outbound HTLC
229236
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
230237
pub(crate) struct HTLCPreviousHopData {
@@ -234,6 +241,7 @@ pub(crate) struct HTLCPreviousHopData {
234241
htlc_id: u64,
235242
incoming_packet_shared_secret: [u8; 32],
236243
phantom_shared_secret: Option<[u8; 32]>,
244+
blinded_failure: Option<BlindedFailure>,
237245

238246
// This field is consumed by `claim_funds_from_hop()` when updating a force-closed backwards
239247
// channel with a preimage provided by the forward channel.
@@ -4072,6 +4080,7 @@ where
40724080
htlc_id: payment.prev_htlc_id,
40734081
incoming_packet_shared_secret: payment.forward_info.incoming_shared_secret,
40744082
phantom_shared_secret: None,
4083+
blinded_failure: None,
40754084
});
40764085

40774086
let failure_reason = HTLCFailReason::from_failure_code(0x4000 | 10);
@@ -4120,6 +4129,7 @@ where
41204129
htlc_id: prev_htlc_id,
41214130
incoming_packet_shared_secret: incoming_shared_secret,
41224131
phantom_shared_secret: $phantom_ss,
4132+
blinded_failure: None,
41234133
});
41244134

41254135
let reason = if $next_hop_unknown {
@@ -4236,6 +4246,7 @@ where
42364246
incoming_packet_shared_secret: incoming_shared_secret,
42374247
// Phantom payments are only PendingHTLCRouting::Receive.
42384248
phantom_shared_secret: None,
4249+
blinded_failure: None,
42394250
});
42404251
if let Err(e) = chan.queue_add_htlc(outgoing_amt_msat,
42414252
payment_hash, outgoing_cltv_value, htlc_source.clone(),
@@ -4319,6 +4330,7 @@ where
43194330
htlc_id: prev_htlc_id,
43204331
incoming_packet_shared_secret: incoming_shared_secret,
43214332
phantom_shared_secret,
4333+
blinded_failure: None,
43224334
},
43234335
// We differentiate the received value from the sender intended value
43244336
// if possible so that we don't prematurely mark MPP payments complete
@@ -4349,6 +4361,7 @@ where
43494361
htlc_id: $htlc.prev_hop.htlc_id,
43504362
incoming_packet_shared_secret: $htlc.prev_hop.incoming_packet_shared_secret,
43514363
phantom_shared_secret,
4364+
blinded_failure: None,
43524365
}), payment_hash,
43534366
HTLCFailReason::reason(0x4000 | 15, htlc_msat_height_data),
43544367
HTLCDestination::FailedPayment { payment_hash: $payment_hash },
@@ -6598,6 +6611,7 @@ where
65986611
htlc_id: prev_htlc_id,
65996612
incoming_packet_shared_secret: forward_info.incoming_shared_secret,
66006613
phantom_shared_secret: None,
6614+
blinded_failure: None,
66016615
});
66026616

66036617
failed_intercept_forwards.push((htlc_source, forward_info.payment_hash,
@@ -8194,6 +8208,7 @@ where
81948208
incoming_packet_shared_secret: htlc.forward_info.incoming_shared_secret,
81958209
phantom_shared_secret: None,
81968210
outpoint: htlc.prev_funding_outpoint,
8211+
blinded_failure: None,
81978212
});
81988213

81998214
let requested_forward_scid /* intercept scid */ = match htlc.forward_info.routing {
@@ -9266,10 +9281,15 @@ impl_writeable_tlv_based_enum!(PendingHTLCStatus, ;
92669281
(1, Fail),
92679282
);
92689283

9284+
impl_writeable_tlv_based_enum!(BlindedFailure,
9285+
(0, FromIntroductionNode) => {}, ;
9286+
);
9287+
92699288
impl_writeable_tlv_based!(HTLCPreviousHopData, {
92709289
(0, short_channel_id, required),
92719290
(1, phantom_shared_secret, option),
92729291
(2, outpoint, required),
9292+
(3, blinded_failure, option),
92739293
(4, htlc_id, required),
92749294
(6, incoming_packet_shared_secret, required),
92759295
(7, user_channel_id, option),

0 commit comments

Comments
 (0)