Uh oh!
There was an error while loading. Please reload this page.
Improve type safety for message failures - #600
Conversation
jkczyz
commented
Apr 20, 2020
Concept ACK Would love to see the code move in this direction, too. Thanks for jumping on this! |
TheBlueMatt
commented
Apr 21, 2020
Yep, what Jeff said! |
9851d05 to
e98b0c3CompareD4nte
commented
Apr 21, 2020
Need to sort build on old Rust toolchain 😟 |
jkczyz
commented
Apr 21, 2020
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
b608426CompareD4nte
commented
Apr 23, 2020
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
commented
Apr 23, 2020
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 |
TheBlueMatt
commented
Apr 23, 2020
Yea, at least personally I really don't mind a larger PR that removes |
D4nte
commented
Apr 23, 2020
Ah yes indeed, all good. |
D4nte
commented
Apr 23, 2020
Ok cool, will do that then. |
TheBlueMatt
commented
Sep 27, 2020
@D4nte any plans on updating this? |
D4nte
commented
Oct 6, 2020
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
MessageFailureenum 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::Reasonvariant.MessageFailurevariables.One downside of this solution is that I had to clone
ChannelUpdate. Let me know if you'd prefer I optimise this before merging.