@@ -277,6 +277,9 @@ pub enum PendingHTLCRouting {
277
277
/// provide the onion shared secret used to decrypt the next level of forwarding
278
278
/// instructions.
279
279
phantom_shared_secret: Option<[u8; 32]>,
280
+ /// If the onion had trampoline forwarding instruction to our node.
281
+ /// This will provice the onion shared secret to encrypt error packets to the sender.
282
+ trampoline_shared_secret: Option<[u8; 32]>,
280
283
/// Custom TLVs which were set by the sender.
281
284
///
282
285
/// For HTLCs received by LDK, this will ultimately be exposed in
@@ -466,6 +469,13 @@ impl PendingAddHTLCInfo {
466
469
PendingHTLCRouting::Receive { phantom_shared_secret, .. } => phantom_shared_secret,
467
470
_ => None,
468
471
};
472
+ let trampoline_shared_secret = match self.forward_info.routing {
473
+ PendingHTLCRouting::Receive { trampoline_shared_secret, .. } => {
474
+ trampoline_shared_secret
475
+ },
476
+ _ => None,
477
+ };
478
+
469
479
HTLCPreviousHopData {
470
480
short_channel_id: self.prev_short_channel_id,
471
481
user_channel_id: Some(self.prev_user_channel_id),
@@ -475,6 +485,7 @@ impl PendingAddHTLCInfo {
475
485
htlc_id: self.prev_htlc_id,
476
486
incoming_packet_shared_secret: self.forward_info.incoming_shared_secret,
477
487
phantom_shared_secret,
488
+ trampoline_shared_secret,
478
489
blinded_failure: self.forward_info.routing.blinded_failure(),
479
490
cltv_expiry: self.forward_info.routing.incoming_cltv_expiry(),
480
491
}
@@ -798,6 +809,7 @@ mod fuzzy_channelmanager {
798
809
pub htlc_id: u64,
799
810
pub incoming_packet_shared_secret: [u8; 32],
800
811
pub phantom_shared_secret: Option<[u8; 32]>,
812
+ pub trampoline_shared_secret: Option<[u8; 32]>,
801
813
pub blinded_failure: Option<BlindedFailure>,
802
814
pub channel_id: ChannelId,
803
815
@@ -6835,14 +6847,16 @@ where
6835
6847
Some(payment_hash),
6836
6848
);
6837
6849
let mut failure_handler =
6838
- |msg, reason, err_data, phantom_ss, next_hop_unknown| {
6850
+ |msg, reason, err_data, phantom_ss, trampoline_ss, next_hop_unknown| {
6839
6851
log_info!(logger, "Failed to accept/forward incoming HTLC: {}", msg);
6840
6852
6841
6853
let mut prev_hop = payment.htlc_previous_hop_data();
6842
6854
// Override the phantom shared secret because it wasn't set in the originating
6843
6855
// `PendingAddHTLCInfo` above, it was calculated below after detecting this as a
6844
6856
// phantom payment.
6845
6857
prev_hop.phantom_shared_secret = phantom_ss;
6858
+ prev_hop.trampoline_shared_secret = trampoline_ss;
6859
+
6846
6860
let failure_type = if next_hop_unknown {
6847
6861
HTLCHandlingFailureType::InvalidForward {
6848
6862
requested_forward_scid: short_chan_id,
@@ -6891,6 +6905,7 @@ where
6891
6905
reason,
6892
6906
sha256_of_onion.to_vec(),
6893
6907
None,
6908
+ None,
6894
6909
false,
6895
6910
);
6896
6911
continue;
@@ -6907,6 +6922,7 @@ where
6907
6922
reason,
6908
6923
Vec::new(),
6909
6924
Some(phantom_shared_secret),
6925
+ None,
6910
6926
false,
6911
6927
);
6912
6928
continue;
@@ -6940,6 +6956,7 @@ where
6940
6956
reason,
6941
6957
err_data,
6942
6958
Some(phantom_shared_secret),
6959
+ None,
6943
6960
false,
6944
6961
);
6945
6962
continue;
@@ -6955,6 +6972,7 @@ where
6955
6972
LocalHTLCFailureReason::UnknownNextPeer,
6956
6973
Vec::new(),
6957
6974
None,
6975
+ None,
6958
6976
true,
6959
6977
);
6960
6978
continue;
@@ -6967,6 +6985,7 @@ where
6967
6985
LocalHTLCFailureReason::UnknownNextPeer,
6968
6986
Vec::new(),
6969
6987
None,
6988
+ None,
6970
6989
true,
6971
6990
);
6972
6991
continue;
@@ -7044,6 +7063,7 @@ where
7044
7063
panic!("short_channel_id != 0 should imply any pending_forward entries are of type Forward");
7045
7064
},
7046
7065
};
7066
+
7047
7067
let next_blinding_point = blinded.and_then(|b| {
7048
7068
b.next_blinding_override.or_else(|| {
7049
7069
let encrypted_tlvs_ss = self
@@ -7276,13 +7296,15 @@ where
7276
7296
mut onion_fields,
7277
7297
has_recipient_created_payment_secret,
7278
7298
invoice_request_opt,
7299
+ trampoline_shared_secret,
7279
7300
) = match routing {
7280
7301
PendingHTLCRouting::Receive {
7281
7302
payment_data,
7282
7303
payment_metadata,
7283
7304
payment_context,
7284
7305
incoming_cltv_expiry,
7285
7306
phantom_shared_secret,
7307
+ trampoline_shared_secret,
7286
7308
custom_tlvs,
7287
7309
requires_blinded_error: _,
7288
7310
} => {
@@ -7301,6 +7323,7 @@ where
7301
7323
onion_fields,
7302
7324
true,
7303
7325
None,
7326
+ trampoline_shared_secret,
7304
7327
)
7305
7328
},
7306
7329
PendingHTLCRouting::ReceiveKeysend {
@@ -7330,6 +7353,7 @@ where
7330
7353
onion_fields,
7331
7354
has_recipient_created_payment_secret,
7332
7355
invoice_request,
7356
+ None,
7333
7357
)
7334
7358
},
7335
7359
_ => {
@@ -7377,6 +7401,7 @@ where
7377
7401
htlc_id: $htlc.prev_hop.htlc_id,
7378
7402
incoming_packet_shared_secret,
7379
7403
phantom_shared_secret,
7404
+ trampoline_shared_secret,
7380
7405
blinded_failure,
7381
7406
cltv_expiry: Some(cltv_expiry),
7382
7407
}),
@@ -8176,6 +8201,7 @@ where
8176
8201
ref htlc_id,
8177
8202
ref incoming_packet_shared_secret,
8178
8203
ref phantom_shared_secret,
8204
+ ref trampoline_shared_secret,
8179
8205
outpoint: _,
8180
8206
ref blinded_failure,
8181
8207
ref channel_id,
@@ -8188,6 +8214,7 @@ where
8188
8214
&payment_hash,
8189
8215
onion_error
8190
8216
);
8217
+ let secondary_shared_secret = trampoline_shared_secret.or(*phantom_shared_secret);
8191
8218
let failure = match blinded_failure {
8192
8219
Some(BlindedFailure::FromIntroductionNode) => {
8193
8220
let blinded_onion_error = HTLCFailReason::reason(
@@ -8196,7 +8223,7 @@ where
8196
8223
);
8197
8224
let err_packet = blinded_onion_error.get_encrypted_failure_packet(
8198
8225
incoming_packet_shared_secret,
8199
- phantom_shared_secret ,
8226
+ &secondary_shared_secret ,
8200
8227
);
8201
8228
HTLCForwardInfo::FailHTLC { htlc_id: *htlc_id, err_packet }
8202
8229
},
@@ -8208,7 +8235,7 @@ where
8208
8235
None => {
8209
8236
let err_packet = onion_error.get_encrypted_failure_packet(
8210
8237
incoming_packet_shared_secret,
8211
- phantom_shared_secret ,
8238
+ &secondary_shared_secret ,
8212
8239
);
8213
8240
HTLCForwardInfo::FailHTLC { htlc_id: *htlc_id, err_packet }
8214
8241
},
@@ -8470,7 +8497,8 @@ where
8470
8497
ComplFunc: FnOnce(
8471
8498
Option<u64>,
8472
8499
bool,
8473
- ) -> (Option<MonitorUpdateCompletionAction>, Option<RAAMonitorUpdateBlockingAction>),
8500
+ )
8501
+ -> (Option<MonitorUpdateCompletionAction>, Option<RAAMonitorUpdateBlockingAction>),
8474
8502
>(
8475
8503
&self, prev_hop: HTLCPreviousHopData, payment_preimage: PaymentPreimage,
8476
8504
payment_info: Option<PaymentClaimDetails>, attribution_data: Option<AttributionData>,
@@ -8508,7 +8536,8 @@ where
8508
8536
ComplFunc: FnOnce(
8509
8537
Option<u64>,
8510
8538
bool,
8511
- ) -> (Option<MonitorUpdateCompletionAction>, Option<RAAMonitorUpdateBlockingAction>),
8539
+ )
8540
+ -> (Option<MonitorUpdateCompletionAction>, Option<RAAMonitorUpdateBlockingAction>),
8512
8541
>(
8513
8542
&self, prev_hop: HTLCClaimSource, payment_preimage: PaymentPreimage,
8514
8543
payment_info: Option<PaymentClaimDetails>, attribution_data: Option<AttributionData>,
@@ -15173,6 +15202,7 @@ impl_writeable_tlv_based_enum!(PendingHTLCRouting,
15173
15202
(5, custom_tlvs, optional_vec),
15174
15203
(7, requires_blinded_error, (default_value, false)),
15175
15204
(9, payment_context, option),
15205
+ (11, trampoline_shared_secret, option),
15176
15206
},
15177
15207
(2, ReceiveKeysend) => {
15178
15208
(0, payment_preimage, required),
@@ -15301,6 +15331,7 @@ impl_writeable_tlv_based!(HTLCPreviousHopData, {
15301
15331
// filled in, so we can safely unwrap it here.
15302
15332
(9, channel_id, (default_value, ChannelId::v1_from_funding_outpoint(outpoint.0.unwrap()))),
15303
15333
(11, counterparty_node_id, option),
15334
+ (13, trampoline_shared_secret, option),
15304
15335
});
15305
15336
15306
15337
impl Writeable for ClaimableHTLC {
0 commit comments