-
Notifications
You must be signed in to change notification settings - Fork 409
Introduce MessageContext and use it to allow abandon failed payments #3085
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7e2fde7
Remove path_id from Responder, and OnionMessageResponse struct
shaavan 7f82cde
Introduce MessageContext in ReceiveTlvs
shaavan fbe9dfa
Update handle_message to accept OffersContext data as an input field
shaavan 42c096c
Allow create_blinded_paths functions to accept MessageContext as inpu…
shaavan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,6 +20,7 @@ use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode, NextMessage | |||||
use crate::blinded_path::utils; | ||||||
use crate::io; | ||||||
use crate::io::Cursor; | ||||||
use crate::ln::channelmanager::PaymentId; | ||||||
use crate::ln::onion_utils; | ||||||
use crate::onion_message::packet::ControlTlvs; | ||||||
use crate::sign::{NodeSigner, Recipient}; | ||||||
|
@@ -52,10 +53,10 @@ pub(crate) struct ForwardTlvs { | |||||
|
||||||
/// Similar to [`ForwardTlvs`], but these TLVs are for the final node. | ||||||
pub(crate) struct ReceiveTlvs { | ||||||
/// If `path_id` is `Some`, it is used to identify the blinded path that this onion message is | ||||||
/// If `context` is `Some`, it is used to identify the blinded path that this onion message is | ||||||
/// sending to. This is useful for receivers to check that said blinded path is being used in | ||||||
/// the right context. | ||||||
pub(crate) path_id: Option<[u8; 32]>, | ||||||
pub context: Option<MessageContext> | ||||||
} | ||||||
|
||||||
impl Writeable for ForwardTlvs { | ||||||
|
@@ -78,16 +79,62 @@ impl Writeable for ReceiveTlvs { | |||||
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> { | ||||||
// TODO: write padding | ||||||
shaavan marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
encode_tlv_stream!(writer, { | ||||||
(6, self.path_id, option), | ||||||
(65537, self.context, option), | ||||||
}); | ||||||
Ok(()) | ||||||
} | ||||||
} | ||||||
|
||||||
/// Represents additional data included by the recipient in a [`BlindedPath`]. | ||||||
/// | ||||||
/// This data is encrypted by the recipient and remains invisible to anyone else. | ||||||
/// It is included in the [`BlindedPath`], making it accessible again to the recipient | ||||||
/// whenever the [`BlindedPath`] is used. | ||||||
/// The recipient can authenticate the message and utilize it for further processing | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll update this in #3139 since I'm touching this. |
||||||
/// if needed. | ||||||
#[derive(Clone, Debug)] | ||||||
pub enum MessageContext { | ||||||
/// Represents the data specific to [`OffersMessage`] | ||||||
/// | ||||||
/// [`OffersMessage`]: crate::onion_message::offers::OffersMessage | ||||||
Offers(OffersContext), | ||||||
/// Represents custom data received in a Custom Onion Message. | ||||||
Custom(Vec<u8>), | ||||||
} | ||||||
|
||||||
/// Contains the data specific to [`OffersMessage`] | ||||||
/// | ||||||
/// [`OffersMessage`]: crate::onion_message::offers::OffersMessage | ||||||
#[derive(Clone, Debug)] | ||||||
pub enum OffersContext { | ||||||
/// Represents an unknown BOLT12 payment context. | ||||||
/// This variant is used when a message is sent without | ||||||
/// using a [`BlindedPath`] or over one created prior to | ||||||
/// LDK version 0.0.124. | ||||||
Unknown {}, | ||||||
/// Represents an outbound BOLT12 payment context. | ||||||
OutboundPayment { | ||||||
/// Payment ID of the outbound BOLT12 payment. | ||||||
payment_id: PaymentId | ||||||
}, | ||||||
} | ||||||
|
||||||
impl_writeable_tlv_based_enum!(MessageContext, ; | ||||||
shaavan marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
(0, Offers), | ||||||
(1, Custom), | ||||||
); | ||||||
|
||||||
impl_writeable_tlv_based_enum!(OffersContext, | ||||||
(0, Unknown) => {}, | ||||||
(1, OutboundPayment) => { | ||||||
(0, payment_id, required), | ||||||
}, | ||||||
;); | ||||||
|
||||||
/// 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, | ||||||
session_priv: &SecretKey | ||||||
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)); | ||||||
|
@@ -99,7 +146,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>( | |||||
None => NextMessageHop::NodeId(*pubkey), | ||||||
}) | ||||||
.map(|next_hop| ControlTlvs::Forward(ForwardTlvs { next_hop, next_blinding_override: None })) | ||||||
.chain(core::iter::once(ControlTlvs::Receive(ReceiveTlvs { path_id: None }))); | ||||||
.chain(core::iter::once(ControlTlvs::Receive(ReceiveTlvs{ context: Some(context) }))); | ||||||
|
||||||
utils::construct_blinded_hops(secp_ctx, pks, tlvs, session_priv) | ||||||
} | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.