-
Notifications
You must be signed in to change notification settings - Fork 401
Eliminate invalid Hop/InboundOnionPayload combinations #3598
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
Eliminate invalid Hop/InboundOnionPayload combinations #3598
Conversation
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.
New commits basically LGTM (I assume the [expound]
tag on the commits is a note to yourself to add more to the commit messages?)
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.
Nice refactor!
lightning/src/ln/channelmanager.rs
Outdated
onion_utils::Hop::Receive(hop_data) => { | ||
let current_height: u32 = self.best_block.read().unwrap().height; | ||
match create_recv_pending_htlc_info(hop_data, | ||
match create_recv_pending_htlc_info(msgs::InboundOnionPayload::Receive(hop_data), | ||
incoming_shared_secret, payment_hash, outgoing_amt_msat, | ||
outgoing_cltv_value, Some(phantom_shared_secret), false, None, | ||
current_height) | ||
{ | ||
Ok(info) => phantom_receives.push(( | ||
prev_short_channel_id, prev_counterparty_node_id, prev_funding_outpoint, | ||
prev_channel_id, prev_user_channel_id, vec![(info, prev_htlc_id)] | ||
)), | ||
Err(InboundHTLCErr { err_code, err_data, msg }) => failed_payment!(msg, err_code, err_data, Some(phantom_shared_secret)) | ||
} | ||
}, | ||
onion_utils::Hop::BlindedReceive(hop_data) => { |
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.
Looks like you can extract hop_data
like
let hop_data = match next_hop {
onion_utils::Hop::Receive(hop_data) => msgs::InboundOnionPayload::Receive(hop_data),
onion_utils::Hop::BlindedReceive(hop_data) => msgs::InboundOnionPayload::BlindedReceive(hop_data),
_ => panic!()
};
and avoid repeating the code here. Maybe other areas where this commit could be DRY'd as well.
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.
there are some other places where the repetition is just one or two lines, so I thought drying those would actually result in more code (which should be called lint imo), but perhaps there's a better way I didn't see
Thanks! As I clean this up (and yes, expound on the comments ;) ) the biggest thing I think I'd like you to take a look at is the modification of your blinded payment unit test, because we're detecting an invalid state earlier and consequently, returning a different error code. |
Blinded path tests changes LGTM! |
In an upcoming commit, we will eliminate various invalid state combinations between `Hop` and `InboundOnionPayload` enums. To do so, rather than nesting one within the other, we will instead have them both referring to the same structs, with variant-dependent supplemental data. This requires pulling each variant's data into its own type.
05bbdb9
to
c1ade72
Compare
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.
Please squash and let's land this!
lightning/src/ln/onion_payment.rs
Outdated
@@ -322,15 +322,27 @@ where | |||
// TODO: If this is potentially a phantom payment we should decode the phantom payment | |||
// onion here and check it. | |||
|
|||
let inbound_onion_payload = match hop { |
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.
super nit: move this up to right under the match so its clear from context why the last arm is unreachable.
Now that each `InboundOnionPayload` variant corresponds to its own struct, we can reference these same types inside `Hop` and thereby avoid nesting that allowed invalid combinations, and instead store supplemental data as each variant calls for.
c1ade72
to
38284a0
Compare
We previously had nested enums of InboundOnionPayload inside of Hop with impossible combinations such as Receive data inside Forward variants and vice versa. Now this is no longer possible, we will be able to better represent decoded information for inner (Trampoline) onions.
Builds on top of #3595.