@@ -277,6 +277,9 @@ pub enum PendingHTLCRouting {
277277 /// provide the onion shared secret used to decrypt the next level of forwarding
278278 /// instructions.
279279 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]>,
280283 /// Custom TLVs which were set by the sender.
281284 ///
282285 /// For HTLCs received by LDK, this will ultimately be exposed in
@@ -466,6 +469,13 @@ impl PendingAddHTLCInfo {
466469 PendingHTLCRouting::Receive { phantom_shared_secret, .. } => phantom_shared_secret,
467470 _ => None,
468471 };
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+
469479 HTLCPreviousHopData {
470480 short_channel_id: self.prev_short_channel_id,
471481 user_channel_id: Some(self.prev_user_channel_id),
@@ -475,6 +485,7 @@ impl PendingAddHTLCInfo {
475485 htlc_id: self.prev_htlc_id,
476486 incoming_packet_shared_secret: self.forward_info.incoming_shared_secret,
477487 phantom_shared_secret,
488+ trampoline_shared_secret,
478489 blinded_failure: self.forward_info.routing.blinded_failure(),
479490 cltv_expiry: self.forward_info.routing.incoming_cltv_expiry(),
480491 }
@@ -798,6 +809,7 @@ mod fuzzy_channelmanager {
798809 pub htlc_id: u64,
799810 pub incoming_packet_shared_secret: [u8; 32],
800811 pub phantom_shared_secret: Option<[u8; 32]>,
812+ pub trampoline_shared_secret: Option<[u8; 32]>,
801813 pub blinded_failure: Option<BlindedFailure>,
802814 pub channel_id: ChannelId,
803815
@@ -7276,13 +7288,15 @@ where
72767288 mut onion_fields,
72777289 has_recipient_created_payment_secret,
72787290 invoice_request_opt,
7291+ trampoline_shared_secret,
72797292 ) = match routing {
72807293 PendingHTLCRouting::Receive {
72817294 payment_data,
72827295 payment_metadata,
72837296 payment_context,
72847297 incoming_cltv_expiry,
72857298 phantom_shared_secret,
7299+ trampoline_shared_secret,
72867300 custom_tlvs,
72877301 requires_blinded_error: _,
72887302 } => {
@@ -7301,6 +7315,7 @@ where
73017315 onion_fields,
73027316 true,
73037317 None,
7318+ trampoline_shared_secret,
73047319 )
73057320 },
73067321 PendingHTLCRouting::ReceiveKeysend {
@@ -7330,6 +7345,7 @@ where
73307345 onion_fields,
73317346 has_recipient_created_payment_secret,
73327347 invoice_request,
7348+ None,
73337349 )
73347350 },
73357351 _ => {
@@ -7377,6 +7393,7 @@ where
73777393 htlc_id: $htlc.prev_hop.htlc_id,
73787394 incoming_packet_shared_secret,
73797395 phantom_shared_secret,
7396+ trampoline_shared_secret,
73807397 blinded_failure,
73817398 cltv_expiry: Some(cltv_expiry),
73827399 }),
@@ -8176,6 +8193,7 @@ where
81768193 ref htlc_id,
81778194 ref incoming_packet_shared_secret,
81788195 ref phantom_shared_secret,
8196+ ref trampoline_shared_secret,
81798197 outpoint: _,
81808198 ref blinded_failure,
81818199 ref channel_id,
@@ -8188,6 +8206,7 @@ where
81888206 &payment_hash,
81898207 onion_error
81908208 );
8209+ let secondary_shared_secret = trampoline_shared_secret.or(*phantom_shared_secret);
81918210 let failure = match blinded_failure {
81928211 Some(BlindedFailure::FromIntroductionNode) => {
81938212 let blinded_onion_error = HTLCFailReason::reason(
@@ -8196,7 +8215,7 @@ where
81968215 );
81978216 let err_packet = blinded_onion_error.get_encrypted_failure_packet(
81988217 incoming_packet_shared_secret,
8199- phantom_shared_secret ,
8218+ &secondary_shared_secret ,
82008219 );
82018220 HTLCForwardInfo::FailHTLC { htlc_id: *htlc_id, err_packet }
82028221 },
@@ -8208,7 +8227,7 @@ where
82088227 None => {
82098228 let err_packet = onion_error.get_encrypted_failure_packet(
82108229 incoming_packet_shared_secret,
8211- phantom_shared_secret ,
8230+ &secondary_shared_secret ,
82128231 );
82138232 HTLCForwardInfo::FailHTLC { htlc_id: *htlc_id, err_packet }
82148233 },
@@ -15173,6 +15192,7 @@ impl_writeable_tlv_based_enum!(PendingHTLCRouting,
1517315192 (5, custom_tlvs, optional_vec),
1517415193 (7, requires_blinded_error, (default_value, false)),
1517515194 (9, payment_context, option),
15195+ (11, trampoline_shared_secret, option),
1517615196 },
1517715197 (2, ReceiveKeysend) => {
1517815198 (0, payment_preimage, required),
@@ -15301,6 +15321,7 @@ impl_writeable_tlv_based!(HTLCPreviousHopData, {
1530115321 // filled in, so we can safely unwrap it here.
1530215322 (9, channel_id, (default_value, ChannelId::v1_from_funding_outpoint(outpoint.0.unwrap()))),
1530315323 (11, counterparty_node_id, option),
15324+ (13, trampoline_shared_secret, option),
1530415325});
1530515326
1530615327impl Writeable for ClaimableHTLC {
0 commit comments