Skip to content

Commit b645237

Browse files
Store whether a forwarded HTLC is blinded in PendingHTLCRouting
We need to store the inbound blinding point in PendingHTLCRouting in order to calculate the outbound blinding point. The new BlindedForward struct will be augmented when we add support for forwarding as a non-intro node.
1 parent 1596116 commit b645237

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ pub enum PendingHTLCRouting {
119119
/// The SCID from the onion that we should forward to. This could be a real SCID or a fake one
120120
/// generated using `get_fake_scid` from the scid_utils::fake_scid module.
121121
short_channel_id: u64, // This should be NonZero<u64> eventually when we bump MSRV
122+
/// Set if this HTLC is being forwarded within a blinded path.
123+
blinded: Option<BlindedForward>,
122124
},
123125
/// An HTLC paid to an invoice (supposedly) generated by us.
124126
/// At this point, we have not checked that the invoice being paid was actually generated by us,
@@ -155,6 +157,16 @@ pub enum PendingHTLCRouting {
155157
},
156158
}
157159

160+
/// Information used to forward or fail this HTLC that is being forwarded within a blinded path.
161+
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
162+
pub struct BlindedForward {
163+
/// The `blinding_point` that was set in the inbound [`msgs::UpdateAddHTLC`], or in the inbound
164+
/// onion payload if we're the introduction node. Useful for calculating the next hop's
165+
/// [`msgs::UpdateAddHTLC::blinding_point`].
166+
pub inbound_blinding_point: PublicKey,
167+
// Another field will be added here when we support forwarding as a non-intro node.
168+
}
169+
158170
/// Full details of an incoming HTLC, including routing info.
159171
#[derive(Clone)] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
160172
pub struct PendingHTLCInfo {
@@ -4013,8 +4025,10 @@ where
40134025
})?;
40144026

40154027
let routing = match payment.forward_info.routing {
4016-
PendingHTLCRouting::Forward { onion_packet, .. } => {
4017-
PendingHTLCRouting::Forward { onion_packet, short_channel_id: next_hop_scid }
4028+
PendingHTLCRouting::Forward { onion_packet, blinded, .. } => {
4029+
PendingHTLCRouting::Forward {
4030+
onion_packet, blinded, short_channel_id: next_hop_scid
4031+
}
40184032
},
40194033
_ => unreachable!() // Only `PendingHTLCRouting::Forward`s are intercepted
40204034
};
@@ -9143,9 +9157,14 @@ impl_writeable_tlv_based!(PhantomRouteHints, {
91439157
(6, real_node_pubkey, required),
91449158
});
91459159

9160+
impl_writeable_tlv_based!(BlindedForward, {
9161+
(0, inbound_blinding_point, required),
9162+
});
9163+
91469164
impl_writeable_tlv_based_enum!(PendingHTLCRouting,
91479165
(0, Forward) => {
91489166
(0, onion_packet, required),
9167+
(1, blinded, option),
91499168
(2, short_channel_id, required),
91509169
},
91519170
(1, Receive) => {

lightning/src/ln/onion_payment.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub(super) fn create_fwd_pending_htlc_info(
5656
routing: PendingHTLCRouting::Forward {
5757
onion_packet: outgoing_packet,
5858
short_channel_id,
59+
blinded: None,
5960
},
6061
payment_hash: msg.payment_hash,
6162
incoming_shared_secret: shared_secret,
@@ -414,7 +415,7 @@ mod tests {
414415
.map_err(|e| e.msg).unwrap();
415416

416417
let next_onion = match peeled.routing {
417-
PendingHTLCRouting::Forward { onion_packet, short_channel_id: _ } => {
418+
PendingHTLCRouting::Forward { onion_packet, .. } => {
418419
onion_packet
419420
},
420421
_ => panic!("expected a forwarded onion"),

0 commit comments

Comments
 (0)