-
Notifications
You must be signed in to change notification settings - Fork 411
Handle receiving payments via Trampoline #3670
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
Changes from 5 commits
4741892
0c82cc2
a293d21
313f344
23b4c80
dc14f26
35ff142
a6f4c7f
3970f1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,6 @@ use bitcoin::script::ScriptBuf; | |
use bitcoin::hash_types::Txid; | ||
|
||
use crate::blinded_path::payment::{BlindedPaymentTlvs, ForwardTlvs, ReceiveTlvs, UnauthenticatedReceiveTlvs}; | ||
#[cfg(trampoline)] | ||
use crate::blinded_path::payment::{BlindedTrampolineTlvs, TrampolineForwardTlvs}; | ||
use crate::ln::channelmanager::Verification; | ||
use crate::ln::types::ChannelId; | ||
|
@@ -2075,12 +2074,11 @@ mod fuzzy_internal_msgs { | |
pub outgoing_cltv_value: u32, | ||
} | ||
|
||
#[cfg(trampoline)] | ||
#[cfg_attr(trampoline, allow(unused))] | ||
#[allow(unused)] | ||
pub struct InboundTrampolineEntrypointPayload { | ||
pub amt_to_forward: u64, | ||
pub outgoing_cltv_value: u32, | ||
pub multipath_trampoline_data: FinalOnionHopData, | ||
pub multipath_trampoline_data: Option<FinalOnionHopData>, | ||
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. Is this the discussion you're referring to in the commit message? lightning/bolts#836 (comment) 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. yup, exactly! @t-bast and I discussed it a bit offline, and I believe they're assessing Eclair code viability for not mandating it outside of MPP scenarios. Alternatively, I can also make it mandatory on the sending side (right now we have an internal mismatch), but I think this approach makes more sense for now. 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'd think that for simplicity, it may be better to just always set this field? One code path. 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'd agree, although it's all cfg-gated for now anyway I suppose... @arik-so was the reason for doing this now for ease of testing? 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. Partially. The other option would require us deciding on a mechanism to convert the prng_seed into a pseudo-random payment secret in the outgoing onion construction method, that's about it. 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. But generating that secret is something to be looked at when implementing the forwarding part isn't it? Isn't it best for now to stick with the proposed spec? 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. The spec did actually get updated this morning to make it optional for the outer onion. 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. Maybe should update the commit message then? |
||
pub trampoline_packet: TrampolineOnionPacket, | ||
/// The blinding point this hop needs to decrypt its Trampoline onion. | ||
/// This is used for Trampoline hops that are not the blinded path intro hop. | ||
|
@@ -2118,23 +2116,19 @@ mod fuzzy_internal_msgs { | |
|
||
pub enum InboundOnionPayload { | ||
Forward(InboundOnionForwardPayload), | ||
#[cfg(trampoline)] | ||
#[cfg_attr(trampoline, allow(unused))] | ||
TrampolineEntrypoint(InboundTrampolineEntrypointPayload), | ||
Receive(InboundOnionReceivePayload), | ||
BlindedForward(InboundOnionBlindedForwardPayload), | ||
BlindedReceive(InboundOnionBlindedReceivePayload), | ||
} | ||
|
||
#[cfg(trampoline)] | ||
pub struct InboundTrampolineForwardPayload { | ||
pub next_trampoline: PublicKey, | ||
/// The value, in msat, of the payment after this hop's fee is deducted. | ||
pub amt_to_forward: u64, | ||
pub outgoing_cltv_value: u32, | ||
} | ||
|
||
#[cfg(trampoline)] | ||
pub struct InboundTrampolineBlindedForwardPayload { | ||
pub next_trampoline: PublicKey, | ||
pub payment_relay: PaymentRelay, | ||
|
@@ -2144,7 +2138,6 @@ mod fuzzy_internal_msgs { | |
pub next_blinding_override: Option<PublicKey>, | ||
} | ||
|
||
#[cfg(trampoline)] | ||
pub enum InboundTrampolinePayload { | ||
Forward(InboundTrampolineForwardPayload), | ||
BlindedForward(InboundTrampolineBlindedForwardPayload), | ||
|
@@ -3239,15 +3232,13 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh | |
let mut payment_metadata: Option<WithoutLength<Vec<u8>>> = None; | ||
let mut total_msat = None; | ||
let mut keysend_preimage: Option<PaymentPreimage> = None; | ||
#[cfg(trampoline)] | ||
let mut trampoline_onion_packet: Option<TrampolineOnionPacket> = None; | ||
let mut invoice_request: Option<InvoiceRequest> = None; | ||
let mut custom_tlvs = Vec::new(); | ||
|
||
let tlv_len = BigSize::read(r)?; | ||
let mut rd = FixedLengthReader::new(r, tlv_len.0); | ||
|
||
#[cfg(trampoline)] | ||
decode_tlv_stream_with_custom_tlv_decode!(&mut rd, { | ||
(2, amt, (option, encoding: (u64, HighZeroBytesDroppedBigSize))), | ||
(4, cltv_value, (option, encoding: (u32, HighZeroBytesDroppedBigSize))), | ||
|
@@ -3268,41 +3259,20 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh | |
custom_tlvs.push((msg_type, value)); | ||
Ok(true) | ||
}); | ||
#[cfg(not(trampoline))] | ||
decode_tlv_stream_with_custom_tlv_decode!(&mut rd, { | ||
(2, amt, (option, encoding: (u64, HighZeroBytesDroppedBigSize))), | ||
(4, cltv_value, (option, encoding: (u32, HighZeroBytesDroppedBigSize))), | ||
(6, short_id, option), | ||
(8, payment_data, option), | ||
(10, encrypted_tlvs_opt, option), | ||
(12, intro_node_blinding_point, option), | ||
(16, payment_metadata, option), | ||
(18, total_msat, (option, encoding: (u64, HighZeroBytesDroppedBigSize))), | ||
(77_777, invoice_request, option), | ||
// See https://github.com/lightning/blips/blob/master/blip-0003.md | ||
(5482373484, keysend_preimage, option) | ||
}, |msg_type: u64, msg_reader: &mut FixedLengthReader<_>| -> Result<bool, DecodeError> { | ||
if msg_type < 1 << 16 { return Ok(false) } | ||
let mut value = Vec::new(); | ||
msg_reader.read_to_limit(&mut value, u64::MAX)?; | ||
custom_tlvs.push((msg_type, value)); | ||
Ok(true) | ||
}); | ||
|
||
if amt.unwrap_or(0) > MAX_VALUE_MSAT { return Err(DecodeError::InvalidValue) } | ||
if intro_node_blinding_point.is_some() && update_add_blinding_point.is_some() { | ||
return Err(DecodeError::InvalidValue) | ||
} | ||
|
||
#[cfg(trampoline)] | ||
if let Some(trampoline_onion_packet) = trampoline_onion_packet { | ||
if payment_metadata.is_some() || encrypted_tlvs_opt.is_some() || | ||
total_msat.is_some() | ||
{ return Err(DecodeError::InvalidValue) } | ||
return Ok(Self::TrampolineEntrypoint(InboundTrampolineEntrypointPayload { | ||
amt_to_forward: amt.ok_or(DecodeError::InvalidValue)?, | ||
outgoing_cltv_value: cltv_value.ok_or(DecodeError::InvalidValue)?, | ||
multipath_trampoline_data: payment_data.ok_or(DecodeError::InvalidValue)?, | ||
multipath_trampoline_data: payment_data, | ||
trampoline_packet: trampoline_onion_packet, | ||
current_path_key: intro_node_blinding_point, | ||
})) | ||
|
@@ -3391,7 +3361,6 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh | |
} | ||
} | ||
|
||
#[cfg(trampoline)] | ||
impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundTrampolinePayload where NS::Target: NodeSigner { | ||
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. It's kind of a shame to keep this duplicated with 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. ah, that one saw a lot of back and forth, and I agree, but the alternative is clunky, too, and loses the benefit of semantic distinction |
||
fn read<R: Read>(r: &mut R, args: (Option<PublicKey>, NS)) -> Result<Self, DecodeError> { | ||
let (update_add_blinding_point, node_signer) = args; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not following the commit message here in 908c6bf since we don't support trampoline forwarding yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, it ensures that receiving forwarding onions results in a rejection, but not a panic or some undefined behavior. I'll rephrase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok Joost explained that we test that we don't support forwarding basically