-
Notifications
You must be signed in to change notification settings - Fork 385
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
Workaround lnd sending funding_locked before channel_reestablish #966
Workaround lnd sending funding_locked before channel_reestablish #966
Conversation
Codecov Report
@@ Coverage Diff @@
## main #966 +/- ##
==========================================
+ Coverage 90.66% 90.85% +0.19%
==========================================
Files 60 60
Lines 30407 31939 +1532
==========================================
+ Hits 27568 29019 +1451
- Misses 2839 2920 +81
Continue to review full report at Codecov.
|
51d7a5b
to
35ec74f
Compare
Added a test for the behavior. |
do_test_drop_messages_peer_disconnect(4); | ||
do_test_drop_messages_peer_disconnect(5); | ||
do_test_drop_messages_peer_disconnect(6); | ||
do_test_drop_messages_peer_disconnect(3, false); |
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.
Any reason why this was moved 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.
To keep the same number of test runs in each test.
/// message until we receive a channel_reestablish. | ||
/// | ||
/// See-also <https://github.com/lightningnetwork/lnd/issues/4006> | ||
pub workaround_lnd_bug_4006: Option<msgs::FundingLocked>, |
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.
Does this need to be persisted in case we crash before getting channel_reestablish
? Or will LND resend funding_locked
?
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 assume they will resend it, ultimately there's no such thing as knowing for sure that a message was delivered, so they need to support re-sending for lnd <-> lnd to work, which hopefully it does.
/// message until we receive a channel_reestablish. | ||
/// | ||
/// See-also <https://github.com/lightningnetwork/lnd/issues/4006> | ||
pub workaround_lnd_bug_4006: Option<msgs::FundingLocked>, |
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.
Why pub
?
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 ChannelManager
accesses it directly on L3389 where it takes from the option and sends it back in as a new message.
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.
Ah, right Channel
is not pub
so no need to make it pub(crate)
.
lightning/src/ln/channel.rs
Outdated
self.workaround_lnd_bug_4006 = Some(msg.clone()); | ||
return Err(ChannelError::Ignore("Peer sent funding_locked when we needed a channel_reestablish. The peer is likely lnd, see their bug #4006.".to_owned())); |
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.
Won't this mean any implementation of ChannelMessageHandler
needs to implement this workaround. Not sure if there is a better way, though. Maybe cache it at the peer handling layer using a wrapper around ChannelMessageHandler
? Might not be feasible if you need the channel state. :/
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.
Yes, if you implement a whole new channel implementation then you would, but I'm not sure how likely that is. You wouldn't need to if you were implementing ChannelMessageHandler
as a simple wrapper around our ChannelManager
(which I do expect people to do).
// in `reconnect_nodes` but we currently don't fail based on that. | ||
// | ||
// See-also <https://github.com/lightningnetwork/lnd/issues/4006> | ||
nodes[1].node.handle_funding_locked(&nodes[0].node.get_our_node_id(), &as_funding_locked.as_ref().unwrap().0); |
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.
noob question: Is it worth getting the channel_id and looking up the Channel and assert workaround_lnd_bug_4006
is Some? or is it because we don't fail this check anymore, it implicitly passes?
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.
In general I think we've tried to avoid (though there are a number of places where we do) writing functional tests where we read non-public/internal datastructures, instead opting for completely black-box testing (at least in functional tests). Ultimately, it doesn't matter a whole lot how ChannelManager
and Channel
handle this case, as long as they successfully do.
lnd has a long-standing bug where, upon reconnection, if the channel is not yet confirmed they will not send a channel_reestablish until the channel locks in. Then, they will send a funding_locked *before* sending the channel_reestablish (which is clearly a violation of the BOLT specs). We copy c-lightning's workaround here and simply store the funding_locked message until we receive a channel_reestablish. See-also lightningnetwork/lnd#4006 Fixes lightningdevkit#963
02a0ba6
to
8df1412
Compare
Squashed the fixup commits with no diff:
|
// | ||
// See-also <https://github.com/lightningnetwork/lnd/issues/4006> | ||
nodes[1].node.handle_funding_locked(&nodes[0].node.get_our_node_id(), &as_funding_locked.as_ref().unwrap().0); | ||
} | ||
// Even if the funding_locked messages get exchanged, as long as nothing further was | ||
// received on either side, both sides will need to resend them. | ||
reconnect_nodes(&nodes[0], &nodes[1], (true, true), (0, 1), (0, 0), (0, 0), (0, 0), (false, false)); |
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.
Just a Q: since send_funding_locked
is (true, true)
here, wouldn't that result in a second nodes[0] funding_locked being sent? Is that similar enough to the lnd scenario we're trying to test? 🤔
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.
Indeed, it will, I think its close enough, but I'm happy to rework if you disagree, its just a good chunk more special-case code 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 it's OK. The test does fail with the previous code
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.
utACK 8df1412
/// lnd has a long-standing bug where, upon reconnection, if the channel is not yet confirmed | ||
/// they will not send a channel_reestablish until the channel locks in. Then, they will send a | ||
/// funding_locked *before* sending the channel_reestablish (which is clearly a violation of | ||
/// the BOLT specs). We copy c-lightning's workaround here and simply store the funding_locked |
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.
A node:
if next_commitment_number is 1 in both the channel_reestablish it sent and received:
MUST retransmit funding_locked.
otherwise:
MUST NOT retransmit funding_locked.
I agree, it's pretty clear, though another fix for them would be to rebroadcast a redundant funding_locked
after channel_reestablish
.
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.
Hmm, no, if they don't know what is in channel_reestablish
they "MUST NOT retransmit funding_locked." I don't think they could do that either.
// | ||
// See-also <https://github.com/lightningnetwork/lnd/issues/4006> | ||
nodes[1].node.handle_funding_locked(&nodes[0].node.get_our_node_id(), &as_funding_locked.as_ref().unwrap().0); | ||
} | ||
// Even if the funding_locked messages get exchanged, as long as nothing further was | ||
// received on either side, both sides will need to resend them. | ||
reconnect_nodes(&nodes[0], &nodes[1], (true, true), (0, 1), (0, 0), (0, 0), (0, 0), (false, false)); |
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 it's OK. The test does fail with the previous code
lnd has a long-standing bug where, upon reconnection, if the
channel is not yet confirmed they will not send a
channel_reestablish until the channel locks in. Then, they will
send a funding_locked before sending the channel_reestablish
(which is clearly a violation of the BOLT specs). We copy
c-lightning's workaround here and simply store the funding_locked
message until we receive a channel_reestablish.
See-also lightningnetwork/lnd#4006
Fixes #963
Should work but needs tests.