-
Notifications
You must be signed in to change notification settings - Fork 423
Remove convert_channel_err! macro #4275
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
Remove convert_channel_err! macro #4275
Conversation
|
👋 Thanks for assigning @tnull as a reviewer! |
b34da00 to
73f182f
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4275 +/- ##
========================================
Coverage 89.37% 89.38%
========================================
Files 180 180
Lines 139395 139623 +228
Branches 139395 139623 +228
========================================
+ Hits 124591 124797 +206
- Misses 12216 12241 +25
+ Partials 2588 2585 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
tnull
left a comment
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.
Changes look good to me, but might be good to add some more docs now that we lost the macro's match arms which made sure we did the right thing(tm) before..
| /// [`ChannelManager::finish_close_channel`]. | ||
| /// | ||
| /// Returns a mapped error. | ||
| fn convert_channel_err_coop( |
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.
The replicated docs don't really explain when you're supposed to use which variant now, and the names aren't super clear either (convert_channel_err_coop/convert_channel_err_funded/convert_channel_err). Can we add some more explanations to make up for the lost functionality of the macro match arms?
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.
I've added the channel states to the docs to make it more clear which of the variants should be used. Looked into further documentation, but I think that would lead to more code restructuring to make the docs make sense.
The goal of this PR is just to get rid of the macros without letting the docs become worse.
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.
This method is particularly easy to mis-use, and documentation doesn't make it clear that the code is wrong at the callsite. coop is maybe enough, but it would be very nice to be much more explicit here (its not like the method name is overly long to begin with) so that its clear from the callsite whether we're doing it wrong or not.
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.
It also isn't converting an error. I've now named it get_coop_close_err. Let me know if you think this is better.
|
👋 The first review has been submitted! Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer. |
73f182f to
d436cbf
Compare
tnull
left a comment
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.
LGTM
Relatively straightforward refactor, so landing this.
TheBlueMatt
left a comment
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 fix the docs and maybe clean it up a bit in a followup.
| }) | ||
| } | ||
|
|
||
| fn convert_funded_channel_err_internal( |
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 place methods with other methods doing roughly similar things. There's already a bunch of error-handling down a few hundred lines (finish_close_channel, which even explicitly references some of the new methods). Breaking things up makes things harder to find.
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.
Moved
| /// [`ChannelManager::finish_close_channel`]. | ||
| /// | ||
| /// Returns a mapped error. | ||
| fn convert_channel_err_coop( |
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.
This method is particularly easy to mis-use, and documentation doesn't make it clear that the code is wrong at the callsite. coop is maybe enough, but it would be very nice to be much more explicit here (its not like the method name is overly long to begin with) so that its clear from the callsite whether we're doing it wrong or not.
| } | ||
|
|
||
| /// When a cooperatively closed channel is removed, two things need to happen: | ||
| /// (a) This must be called in the same `per_peer_state` lock as the channel-closing action, |
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.
These docs are now all wrong - its not just "this" that must be called but one of a few methods.
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.
My impression is that for a coop closed channel, this is the one method to call?
| &mut peer_state.closed_channel_monitor_update_ids, | ||
| &mut peer_state.in_flight_monitor_updates, |
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.
I really do not find this more readable than the macro was. Its not really a huge deal, but the macro hid some of the crap that had to be passed in because of lifetime restrictions without doing much else.
I do not buy that we should be removing macros for the sake of removing macros. There's some compilation-time wins to be had by reducing codegen steps through macro removal, and they're often hard to read in our codebase, but that doesn't mean that removing them is inherently easier to read just because they're gone, especially if they leave behind more code than we had.
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.
From previous discussions during dev sync, I got that the general consensus is that we want to get rid of macros unless absolutely necessary.
For what it is worth, I personally find macros a source of micro friction. Code navigation breaks, references lookup breaks, stack traces aren't complete, debugging gets more difficult, identifying the applicable match arm is a manual thought step, the syntax is different and rustfmt acts weird sometimes.
I agree to the lifetime argument favoring macros, but in this case I thought it was worth it.
|
|
||
| /// When a channel is removed, two things need to happen: | ||
| /// (a) [`convert_channel_err`] must be called in the same `per_peer_state` lock as the | ||
| /// (a) [`ChannelManager::convert_channel_err`] must be called in the same `per_peer_state` lock as the |
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.
No, or one of the other few methods.
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.
Updated phrasing to the more generic
The close error must be converted to [
MsgHandleErrInternal]
| "Can't find a peer matching the passed counterparty node_id {}", | ||
| peer_node_id |
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.
As we go it would be nice to inline the format arguments where possible.
| "Can't find a peer matching the passed counterparty node_id {}", | |
| peer_node_id | |
| "Can't find a peer matching the passed counterparty node_id {peer_node_id}" |
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.
Fixed together with another one further down.
|
Follow ups: #4281 |
Fewer macros, less pain