Skip to content

Commit f3b5985

Browse files
Support next_blinding_override in blinded payment paths.
This allow us to forward blinded payments where the blinded path that we are forwarding within was concatenated to another blinded path that starts at the next hop. Also allows constructing blinded paths using this override.
1 parent a76ec06 commit f3b5985

File tree

6 files changed

+38
-10
lines changed

6 files changed

+38
-10
lines changed

lightning/src/blinded_path/payment.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ pub struct ForwardTlvs {
6161
///
6262
/// [`BlindedHop::encrypted_payload`]: crate::blinded_path::BlindedHop::encrypted_payload
6363
pub features: BlindedHopFeatures,
64+
/// Set if this [`BlindedPath`] is concatenated to another, to indicate the
65+
/// [`BlindedPath::blinding_point`] of the appended blinded path.
66+
pub next_blinding_override: Option<PublicKey>,
6467
}
6568

6669
/// Data to construct a [`BlindedHop`] for receiving a payment. This payload is custom to LDK and
@@ -240,6 +243,7 @@ impl Readable for BlindedPaymentTlvs {
240243
_init_and_read_tlv_stream!(r, {
241244
(1, _padding, option),
242245
(2, scid, option),
246+
(8, next_blinding_override, option),
243247
(10, payment_relay, option),
244248
(12, payment_constraints, required),
245249
(14, features, option),
@@ -256,6 +260,7 @@ impl Readable for BlindedPaymentTlvs {
256260
short_channel_id,
257261
payment_relay: payment_relay.ok_or(DecodeError::InvalidValue)?,
258262
payment_constraints: payment_constraints.0.unwrap(),
263+
next_blinding_override,
259264
features: features.unwrap_or_else(BlindedHopFeatures::empty),
260265
}))
261266
} else {
@@ -500,6 +505,7 @@ mod tests {
500505
max_cltv_expiry: 0,
501506
htlc_minimum_msat: 100,
502507
},
508+
next_blinding_override: None,
503509
features: BlindedHopFeatures::empty(),
504510
},
505511
htlc_maximum_msat: u64::max_value(),
@@ -516,6 +522,7 @@ mod tests {
516522
max_cltv_expiry: 0,
517523
htlc_minimum_msat: 1_000,
518524
},
525+
next_blinding_override: None,
519526
features: BlindedHopFeatures::empty(),
520527
},
521528
htlc_maximum_msat: u64::max_value(),
@@ -573,6 +580,7 @@ mod tests {
573580
max_cltv_expiry: 0,
574581
htlc_minimum_msat: 1,
575582
},
583+
next_blinding_override: None,
576584
features: BlindedHopFeatures::empty(),
577585
},
578586
htlc_maximum_msat: u64::max_value()
@@ -589,6 +597,7 @@ mod tests {
589597
max_cltv_expiry: 0,
590598
htlc_minimum_msat: 2_000,
591599
},
600+
next_blinding_override: None,
592601
features: BlindedHopFeatures::empty(),
593602
},
594603
htlc_maximum_msat: u64::max_value()
@@ -624,6 +633,7 @@ mod tests {
624633
max_cltv_expiry: 0,
625634
htlc_minimum_msat: 5_000,
626635
},
636+
next_blinding_override: None,
627637
features: BlindedHopFeatures::empty(),
628638
},
629639
htlc_maximum_msat: u64::max_value()
@@ -640,6 +650,7 @@ mod tests {
640650
max_cltv_expiry: 0,
641651
htlc_minimum_msat: 2_000,
642652
},
653+
next_blinding_override: None,
643654
features: BlindedHopFeatures::empty(),
644655
},
645656
htlc_maximum_msat: u64::max_value()
@@ -679,6 +690,7 @@ mod tests {
679690
max_cltv_expiry: 0,
680691
htlc_minimum_msat: 1,
681692
},
693+
next_blinding_override: None,
682694
features: BlindedHopFeatures::empty(),
683695
},
684696
htlc_maximum_msat: 5_000,
@@ -695,6 +707,7 @@ mod tests {
695707
max_cltv_expiry: 0,
696708
htlc_minimum_msat: 1,
697709
},
710+
next_blinding_override: None,
698711
features: BlindedHopFeatures::empty(),
699712
},
700713
htlc_maximum_msat: 10_000

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ fn blinded_payment_path(
5050
htlc_minimum_msat: intro_node_min_htlc_opt.take()
5151
.unwrap_or_else(|| channel_upds[idx - 1].htlc_minimum_msat),
5252
},
53+
next_blinding_override: None,
5354
features: BlindedHopFeatures::empty(),
5455
},
5556
htlc_maximum_msat: intro_node_max_htlc_opt.take()

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ pub struct BlindedForward {
225225
/// If needed, this determines how this HTLC should be failed backwards, based on whether we are
226226
/// the introduction node.
227227
pub failure: BlindedFailure,
228+
/// Overrides the next hop's [`msgs::UpdateAddHTLC::blinding_point`]. Set if this HTLC is being
229+
/// forwarded within a [`BlindedPath`] that was concatenated to another blinded path that starts
230+
/// at the next hop.
231+
pub next_blinding_override: Option<PublicKey>,
228232
}
229233

