Skip to content

Commit ba13326

Browse files
committed
Resolve blinded path when creating onion message
Add a version of the create_onion_message utility function that attempts to resolved the introduction node of the destination's BlindedPath using a ReadOnlyNetworkGraph`. Otherwise, if given a path using the compact representation, using create_onion_message would fail. Keep the current version for use internally and for external uses where the blinded path is known to be resolved.
1 parent dc3ee2a commit ba13326

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lightning/src/onion_message/messenger.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,42 @@ pub enum PeeledOnion<T: OnionMessageContents> {
577577
Receive(ParsedOnionMessageContents<T>, Option<[u8; 32]>, Option<BlindedPath>)
578578
}
579579

580+
581+
/// Creates an [`OnionMessage`] with the given `contents` for sending to the destination of
582+
/// `path`, first calling [`Destination::resolve`] on `path.destination` with the given
583+
/// [`ReadOnlyNetworkGraph`].
584+
///
585+
/// Returns the node id of the peer to send the message to, the message itself, and any addresses
586+
/// need to connect to the first node.
587+
pub fn create_onion_message_resolving_destination<
588+
ES: Deref, NS: Deref, NL: Deref, T: OnionMessageContents
589+
>(
590+
entropy_source: &ES, node_signer: &NS, node_id_lookup: &NL,
591+
network_graph: &ReadOnlyNetworkGraph, secp_ctx: &Secp256k1<secp256k1::All>,
592+
mut path: OnionMessagePath, contents: T, reply_path: Option<BlindedPath>,
593+
) -> Result<(PublicKey, OnionMessage, Option<Vec<SocketAddress>>), SendError>
594+
where
595+
ES::Target: EntropySource,
596+
NS::Target: NodeSigner,
597+
NL::Target: NodeIdLookUp,
598+
{
599+
path.destination.resolve(network_graph);
600+
create_onion_message(
601+
entropy_source, node_signer, node_id_lookup, secp_ctx, path, contents, reply_path,
602+
)
603+
}
604+
580605
/// Creates an [`OnionMessage`] with the given `contents` for sending to the destination of
581606
/// `path`.
582607
///
583608
/// Returns the node id of the peer to send the message to, the message itself, and any addresses
584609
/// need to connect to the first node.
610+
///
611+
/// Returns [`SendError::UnresolvedIntroductionNode`] if:
612+
/// - `destination` contains a blinded path with an [`IntroductionNode::DirectedShortChannelId`],
613+
/// - unless it can be resolved by [`NodeIdLookUp::next_node_id`].
614+
/// Use [`create_onion_message_resolving_destination`] instead to resolve the introduction node
615+
/// first with a [`ReadOnlyNetworkGraph`].
585616
pub fn create_onion_message<ES: Deref, NS: Deref, NL: Deref, T: OnionMessageContents>(
586617
entropy_source: &ES, node_signer: &NS, node_id_lookup: &NL,
587618
secp_ctx: &Secp256k1<secp256k1::All>, path: OnionMessagePath, contents: T,

0 commit comments

Comments
 (0)