-
Notifications
You must be signed in to change notification settings - Fork 902
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
openingd/: Fail fundchannel_start
if we already are, or will become, the fundee.
#4116
Conversation
50a6f0c
to
c4c8616
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.
Nice debugging work on this! You don't need a new wire call to fix this. We already do a similar/exact call a few lines above, opening_got_offer
, which is used for the openchannel
hook. We should toggle this flag there.
lightningd/opening_control.c
Outdated
@@ -415,6 +420,17 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp, | |||
tal_free(fc->uc); | |||
} | |||
|
|||
static void | |||
opening_funder_failed_cancel_commands(struct uncommitted_channel *uc, |
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.
Having a separate declaration from implementation is only kosher for recursive functions. It unnecessarily confuses ctag jumps in vim and clutters the code. Either move opening_fundee_started
below the function you're using or move the other up here.
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 think opening_fundee_started
is just fine where it is, and the other one is also just fine where it is. A small declaration to me is just small and easy to skip over with proper folding. shrug.
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.
Also, modern vim understands etags just fine and we have a make TAGS
that uses etags, declarations do not confuse etags the way they confuse ctags. ctags is really just a lousy beta-level software, use etags instead. Twisting your codebase because of lousy tools is worse than just not having that tool.
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.
@niftynei is right here; C is always written bottom to top. Sometimes judicious use of pre-declaration can reduce diff size, but best practice is usually a separate preparatory commit to reorder.
The reason why I did not reuse Lines 965 to 972 in 60be62a
We would need to add more code in Looking over at lightning/lightningd/opening_control.c Lines 729 to 736 in 60be62a
Then later, if a plugin tells us to fail it, we should add a check in this function: lightning/lightningd/opening_control.c Lines 625 to 644 in 60be62a
Unfortunately, it seems we do not have access to the |
Removed the new wire. Cancel a conflicting |
So, not to get too "putting on my arm-chair psychologist hat" here, but as you did bring up the topic of "mental gymnastics" I think we should discuss the laundry list of rationales you've given so far as to why it's ok to disregard the request to do the reorg needed to remove the Rationales offered:
These are all stated in the pull request comments. However, I find it peculiar that none of these are mentioned in the actual code comment you added (and vice versa, that the reason given there isn't mentioned elsewhere), which is
Which can be summarized as
I'm not going to address the rationales given here, I merely wish to point out that you've triggered my "methinksth thou dost protesth too much" heuristic of argumentation. Usually this is an indication that there's actually another, unspoken and perhaps unconscious, rationale for as to why you'd like to keep the code the way it is, rather than following the fairly small request, I think at this point, to change it. What do you think? |
Well, I could put a long treatise in the comments like so, if that is what you would prefer: /* Often, in programming, we find we need to split functions into smaller pieces,
* simply as a consequence of refactoring code for code reuse, or in a server
* context, simply as a consequence of having to do callback-style coding
* in order to block for a task but not block the entire server.
* Now, ideally you want those functions to be in a reasonable order, that is,
* in the same order you would have read the lines if they were a single
* large function instead of broken up into tiny pieces.
*
* However, C requires functions to be predeclared before first use.
* So if you have to split up a function into two pieces, for refactoring, or
* to make a callback for a blocking operation, and the first piece has to
* refer to the second piece (to call it or to provide as callback function)
*
* - Either you predeclare the second piece and add a few lines.
* - You twist your code so that the second piece is written before the first.
*
* Now, there are other reasons to predeclare, or not predeclare.
*
* - If you have to do mutual recursion, no choice but to predeclare.
* - If you want to isolate a common operation off into its own function,
* you should not predeclare, or should consider moving it off into
* its own source file.
* (And if it is off into its own source file, it is effectively predeclared
* in its own header).
*
* On the other hand, maintaining the proper order for executing
* code should generally be a reason to predeclare code.
* Predeclaration is just a few lines.
*
* But really, the issue is that C requires predeclaration *at all*.
*/ Does that satisfy your psychologist? Or can we get on with fixing this bug? |
Removed the predeclaration as a separate commit so that the code-move can be reviewed separately from the code-modification. |
bump @ZmnSCPxj |
…, the fundee. Fixes: ElementsProject#4108 Changelog-Fixed: Network: Fixed a race condition when us and a peer attempt to make channels to each other at nearly the same time.
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.
Fixes: #4108
Requesting review from nifty and rusty, since my grasp of the openingd is not good.
As well, there may be a similar issue in dual-funding, so please consider as well for that point-of-view, I am much more ignorant about the dual-funding flow than openingd flow.