230234
impl PendingHTLCRouting {
@@ -5308,12 +5312,14 @@ where
53085312
blinded_failure: blinded.map(|b| b.failure),
53095313
});
53105314
let next_blinding_point = blinded.and_then(|b| {
5311-
let encrypted_tlvs_ss = self.node_signer.ecdh(
5312-
Recipient::Node, &b.inbound_blinding_point, None
5313-
).unwrap().secret_bytes();
5314-
onion_utils::next_hop_pubkey(
5315-
&self.secp_ctx, b.inbound_blinding_point, &encrypted_tlvs_ss
5316-
).ok()
5315+
b.next_blinding_override.or_else(|| {
5316+
let encrypted_tlvs_ss = self.node_signer.ecdh(
5317+
Recipient::Node, &b.inbound_blinding_point, None
5318+
).unwrap().secret_bytes();
5319+
onion_utils::next_hop_pubkey(
5320+
&self.secp_ctx, b.inbound_blinding_point, &encrypted_tlvs_ss
5321+
).ok()
5322+
})
53175323
});
53185324

53195325
// Forward the HTLC over the most appropriate channel with the corresponding peer,
@@ -11009,6 +11015,7 @@ impl_writeable_tlv_based!(PhantomRouteHints, {
1100911015
impl_writeable_tlv_based!(BlindedForward, {
1101011016
(0, inbound_blinding_point, required),
1101111017
(1, failure, (default_value, BlindedFailure::FromIntroductionNode)),
11018+
(3, next_blinding_override, option),
1101211019
});
1101311020

1101411021
impl_writeable_tlv_based_enum!(PendingHTLCRouting,

lightning/src/ln/msgs.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,7 @@ mod fuzzy_internal_msgs {
17291729
payment_constraints: PaymentConstraints,
17301730
features: BlindedHopFeatures,
17311731
intro_node_blinding_point: Option<PublicKey>,
1732+
next_blinding_override: Option<PublicKey>,
17321733
},
17331734
BlindedReceive {
17341735
sender_intended_htlc_amt_msat: u64,
@@ -2758,7 +2759,7 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, &NS)> for InboundOnionPayload w
27582759
let mut reader = FixedLengthReader::new(&mut s, enc_tlvs.len() as u64);
27592760
match ChaChaPolyReadAdapter::read(&mut reader, rho)? {
27602761
ChaChaPolyReadAdapter { readable: BlindedPaymentTlvs::Forward(ForwardTlvs {
2761-
short_channel_id, payment_relay, payment_constraints, features
2762+
short_channel_id, payment_relay, payment_constraints, features, next_blinding_override
27622763
})} => {
27632764
if amt.is_some() || cltv_value.is_some() || total_msat.is_some() ||
27642765
keysend_preimage.is_some()
@@ -2771,6 +2772,7 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, &NS)> for InboundOnionPayload w
27712772
payment_constraints,
27722773
features,
27732774
intro_node_blinding_point,
2775+
next_blinding_override,
27742776
})
27752777
},
27762778
ChaChaPolyReadAdapter { readable: BlindedPaymentTlvs::Receive(ReceiveTlvs {

lightning/src/ln/onion_payment.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ pub(super) fn create_fwd_pending_htlc_info(
7575
};
7676

7777
let (
78-
short_channel_id, amt_to_forward, outgoing_cltv_value, intro_node_blinding_point
78+
short_channel_id, amt_to_forward, outgoing_cltv_value, intro_node_blinding_point,
79+
next_blinding_override
7980
) = match hop_data {
8081
msgs::InboundOnionPayload::Forward { short_channel_id, amt_to_forward, outgoing_cltv_value } =>
81-
(short_channel_id, amt_to_forward, outgoing_cltv_value, None),
82+
(short_channel_id, amt_to_forward, outgoing_cltv_value, None, None),
8283
msgs::InboundOnionPayload::BlindedForward {
8384
short_channel_id, payment_relay, payment_constraints, intro_node_blinding_point, features,
85+
next_blinding_override,
8486
} => {
8587
let (amt_to_forward, outgoing_cltv_value) = check_blinded_forward(
8688
msg.amount_msat, msg.cltv_expiry, &payment_relay, &payment_constraints, &features
@@ -93,7 +95,8 @@ pub(super) fn create_fwd_pending_htlc_info(
9395
err_data: vec![0; 32],
9496
}
9597
})?;
96-
(short_channel_id, amt_to_forward, outgoing_cltv_value, intro_node_blinding_point)
98+
(short_channel_id, amt_to_forward, outgoing_cltv_value, intro_node_blinding_point,
99+
next_blinding_override)
97100
},
98101
msgs::InboundOnionPayload::Receive { .. } | msgs::InboundOnionPayload::BlindedReceive { .. } =>
99102
return Err(InboundHTLCErr {
@@ -110,6 +113,7 @@ pub(super) fn create_fwd_pending_htlc_info(
110113
blinded: intro_node_blinding_point.or(msg.blinding_point)
111114
.map(|bp| BlindedForward {
112115
inbound_blinding_point: bp,
116+
next_blinding_override,
113117
failure: intro_node_blinding_point
114118
.map(|_| BlindedFailure::FromIntroductionNode)
115119
.unwrap_or(BlindedFailure::FromBlindedNode),

lightning/src/routing/router.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, ES: Deref, S: Deref,
149149
short_channel_id,
150150
payment_relay,
151151
payment_constraints,
152+
next_blinding_override: None,
152153
features: BlindedHopFeatures::empty(),
153154
},
154155
node_id: details.counterparty.node_id,

0 commit comments

Comments
 (0)