-
Notifications
You must be signed in to change notification settings - Fork 407
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
Conversation
Concept ACK Would love to see the code move in this direction, too. Thanks for jumping on this! |
Yep, what Jeff said! |
9851d05
to
e98b0c3
Compare
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:
You might find the |
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.
e98b0c3
to
b608426
Compare
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. |
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?
Looks like we were already cloning |
Yea, at least personally I really don't mind a larger PR that removes |
Ah yes indeed, all good. |
Ok cool, will do that then. |
@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. |
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:
MessageFailure
, allowing the removal of theHTLCFailReason::Reason
variant.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.