@@ -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
@@ -7276,13 +7288,15 @@ where
7276
7288
mut onion_fields,
7277
7289
has_recipient_created_payment_secret,
7278
7290
invoice_request_opt,
7291
+ trampoline_shared_secret,
7279
7292
) = match routing {
7280
7293
PendingHTLCRouting::Receive {
7281
7294
payment_data,
7282
7295
payment_metadata,
7283
7296
payment_context,
7284
7297
incoming_cltv_expiry,
7285
7298
phantom_shared_secret,
7299
+ trampoline_shared_secret,
7286
7300
custom_tlvs,
7287
7301
requires_blinded_error: _,
7288
7302
} => {
@@ -7301,6 +7315,7 @@ where
7301
7315
onion_fields,
7302
7316
true,
7303
7317
None,
7318
+ trampoline_shared_secret,
7304
7319
)
7305
7320
},
7306
7321
PendingHTLCRouting::ReceiveKeysend {
@@ -7330,6 +7345,7 @@ where
7330
7345
onion_fields,
7331
7346
has_recipient_created_payment_secret,
7332
7347
invoice_request,
7348
+ None,
7333
7349
)
7334
7350
},
7335
7351
_ => {
@@ -7377,6 +7393,7 @@ where
7377
7393
htlc_id: $htlc.prev_hop.htlc_id,
7378
7394
incoming_packet_shared_secret,
7379
7395
phantom_shared_secret,
7396
+ trampoline_shared_secret,
7380
7397
blinded_failure,
7381
7398
cltv_expiry: Some(cltv_expiry),
7382
7399
}),
@@ -8176,6 +8193,7 @@ where
8176
8193
ref htlc_id,
8177
8194
ref incoming_packet_shared_secret,
8178
8195
ref phantom_shared_secret,
8196
+ ref trampoline_shared_secret,
8179
8197
outpoint: _,
8180
8198
ref blinded_failure,
8181
8199
ref channel_id,
@@ -8188,6 +8206,7 @@ where
8188
8206
&payment_hash,
8189
8207
onion_error
8190
8208
);
8209
+ let secondary_shared_secret = trampoline_shared_secret.or(*phantom_shared_secret);
8191
8210
let failure = match blinded_failure {
8192
8211
Some(BlindedFailure::FromIntroductionNode) => {
8193
8212
let blinded_onion_error = HTLCFailReason::reason(
@@ -8196,7 +8215,7 @@ where
8196
8215
);
8197
8216
let err_packet = blinded_onion_error.get_encrypted_failure_packet(
8198
8217
incoming_packet_shared_secret,
8199
- phantom_shared_secret ,
8218
+ &secondary_shared_secret ,
8200
8219
);
8201
8220
HTLCForwardInfo::FailHTLC { htlc_id: *htlc_id, err_packet }
8202
8221
},
@@ -8208,7 +8227,7 @@ where
8208
8227
None => {
8209
8228
let err_packet = onion_error.get_encrypted_failure_packet(
8210
8229
incoming_packet_shared_secret,
8211
- phantom_shared_secret ,
8230
+ &secondary_shared_secret ,
8212
8231
);
8213
8232
HTLCForwardInfo::FailHTLC { htlc_id: *htlc_id, err_packet }
8214
8233
},
@@ -15173,6 +15192,7 @@ impl_writeable_tlv_based_enum!(PendingHTLCRouting,
15173
15192
(5, custom_tlvs, optional_vec),
15174
15193
(7, requires_blinded_error, (default_value, false)),
15175
15194
(9, payment_context, option),
15195
+ (11, trampoline_shared_secret, option),
15176
15196
},
15177
15197
(2, ReceiveKeysend) => {
15178
15198
(0, payment_preimage, required),
@@ -15301,6 +15321,7 @@ impl_writeable_tlv_based!(HTLCPreviousHopData, {
15301
15321
// filled in, so we can safely unwrap it here.
15302
15322
(9, channel_id, (default_value, ChannelId::v1_from_funding_outpoint(outpoint.0.unwrap()))),
15303
15323
(11, counterparty_node_id, option),
15324
+ (13, trampoline_shared_secret, option),
15304
15325
});
15305
15326
15306
15327
impl Writeable for ClaimableHTLC {
0 commit comments