Skip to content
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

Prefactor for inbound Trampoline parsing/decryption #3595

Merged

Conversation

arik-so
Copy link
Contributor

@arik-so arik-so commented Feb 10, 2025

Parsing inbound Trampoline packets (#3585) requires a somewhat awkward trail of refactors and potential code duplication. This PR is meant to prefactor some of the changes that ought to take up less iteration.

In a subsequent commit, we will be storing `TrampolineOnionPacket`s
within `PendingHTLCRouting`, requiring that they be serialized for
storage. To do so, `RequiredWrapper`'s requirements must be loosened to
only require `LengthReadable` instead of `Readable`.
@arik-so arik-so force-pushed the arik/trampoline/inbound-prefactors branch 2 times, most recently from 2458f09 to c30ea82 Compare February 11, 2025 05:59
/// The node ID of the Trampoline node which we need to route this HTLC to.
node_id: NodeId,
/// Set if this HTLC is being forwarded within a blinded path.
blinded: Option<BlindedForward>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm? We can have a trampoline in a blinded path? I didn't think we could.

@@ -131,7 +132,6 @@ pub use crate::ln::outbound_payment::{Bolt12PaymentError, ProbeSendFailure, Retr
#[cfg(test)]
pub(crate) use crate::ln::outbound_payment::PaymentSendFailure;
use crate::ln::script::ShutdownScript;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

@@ -169,6 +169,23 @@ pub enum PendingHTLCRouting {
/// The absolute CLTV of the inbound HTLC
incoming_cltv_expiry: Option<u32>,
},
/// An HTLC which should be forwarded on to another Trampoline node.
TrampolineForward {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need to be cfg-tagged? After adding this we can panic in process_pending_htlc_forwards with "short_channel_id == 0 should imply any pending_forward entries are of type Receive"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not opposed to cfg-gating, but I don't think we'll hit this panic right now since we fail during process_pending_update_add_htlcs 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps cfg-gating might prove useful for the ability to split up PRs between decrypting the inbound onion and handling forwarding, which are otherwise fairly tightly coupled

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, my concern is we end up shipping 0.2 without adding the missing cfg-gate or fully handling trampoline forwards and someone downgrades to 0.2, hitting the panic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'll cfg-gate the forwards

@@ -4298,7 +4321,13 @@ where
fn can_forward_htlc(
&self, msg: &msgs::UpdateAddHTLC, next_packet_details: &NextPacketDetails
) -> Result<(), (&'static str, u16)> {
match self.do_funded_channel_callback(next_packet_details.outgoing_scid, |chan: &mut FundedChannel<SP>| {
let outgoing_scid = match next_packet_details.outgoing_connector {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ISTM we should be changing can_forward_htlc's API to take an SCID instead of NextPacketDetails if we're changing NextPacketDetails. We still want to run this after we calculate a route when doing trampoline, I imagine.

@arik-so arik-so force-pushed the arik/trampoline/inbound-prefactors branch 3 times, most recently from 6809c8f to 9c493d8 Compare February 12, 2025 08:54
@@ -12477,6 +12504,42 @@ impl_writeable_tlv_based_enum!(PendingHTLCRouting,
(11, invoice_request, option),
},
);
#[cfg(trampoline)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice to avoid this duplication but I can't think of a way to do so

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, we'll survive for a month.

@TheBlueMatt
Copy link
Collaborator

LGTM, I guess you removed the commit with #3595 (comment) ? Feel free to squash and we can land.

Forwarding Trampoline packets requires storing their shared secrets on
top of the outer onion's shared secrets, as well as referencing the
next hop by its node ID as opposed to by an SCID. We modify
PendingHTLCRouting to adequately represent this information.
@arik-so arik-so force-pushed the arik/trampoline/inbound-prefactors branch from 45ac91d to 37ab8b9 Compare February 13, 2025 01:57
@arik-so
Copy link
Contributor Author

arik-so commented Feb 13, 2025

ok, CI passes post-squash. And yes, as addressed offline, the HopConnector enum needs a slightly different layout so I'm moving that commit out.

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

ci/ci-tests.sh Outdated
@@ -131,6 +131,8 @@ RUSTFLAGS="--cfg=taproot" cargo test --verbose --color always -p lightning
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
RUSTFLAGS="--cfg=splicing" cargo test --verbose --color always -p lightning
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
RUSTFLAGS="--cfg=taproot" cargo test --verbose --color always -p lightning
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/taproot/trampoline

@arik-so arik-so force-pushed the arik/trampoline/inbound-prefactors branch from 37ab8b9 to 2c685d2 Compare February 13, 2025 16:53
@TheBlueMatt TheBlueMatt merged commit b05402a into lightningdevkit:main Feb 13, 2025
24 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants