Skip to content

Improve type safety for message failures #600

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

Closed

Conversation

D4nte
Copy link
Contributor

@D4nte D4nte commented Apr 20, 2020

Follow-up of #596

Edit: Ready for review.

This a step towards a safer handling of failure code and associated data by using a new MessageFailure enum instead of serialising the code and data on call site.

I see several ways to follow-up with this change:

  1. Deserialise all possible message failures to MessageFailure, allowing the removal of the HTLCFailReason::Reason variant.
  2. Continue to replace call site assignment of code value with instantiation of MessageFailure variables.

One downside of this solution is that I had to clone ChannelUpdate. Let me know if you'd prefer I optimise this before merging.

@jkczyz
Copy link
Contributor

jkczyz commented Apr 20, 2020

Concept ACK

Would love to see the code move in this direction, too. Thanks for jumping on this!

@TheBlueMatt
Copy link
Collaborator

Yep, what Jeff said!

@D4nte D4nte force-pushed the type-safety-message-failures branch from 9851d05 to e98b0c3 Compare April 21, 2020 09:58
@D4nte D4nte changed the title [draft]Type message failures Improve type safety for message failures Apr 21, 2020
@D4nte D4nte marked this pull request as ready for review April 21, 2020 10:04
@D4nte
Copy link
Contributor Author

D4nte commented Apr 21, 2020

Need to sort build on old Rust toolchain 😟

@jkczyz
Copy link
Contributor

jkczyz commented Apr 21, 2020

Need to sort build on old Rust toolchain 😟

Looks like you're running into issues on 1.22.0 with matching enum variants. The syntax is a bit more verbose in this version. You can reproduce the errors using:

cargo +1.22.0 check -p lightning
cargo +1.22.0 test -p lightning

You might find the wire module useful as an example of the syntax if the compiler messages aren't helpful.

D4nte added 6 commits April 22, 2020 09:35
All message failure are constructed on the fly in
the channel manager. Instead, we add the `MessageFailure`
enum. The enum will list the possible message failures and type
the data to be included.
The code would also be defined once in an impl block and this
enum can directly provide the data byte array and code using
`Writeable` trait.

This commit adds the skeleton.
These values are used at several places of the code.
Constants usage is preferred to avoid typos and make
code more readable.
@D4nte D4nte force-pushed the type-safety-message-failures branch from e98b0c3 to b608426 Compare April 21, 2020 23:38
@D4nte
Copy link
Contributor Author

D4nte commented Apr 23, 2020

Need to sort build on old Rust toolchain 😟

Looks like you're running into issues on 1.22.0 with matching enum variants. The syntax is a bit more verbose in this version. You can reproduce the errors using:

cargo +1.22.0 check -p lightning
cargo +1.22.0 test -p lightning

You might find the wire module useful as an example of the syntax if the compiler messages aren't helpful.

Yep, thanks, no worries. I was working in Rust already when they did those improvements on the compiler where it is able to infer referencing. It's now ready for review/merge.

@jkczyz
Copy link
Contributor

jkczyz commented Apr 23, 2020

Follow-up of #596

Edit: Ready for review.

This a step towards a safer handling of failure code and associated data by using a new MessageFailure enum instead of serialising the code and data on call site.

I see several ways to follow-up with this change:

  1. Deserialise all possible message failures to MessageFailure, allowing the removal of the HTLCFailReason::Reason variant.
  2. Continue to replace call site assignment of code value with instantiation of MessageFailure variables.

I have a bit of a preference to make all these changes in one PR rather than leaving the code in an intermediary state. Or at very least for (2). @TheBlueMatt What do you think?

One downside of this solution is that I had to clone ChannelUpdate. Let me know if you'd prefer I optimise this before merging.

Looks like we were already cloning ChannelUpdate inside peer_disconnected. Or were you referring to somewhere else?

@jkczyz jkczyz self-requested a review April 23, 2020 14:48
@TheBlueMatt
Copy link
Collaborator

Yea, at least personally I really don't mind a larger PR that removes HTLCFailReason::Reason and replaces it with types, obviously with smaller intermediary commits, though.

@D4nte
Copy link
Contributor Author

D4nte commented Apr 23, 2020

Looks like we were already cloning ChannelUpdate inside peer_disconnected. Or were you referring to somewhere else?

Ah yes indeed, all good.

@D4nte
Copy link
Contributor Author

D4nte commented Apr 23, 2020

Yea, at least personally I really don't mind a larger PR that removes HTLCFailReason::Reason and replaces it with types, obviously with smaller intermediary commits, though.

Ok cool, will do that then.

@TheBlueMatt
Copy link
Collaborator

@D4nte any plans on updating this?

@D4nte
Copy link
Contributor Author

D4nte commented Oct 6, 2020

@D4nte any plans on updating this?

Hi @TheBlueMatt, I don't see an opportunity to follow-up within the next two months. I'll close for now.

@D4nte D4nte closed this Oct 6, 2020
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