mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 07:17:40 +01:00
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.
This commit is contained in:
parent
1596116fa4
commit
b64523780b
2 changed files with 23 additions and 3 deletions
|
@ -119,6 +119,8 @@ pub enum PendingHTLCRouting {
|
|||
/// The SCID from the onion that we should forward to. This could be a real SCID or a fake one
|
||||
/// generated using `get_fake_scid` from the scid_utils::fake_scid module.
|
||||
short_channel_id: u64, // This should be NonZero<u64> eventually when we bump MSRV
|
||||
/// Set if this HTLC is being forwarded within a blinded path.
|
||||
blinded: Option<BlindedForward>,
|
||||
},
|
||||
/// An HTLC paid to an invoice (supposedly) generated by us.
|
||||
/// At this point, we have not checked that the invoice being paid was actually generated by us,
|
||||
|
@ -155,6 +157,16 @@ pub enum PendingHTLCRouting {
|
|||
},
|
||||
}
|
||||
|
||||
/// Information used to forward or fail this HTLC that is being forwarded within a blinded path.
|
||||
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
|
||||
pub struct BlindedForward {
|
||||
/// The `blinding_point` that was set in the inbound [`msgs::UpdateAddHTLC`], or in the inbound
|
||||
/// onion payload if we're the introduction node. Useful for calculating the next hop's
|
||||
/// [`msgs::UpdateAddHTLC::blinding_point`].
|
||||
pub inbound_blinding_point: PublicKey,
|
||||
// Another field will be added here when we support forwarding as a non-intro node.
|
||||
}
|
||||
|
||||
/// Full details of an incoming HTLC, including routing info.
|
||||
#[derive(Clone)] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
|
||||
pub struct PendingHTLCInfo {
|
||||
|
@ -4013,8 +4025,10 @@ where
|
|||
})?;
|
||||
|
||||
let routing = match payment.forward_info.routing {
|
||||
PendingHTLCRouting::Forward { onion_packet, .. } => {
|
||||
PendingHTLCRouting::Forward { onion_packet, short_channel_id: next_hop_scid }
|
||||
PendingHTLCRouting::Forward { onion_packet, blinded, .. } => {
|
||||
PendingHTLCRouting::Forward {
|
||||
onion_packet, blinded, short_channel_id: next_hop_scid
|
||||
}
|
||||
},
|
||||
_ => unreachable!() // Only `PendingHTLCRouting::Forward`s are intercepted
|
||||
};
|
||||
|
@ -9143,9 +9157,14 @@ impl_writeable_tlv_based!(PhantomRouteHints, {
|
|||
(6, real_node_pubkey, required),
|
||||
});
|
||||
|
||||
impl_writeable_tlv_based!(BlindedForward, {
|
||||
(0, inbound_blinding_point, required),
|
||||
});
|
||||
|
||||
impl_writeable_tlv_based_enum!(PendingHTLCRouting,
|
||||
(0, Forward) => {
|
||||
(0, onion_packet, required),
|
||||
(1, blinded, option),
|
||||
(2, short_channel_id, required),
|
||||
},
|
||||
(1, Receive) => {
|
||||
|
|
|
@ -56,6 +56,7 @@ pub(super) fn create_fwd_pending_htlc_info(
|
|||
routing: PendingHTLCRouting::Forward {
|
||||
onion_packet: outgoing_packet,
|
||||
short_channel_id,
|
||||
blinded: None,
|
||||
},
|
||||
payment_hash: msg.payment_hash,
|
||||
incoming_shared_secret: shared_secret,
|
||||
|
@ -414,7 +415,7 @@ mod tests {
|
|||
.map_err(|e| e.msg).unwrap();
|
||||
|
||||
let next_onion = match peeled.routing {
|
||||
PendingHTLCRouting::Forward { onion_packet, short_channel_id: _ } => {
|
||||
PendingHTLCRouting::Forward { onion_packet, .. } => {
|
||||
onion_packet
|
||||
},
|
||||
_ => panic!("expected a forwarded onion"),
|
||||
|
|
Loading…
Add table
Reference in a new issue