Skip to content

Simplify + document the ChannelManager Err flow, fix close-outside-lock race, finish ChannelError conversion #258

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

Merged
merged 8 commits into from
Nov 26, 2018

Conversation

TheBlueMatt
Copy link
Collaborator

This addresses the races discovered during work on #254, as well as finishes the conversion to using ChannelError in place of HandleError in Channel Errs. It makes ChannelManager a bit more complicated, but we end up in a more consistent state than we were in previously, so hopefully its still within reason.

Currently channel_reserve_test sends a garbage update_add_htlc
message and then relies on it being silently ignored to continue
using the channel. This shouldn't be the case, so take the easy
way out and split the test in two, at first not delivering the
bogus update_add_htlc and then delivering it, but not running the
rest of the test.
This converts block_connected failures to returning the
ErrorMessage that needs to be sent directly, since it always
results in channel closure and never results in needing to call
force_shutdown. It also converts update_add_htlc and closing_signed
handlers to ChannelError as the rest of the message handlers.
This moves a clone() inside Channel from ChannelManager making
references simpler for the coming refactors.
If we never accessed channels for a peer outside of a message
handler for that peer then this wouldn't be a problem since message
handlers are required to be serialized per-peer. However, that
isn't the world we live in - we may want to forward payments or we
may get a send_payment call.
Technically funding_transaction_generated was fine using it, but
calling force_shutdown on an empty Channel inside the channel_state
lock isn't a big deal and almost any other use of it would be
unsafe.
This removes all the channel-closure stuff from handle_error!() and
MsgHandleErrInternal, making all the Err handling consistent by
closing the channel before releasing the channel_state lock and
then calling handle_error!() outside of the lock.
Copy link

@ariard ariard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay seems good as it's mostly refactors, maybe more documentation on what have to do upstream with ShutdownResult (HTLCSource)

@@ -464,6 +464,24 @@ macro_rules! handle_error {
}
}

macro_rules! break_chan_entry {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm exhaused but isn't break_chan_entry exactly the same as try_chan_entry ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break vs return in the Err conditions - one is used in let err = loop { };, the other when we just want to return.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay good, shouldn't review after a given hour!

HandleError{err, .. } => assert_eq!(err, "Remote HTLC add would put them over their reserve value"),
}
// If we send a garbage message, the channel should get closed, making the rest of this test case fail.
/*assert_eq!(nodes[1].node.list_channels().len(), 1);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, comments of the test isn't voluntary there ?
(uncommented on your branch)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the test test for the correct behavior but it isnt implemented until the next commit, so the next commit just uncomments it. I can add a comment there for clarity if you want, but its just git history consistency....

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, don't care go ahead merge it

@TheBlueMatt TheBlueMatt merged commit 5e9e199 into lightningdevkit:master Nov 26, 2018
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.

2 participants