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

[lnwallet] Only Forward Committed Settles and Fails #1293

Merged
merged 2 commits into from
May 29, 2018

Conversation

cfromknecht
Copy link
Contributor

@cfromknecht cfromknecht commented May 28, 2018

This PR fixes an issue that would cause us to forward a settle or fail prematurely, i.e. we would forward a settle or fail before it was fully committed by both commitment transactions.

Previously, we had such a check for Add htlcs, and ensure that neither the addCommitHeightRemote and addCommitHeightLocal were both non-zero. Here, we add the same constraints to removeCommitHeightRemote and removeCommitHeightLocal.

We also change the logic around when an Fail or Settle should be forwarded by requiring equality between the remote height and removeCommitHeightRemote. Currently, we use >= to determine when we should forward an HTLC in order to mimic the logic for Adds.

This change is more minor, and shouldn't result in any observed difference in behavior, but should provide an additional protection against forwarding the same settle or fail twice. The difference lies in that Add updates can persist in the log across multiple commitments after being added, while Settles and Fails are always removed immediately after being locked in.

Fixes #1124.
Fixes #1053.
Fixes #977.

@cfromknecht cfromknecht changed the title Freshly locked settle fail [lnwallet] Only Forward Committed Settles and Fails May 28, 2018
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Nice! This is definitely a bug that has been lingering for some time. I've modified this patch locally to remove the initial "fix" commit and confirmed that the added test does indeed fail at the proper location.

Noted one minor aspect: in that we can make our assertion on forwarded fails more accurate to ensure the correct HTLC failure is forwarded, and not just any failure.

t.Fatalf("alice shouldn't forward any HTLC's, instead wants to "+
"forward %v htlcs", len(fwdPkg.Adds))
}
if len(fwdPkg.SettleFails) != 1 {
Copy link
Member

Choose a reason for hiding this comment

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

We can strengthen this check a bit by ensuring the _proper failed HTLC is what's being forwarded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@cfromknecht cfromknecht force-pushed the freshly-locked-settle-fail branch from 4033b59 to c285c32 Compare May 28, 2018 23:13
Copy link
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

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

utACK

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 👾

@Roasbeef Roasbeef merged commit 622bd5c into master May 29, 2018
@Roasbeef Roasbeef added this to the 0.4.2-beta milestone May 29, 2018
@cfromknecht cfromknecht deleted the freshly-locked-settle-fail branch August 8, 2018 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants