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

Move shared secret calculation into decode_next_payment_hop #3607

Merged

Conversation

arik-so
Copy link
Contributor

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

For Trampoline, we'll need to keep track of both the outer and inner onion's shared secrets. To this end, we're moving the secret calculation inside the hop decoding method such that, when applicable, it can return both.

This might end up being just one commit, but the primary consideration in this PR is whether to make the relay error return the shared secret, or do the HTLCFailReason within. I opted for the former due to the awkwardness the latter seemed to entail, but open to undoing it, or passing the channel/HTLC details into the decode method to be able to return an HTLCFailureMsg.

@TheBlueMatt
Copy link
Collaborator

Makes sense to me, care to clean up the commits?

@arik-so arik-so force-pushed the arik/trampoline/inbound-prefactors-03 branch from 8c9f53b to 49f9ba9 Compare February 18, 2025 19:08
Copy link

codecov bot commented Feb 18, 2025

Codecov Report

Attention: Patch coverage is 80.90909% with 21 lines in your changes missing coverage. Please review.

Project coverage is 89.48%. Comparing base (38284a0) to head (49f9ba9).
Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/onion_utils.rs 73.43% 17 Missing ⚠️
lightning/src/ln/onion_payment.rs 90.32% 3 Missing ⚠️
lightning/src/ln/channelmanager.rs 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3607      +/-   ##
==========================================
+ Coverage   88.69%   89.48%   +0.79%     
==========================================
  Files         149      149              
  Lines      117505   123481    +5976     
  Branches   117505   123481    +5976     
==========================================
+ Hits       104219   110496    +6277     
+ Misses      10794    10423     -371     
- Partials     2492     2562      +70     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

TheBlueMatt
TheBlueMatt previously approved these changes Feb 19, 2025
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

LGTM, one small nit on commits but otherwise happy

},
onion_utils::Hop::BlindedReceive(next_hop_data) => {
onion_utils::Hop::Receive { .. } | onion_utils::Hop::BlindedReceive { .. } => {
let inbound_onion_payload = match decoded_hop {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This kinda thing could probably go in a separate commit since its just a cleanup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, done

@arik-so arik-so force-pushed the arik/trampoline/inbound-prefactors-03 branch from 49f9ba9 to a0ce434 Compare February 19, 2025 17:20
@arik-so arik-so force-pushed the arik/trampoline/inbound-prefactors-03 branch from a0ce434 to 912a5dd Compare February 19, 2025 17:29
Essentially a follow-up to 38284a0, deduplicating some additional code.
@arik-so arik-so force-pushed the arik/trampoline/inbound-prefactors-03 branch from 912a5dd to 78ddff5 Compare February 19, 2025 17:39
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.

Nothing blocking!

Some(next_packet_pubkey),
)?
},
onion_utils::Hop::Receive(received_data) => {
onion_utils::Hop::Receive{hop_data, shared_secret} => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
onion_utils::Hop::Receive{hop_data, shared_secret} => {
onion_utils::Hop::Receive { hop_data, shared_secret } => {

None, allow_skimmed_fees, msg.skimmed_fee_msat, cur_height,
)?
},
onion_utils::Hop::BlindedReceive(received_data) => {
onion_utils::Hop::BlindedReceive{hop_data, shared_secret} => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
onion_utils::Hop::BlindedReceive{hop_data, shared_secret} => {
onion_utils::Hop::BlindedReceive { hop_data, shared_secret } => {

let shared_secret = node_signer
.ecdh(recipient, hop_pubkey, blinded_node_id_tweak.as_ref())
.unwrap()
.secret_bytes();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid calling secret_bytes here and only call it below for decode_next_hop instead? Avoids doing SharedSecret::from_bytes in a bunch of places

Comment on lines 1474 to 1477
Hop::Forward { shared_secret, .. } => shared_secret.clone(),
Hop::BlindedForward { shared_secret, .. } => shared_secret.clone(),
Hop::Receive { shared_secret, .. } => shared_secret.clone(),
Hop::BlindedReceive { shared_secret, .. } => shared_secret.clone(),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: doesn't matter much but could return a reference (or dereference) instead of cloning

@arik-so
Copy link
Contributor Author

arik-so commented Feb 19, 2025

yup, will squash as soon as CI passes on my fork

@arik-so arik-so force-pushed the arik/trampoline/inbound-prefactors-03 branch from 2cce8d7 to 5afe97f Compare February 19, 2025 21:20
For Trampoline, we'll need to keep track of both the outer and inner
onion's shared secrets. To this end, we're moving the secret
calculation inside `decode_next_payment_hop` such that, when applicable,
it can return both.
@arik-so arik-so force-pushed the arik/trampoline/inbound-prefactors-03 branch from 5afe97f to 5291445 Compare February 19, 2025 21:22
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Thanks

@TheBlueMatt TheBlueMatt merged commit ef8868b into lightningdevkit:main Feb 20, 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