Skip to content

Disambiguate blinded path ForwardNodes between payment + message #3265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions fuzz/src/invoice_request_deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::utils::test_logger;
use bitcoin::secp256k1::{self, Keypair, Parity, PublicKey, Secp256k1, SecretKey};
use core::convert::TryFrom;
use lightning::blinded_path::payment::{
BlindedPaymentPath, Bolt12OfferContext, ForwardNode, ForwardTlvs, PaymentConstraints,
PaymentContext, PaymentRelay, ReceiveTlvs,
BlindedPaymentPath, Bolt12OfferContext, ForwardTlvs, PaymentConstraints, PaymentContext,
PaymentForwardNode, PaymentRelay, ReceiveTlvs,
};
use lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA;
use lightning::ln::features::BlindedHopFeatures;
Expand Down Expand Up @@ -100,7 +100,7 @@ fn build_response<T: secp256k1::Signing + secp256k1::Verification>(
},
payment_context,
};
let intermediate_nodes = [ForwardNode {
let intermediate_nodes = [PaymentForwardNode {
tlvs: ForwardTlvs {
short_channel_id: 43,
payment_relay: PaymentRelay {
Expand Down
6 changes: 3 additions & 3 deletions fuzz/src/refund_deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::utils::test_logger;
use bitcoin::secp256k1::{self, Keypair, PublicKey, Secp256k1, SecretKey};
use core::convert::TryFrom;
use lightning::blinded_path::payment::{
BlindedPaymentPath, Bolt12RefundContext, ForwardNode, ForwardTlvs, PaymentConstraints,
PaymentContext, PaymentRelay, ReceiveTlvs,
BlindedPaymentPath, Bolt12RefundContext, ForwardTlvs, PaymentConstraints, PaymentContext,
PaymentForwardNode, PaymentRelay, ReceiveTlvs,
};
use lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA;
use lightning::ln::features::BlindedHopFeatures;
Expand Down Expand Up @@ -78,7 +78,7 @@ fn build_response<T: secp256k1::Signing + secp256k1::Verification>(
},
payment_context,
};
let intermediate_nodes = [ForwardNode {
let intermediate_nodes = [PaymentForwardNode {
tlvs: ForwardTlvs {
short_channel_id: 43,
payment_relay: PaymentRelay {
Expand Down
14 changes: 7 additions & 7 deletions lightning/src/blinded_path/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ impl BlindedMessagePath {
/// Errors if no hops are provided or if `node_pk`(s) are invalid.
// TODO: make all payloads the same size with padding + add dummy hops
pub fn new<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
intermediate_nodes: &[ForwardNode], recipient_node_id: PublicKey, context: MessageContext,
entropy_source: ES, secp_ctx: &Secp256k1<T>
intermediate_nodes: &[MessageForwardNode], recipient_node_id: PublicKey,
context: MessageContext, entropy_source: ES, secp_ctx: &Secp256k1<T>,
) -> Result<Self, ()> where ES::Target: EntropySource {
let introduction_node = IntroductionNode::NodeId(
intermediate_nodes.first().map_or(recipient_node_id, |n| n.node_id)
Expand Down Expand Up @@ -216,12 +216,12 @@ pub enum NextMessageHop {

/// An intermediate node, and possibly a short channel id leading to the next node.
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
pub struct ForwardNode {
pub struct MessageForwardNode {
/// This node's pubkey.
pub node_id: PublicKey,
/// The channel between `node_id` and the next hop. If set, the constructed [`BlindedHop`]'s
/// `encrypted_payload` will use this instead of the next [`ForwardNode::node_id`] for a more
/// compact representation.
/// `encrypted_payload` will use this instead of the next [`MessageForwardNode::node_id`] for a
/// more compact representation.
pub short_channel_id: Option<u64>,
}

Expand Down Expand Up @@ -371,8 +371,8 @@ impl_writeable_tlv_based_enum!(OffersContext,

/// Construct blinded onion message hops for the given `intermediate_nodes` and `recipient_node_id`.
pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
secp_ctx: &Secp256k1<T>, intermediate_nodes: &[ForwardNode], recipient_node_id: PublicKey,
context: MessageContext, session_priv: &SecretKey
secp_ctx: &Secp256k1<T>, intermediate_nodes: &[MessageForwardNode],
recipient_node_id: PublicKey, context: MessageContext, session_priv: &SecretKey,
) -> Result<Vec<BlindedHop>, secp256k1::Error> {
let pks = intermediate_nodes.iter().map(|node| &node.node_id)
.chain(core::iter::once(&recipient_node_id));
Expand Down
34 changes: 17 additions & 17 deletions lightning/src/blinded_path/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ impl BlindedPaymentPath {
/// * any unknown features are required in the provided [`ForwardTlvs`]
// TODO: make all payloads the same size with padding + add dummy hops
pub fn new<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
intermediate_nodes: &[ForwardNode], payee_node_id: PublicKey, payee_tlvs: ReceiveTlvs,
htlc_maximum_msat: u64, min_final_cltv_expiry_delta: u16, entropy_source: ES,
secp_ctx: &Secp256k1<T>
intermediate_nodes: &[PaymentForwardNode], payee_node_id: PublicKey,
payee_tlvs: ReceiveTlvs, htlc_maximum_msat: u64, min_final_cltv_expiry_delta: u16,
entropy_source: ES, secp_ctx: &Secp256k1<T>,
) -> Result<Self, ()> where ES::Target: EntropySource {
let introduction_node = IntroductionNode::NodeId(
intermediate_nodes.first().map_or(payee_node_id, |n| n.node_id)
Expand Down Expand Up @@ -221,7 +221,7 @@ impl BlindedPaymentPath {

/// An intermediate node, its outbound channel, and relay parameters.
#[derive(Clone, Debug)]
pub struct ForwardNode {
pub struct PaymentForwardNode {
/// The TLVs for this node's [`BlindedHop`], where the fee parameters contained within are also
/// used for [`BlindedPayInfo`] construction.
pub tlvs: ForwardTlvs,
Expand Down Expand Up @@ -459,8 +459,8 @@ impl Readable for BlindedPaymentTlvs {

/// Construct blinded payment hops for the given `intermediate_nodes` and payee info.
pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
secp_ctx: &Secp256k1<T>, intermediate_nodes: &[ForwardNode],
payee_node_id: PublicKey, payee_tlvs: ReceiveTlvs, session_priv: &SecretKey
secp_ctx: &Secp256k1<T>, intermediate_nodes: &[PaymentForwardNode],
payee_node_id: PublicKey, payee_tlvs: ReceiveTlvs, session_priv: &SecretKey,
) -> Result<Vec<BlindedHop>, secp256k1::Error> {
let pks = intermediate_nodes.iter().map(|node| &node.node_id)
.chain(core::iter::once(&payee_node_id));
Expand Down Expand Up @@ -491,8 +491,8 @@ pub(crate) fn amt_to_forward_msat(inbound_amt_msat: u64, payment_relay: &Payment
}

pub(super) fn compute_payinfo(
intermediate_nodes: &[ForwardNode], payee_tlvs: &ReceiveTlvs, payee_htlc_maximum_msat: u64,
min_final_cltv_expiry_delta: u16
intermediate_nodes: &[PaymentForwardNode], payee_tlvs: &ReceiveTlvs,
payee_htlc_maximum_msat: u64, min_final_cltv_expiry_delta: u16,
) -> Result<BlindedPayInfo, ()> {
let mut curr_base_fee: u64 = 0;
let mut curr_prop_mil: u64 = 0;
Expand Down Expand Up @@ -628,7 +628,7 @@ impl_writeable_tlv_based!(Bolt12RefundContext, {});
#[cfg(test)]
mod tests {
use bitcoin::secp256k1::PublicKey;
use crate::blinded_path::payment::{ForwardNode, ForwardTlvs, ReceiveTlvs, PaymentConstraints, PaymentContext, PaymentRelay};
use crate::blinded_path::payment::{PaymentForwardNode, ForwardTlvs, ReceiveTlvs, PaymentConstraints, PaymentContext, PaymentRelay};
use crate::ln::types::PaymentSecret;
use crate::ln::features::BlindedHopFeatures;
use crate::ln::functional_test_utils::TEST_FINAL_CLTV;
Expand All @@ -638,7 +638,7 @@ mod tests {
// Taken from the spec example for aggregating blinded payment info. See
// https://github.com/lightning/bolts/blob/master/proposals/route-blinding.md#blinded-payments
let dummy_pk = PublicKey::from_slice(&[2; 33]).unwrap();
let intermediate_nodes = vec![ForwardNode {
let intermediate_nodes = vec![PaymentForwardNode {
node_id: dummy_pk,
tlvs: ForwardTlvs {
short_channel_id: 0,
Expand All @@ -655,7 +655,7 @@ mod tests {
features: BlindedHopFeatures::empty(),
},
htlc_maximum_msat: u64::max_value(),
}, ForwardNode {
}, PaymentForwardNode {
node_id: dummy_pk,
tlvs: ForwardTlvs {
short_channel_id: 0,
Expand Down Expand Up @@ -713,7 +713,7 @@ mod tests {
// If no hops charge fees, the htlc_minimum_msat should just be the maximum htlc_minimum_msat
// along the path.
let dummy_pk = PublicKey::from_slice(&[2; 33]).unwrap();
let intermediate_nodes = vec![ForwardNode {
let intermediate_nodes = vec![PaymentForwardNode {
node_id: dummy_pk,
tlvs: ForwardTlvs {
short_channel_id: 0,
Expand All @@ -730,7 +730,7 @@ mod tests {
features: BlindedHopFeatures::empty(),
},
htlc_maximum_msat: u64::max_value()
}, ForwardNode {
}, PaymentForwardNode {
node_id: dummy_pk,
tlvs: ForwardTlvs {
short_channel_id: 0,
Expand Down Expand Up @@ -766,7 +766,7 @@ mod tests {
// Create a path with varying fees and htlc_mins, and make sure htlc_minimum_msat ends up as the
// max (htlc_min - following_fees) along the path.
let dummy_pk = PublicKey::from_slice(&[2; 33]).unwrap();
let intermediate_nodes = vec![ForwardNode {
let intermediate_nodes = vec![PaymentForwardNode {
node_id: dummy_pk,
tlvs: ForwardTlvs {
short_channel_id: 0,
Expand All @@ -783,7 +783,7 @@ mod tests {
features: BlindedHopFeatures::empty(),
},
htlc_maximum_msat: u64::max_value()
}, ForwardNode {
}, PaymentForwardNode {
node_id: dummy_pk,
tlvs: ForwardTlvs {
short_channel_id: 0,
Expand Down Expand Up @@ -823,7 +823,7 @@ mod tests {
// Create a path with varying fees and `htlc_maximum_msat`s, and make sure the aggregated max
// htlc ends up as the min (htlc_max - following_fees) along the path.
let dummy_pk = PublicKey::from_slice(&[2; 33]).unwrap();
let intermediate_nodes = vec![ForwardNode {
let intermediate_nodes = vec![PaymentForwardNode {
node_id: dummy_pk,
tlvs: ForwardTlvs {
short_channel_id: 0,
Expand All @@ -840,7 +840,7 @@ mod tests {
features: BlindedHopFeatures::empty(),
},
htlc_maximum_msat: 5_000,
}, ForwardNode {
}, PaymentForwardNode {
node_id: dummy_pk,
tlvs: ForwardTlvs {
short_channel_id: 0,
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/blinded_payment_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey, schnorr};
use bitcoin::secp256k1::ecdh::SharedSecret;
use bitcoin::secp256k1::ecdsa::{RecoverableSignature, Signature};
use crate::blinded_path;
use crate::blinded_path::payment::{BlindedPaymentPath, ForwardNode, ForwardTlvs, PaymentConstraints, PaymentContext, PaymentRelay, ReceiveTlvs};
use crate::blinded_path::payment::{BlindedPaymentPath, PaymentForwardNode, ForwardTlvs, PaymentConstraints, PaymentContext, PaymentRelay, ReceiveTlvs};
use crate::events::{Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, PaymentFailureReason};
use crate::ln::types::{ChannelId, PaymentHash, PaymentSecret};
use crate::ln::channelmanager;
Expand Down Expand Up @@ -44,7 +44,7 @@ fn blinded_payment_path(
let mut intro_node_min_htlc_opt = Some(intro_node_min_htlc);
let mut intro_node_max_htlc_opt = Some(intro_node_max_htlc);
for (idx, (node_id, chan_upd)) in node_ids.iter().zip(channel_upds).enumerate() {
intermediate_nodes.push(ForwardNode {
intermediate_nodes.push(PaymentForwardNode {
node_id: *node_id,
tlvs: ForwardTlvs {
short_channel_id: chan_upd.short_channel_id,
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use bitcoin::{secp256k1, Sequence};

use crate::blinded_path::message::{MessageContext, OffersContext};
use crate::blinded_path::NodeIdLookUp;
use crate::blinded_path::message::{BlindedMessagePath, ForwardNode};
use crate::blinded_path::message::{BlindedMessagePath, MessageForwardNode};
use crate::blinded_path::payment::{BlindedPaymentPath, Bolt12OfferContext, Bolt12RefundContext, PaymentConstraints, PaymentContext, ReceiveTlvs};
use crate::chain;
use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
Expand Down Expand Up @@ -9354,7 +9354,7 @@ where
.map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
.filter(|(_, peer)| peer.is_connected)
.filter(|(_, peer)| peer.latest_features.supports_onion_messages())
.map(|(node_id, peer)| ForwardNode {
.map(|(node_id, peer)| MessageForwardNode {
node_id: *node_id,
short_channel_id: peer.channel_by_id
.iter()
Expand Down
34 changes: 17 additions & 17 deletions lightning/src/onion_message/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! Onion message testing and test utilities live here.

use crate::blinded_path::EmptyNodeIdLookUp;
use crate::blinded_path::message::{BlindedMessagePath, ForwardNode, MessageContext, OffersContext};
use crate::blinded_path::message::{BlindedMessagePath, MessageForwardNode, MessageContext, OffersContext};
use crate::events::{Event, EventsProvider};
use crate::ln::features::{ChannelFeatures, InitFeatures};
use crate::ln::msgs::{self, DecodeError, OnionMessageHandler};
Expand Down Expand Up @@ -386,7 +386,7 @@ fn two_unblinded_two_blinded() {
let test_msg = TestCustomMessage::Pong;

let secp_ctx = Secp256k1::new();
let intermediate_nodes = [ForwardNode { node_id: nodes[3].node_id, short_channel_id: None }];
let intermediate_nodes = [MessageForwardNode { node_id: nodes[3].node_id, short_channel_id: None }];
let context = MessageContext::Custom(Vec::new());
let blinded_path = BlindedMessagePath::new(&intermediate_nodes, nodes[4].node_id, context, &*nodes[4].entropy_source, &secp_ctx).unwrap();
let path = OnionMessagePath {
Expand All @@ -407,8 +407,8 @@ fn three_blinded_hops() {

let secp_ctx = Secp256k1::new();
let intermediate_nodes = [
ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
ForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
MessageForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
MessageForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
];
let context = MessageContext::Custom(Vec::new());
let blinded_path = BlindedMessagePath::new(&intermediate_nodes, nodes[3].node_id, context, &*nodes[3].entropy_source, &secp_ctx).unwrap();
Expand Down Expand Up @@ -548,8 +548,8 @@ fn we_are_intro_node() {

let secp_ctx = Secp256k1::new();
let intermediate_nodes = [
ForwardNode { node_id: nodes[0].node_id, short_channel_id: None },
ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
MessageForwardNode { node_id: nodes[0].node_id, short_channel_id: None },
MessageForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
];
let context = MessageContext::Custom(Vec::new());
let blinded_path = BlindedMessagePath::new(&intermediate_nodes, nodes[2].node_id, context, &*nodes[2].entropy_source, &secp_ctx).unwrap();
Expand All @@ -560,7 +560,7 @@ fn we_are_intro_node() {
pass_along_path(&nodes);

// Try with a two-hop blinded path where we are the introduction node.
let intermediate_nodes = [ForwardNode { node_id: nodes[0].node_id, short_channel_id: None }];
let intermediate_nodes = [MessageForwardNode { node_id: nodes[0].node_id, short_channel_id: None }];
let context = MessageContext::Custom(Vec::new());
let blinded_path = BlindedMessagePath::new(&intermediate_nodes, nodes[1].node_id, context, &*nodes[1].entropy_source, &secp_ctx).unwrap();
let destination = Destination::BlindedPath(blinded_path);
Expand All @@ -577,7 +577,7 @@ fn invalid_blinded_path_error() {
let test_msg = TestCustomMessage::Pong;

let secp_ctx = Secp256k1::new();
let intermediate_nodes = [ForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
let intermediate_nodes = [MessageForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
let context = MessageContext::Custom(Vec::new());
let mut blinded_path = BlindedMessagePath::new(&intermediate_nodes, nodes[2].node_id, context, &*nodes[2].entropy_source, &secp_ctx).unwrap();
blinded_path.clear_blinded_hops();
Expand All @@ -599,8 +599,8 @@ fn reply_path() {
first_node_addresses: None,
};
let intermediate_nodes = [
ForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
MessageForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
MessageForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
];
let context = MessageContext::Custom(Vec::new());
let reply_path = BlindedMessagePath::new(&intermediate_nodes, nodes[0].node_id, context, &*nodes[0].entropy_source, &secp_ctx).unwrap();
Expand All @@ -614,15 +614,15 @@ fn reply_path() {

// Destination::BlindedPath
let intermediate_nodes = [
ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
ForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
MessageForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
MessageForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
];
let context = MessageContext::Custom(Vec::new());
let blinded_path = BlindedMessagePath::new(&intermediate_nodes, nodes[3].node_id, context, &*nodes[3].entropy_source, &secp_ctx).unwrap();
let destination = Destination::BlindedPath(blinded_path);
let intermediate_nodes = [
ForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
MessageForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
MessageForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
];
let context = MessageContext::Custom(Vec::new());
let reply_path = BlindedMessagePath::new(&intermediate_nodes, nodes[0].node_id, context, &*nodes[0].entropy_source, &secp_ctx).unwrap();
Expand Down Expand Up @@ -705,7 +705,7 @@ fn requests_peer_connection_for_buffered_messages() {
let secp_ctx = Secp256k1::new();
add_channel_to_graph(&nodes[0], &nodes[1], &secp_ctx, 42);

let intermediate_nodes = [ForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
let intermediate_nodes = [MessageForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
let context = MessageContext::Custom(Vec::new());
let blinded_path = BlindedMessagePath::new(
&intermediate_nodes, nodes[2].node_id, context, &*nodes[0].entropy_source, &secp_ctx
Expand Down Expand Up @@ -744,7 +744,7 @@ fn drops_buffered_messages_waiting_for_peer_connection() {
let secp_ctx = Secp256k1::new();
add_channel_to_graph(&nodes[0], &nodes[1], &secp_ctx, 42);

let intermediate_nodes = [ForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
let intermediate_nodes = [MessageForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
let context = MessageContext::Custom(Vec::new());
let blinded_path = BlindedMessagePath::new(
&intermediate_nodes, nodes[2].node_id, context, &*nodes[0].entropy_source, &secp_ctx
Expand Down Expand Up @@ -795,7 +795,7 @@ fn intercept_offline_peer_oms() {

let message = TestCustomMessage::Pong;
let secp_ctx = Secp256k1::new();
let intermediate_nodes = [ForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
let intermediate_nodes = [MessageForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
let context = MessageContext::Custom(Vec::new());
let blinded_path = BlindedMessagePath::new(
&intermediate_nodes, nodes[2].node_id, context, &*nodes[2].entropy_source, &secp_ctx
Expand Down
Loading
Loading