Skip to content
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

Fix TestNewBreachRetributionSkipsDustHtlcs incorrect state transtion #3998

Merged
merged 2 commits into from
Feb 17, 2020

Conversation

halseth
Copy link
Contributor

@halseth halseth commented Feb 12, 2020

The unit test TestNewBreachRetributionSkipsDustHtlcs triggered a state
transition from Bob, even though it was Alice that had added the HTLCs.
This is wrong since it will lead to Bob still owing Alice a commitment,
which is not accounted for in the unit tests.

We add a sanity check that the add heights has been set for all entries
found in the logs, and return an error otherwise. This won't happen
during normal operation, but it does reveal the mistake in the unit
test, which is fixed by making Alice trigger the transition.

In addition we resolve a long standing TODO by removing a (purposeful)
panic in the channel state machine. Old version of lnd had a bug that
could lead to the parent entries being lost during channel restore. A
panic was added to get to the bottom of if.

This is now fixed, so new nodes shouldn't encounter it. However, to be
on the safe side, instead of panicking we return an error back to
gracefully exit the channel state machine.

The unit test TestNewBreachRetributionSkipsDustHtlcs triggered a state
transition from Bob, even though it was Alice that had added the HTLCs.
This is wrong since it will lead to Bob still owing Alice a commitment,
which is not accounted for in the unit tests.

We add a sanity check that the add heights has been set for all entries
found in the logs, and return an error otherwise. This won't happen
during normal operation, but it does reveal the mistake in the unit
test, which is fixed by making Alice trigger the transition.

In addition we resolve a long standing TODO by removing a (purposeful)
panic in the channel state machine. Old version of lnd had a bug that
could lead to the parent entries being lost during channel restore. A
panic was added to get to the bottom of if.

This is now fixed, so new nodes shouldn't encounter it. However, to be
on the safe side, instead of panicking we return an error back to
gracefully exit the channel state machine.
@halseth halseth requested review from cfromknecht and joostjager and removed request for Roasbeef February 12, 2020 10:21
Copy link
Contributor

@joostjager joostjager left a comment

Choose a reason for hiding this comment

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

How does this play with settles pipelining? When we find out that the update log isn't sane, we already handed off the settle to the switch.

)

// The parent add height should never be zero at this point. If
// that's the case we probably forgot to send a new commitment.
Copy link
Contributor

Choose a reason for hiding this comment

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

It should never be zero, because commit height 0 is the opening commitment tx that doesn't contain any htlcs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. If it is zero it means it wasn't added to a commitment (yet), so a CommitSig that covers it must be sent. This is what was missing in the test case, and hence we wasn't actually testing settling the HTLCs, as they weren't added at that point.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean just using the magic value of zero to signal that it wasn't added, while commit height zero is also a valid commitment. But I guess it is ok

lnwallet/channel.go Show resolved Hide resolved
lnwallet/channel.go Show resolved Hide resolved
@halseth
Copy link
Contributor Author

halseth commented Feb 13, 2020

How does this play with settles pipelining? When we find out that the update log isn't sane, we already handed off the settle to the switch.

It shouldn't happen, since this is not really a situation that happens in practice. And if that happens I guess it is better to pipeline it to the switch so you can claim your money there then not to :)

Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

LGTM 🤓

@joostjager
Copy link
Contributor

It shouldn't happen, since this is not really a situation that happens in practice. And if that happens I guess it is better to pipeline it to the switch so you can claim your money there then not to :)

And there are no other side effects of the pipelining that we need to be aware of? Closing circuits, updating fwd log? I don't have a particular concern, but just checking

@cfromknecht
Copy link
Contributor

@joostjager pipelining of settles only after processing the settle successfully so we should be fine in terms of circuits, fwding log, etc

@halseth halseth merged commit 13ca3f4 into lightningnetwork:master Feb 17, 2020
@halseth halseth added this to the 0.9.1 milestone Feb 19, 2020
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.

3 participants