Skip to content

lnwallet+test: properly generate the sender HTLC script in a contract breach scenario#1025

Merged
Roasbeef merged 5 commits into
lightningnetwork:masterfrom
Roasbeef:incoming-htlc-breach-retribution
Apr 6, 2018
Merged

lnwallet+test: properly generate the sender HTLC script in a contract breach scenario#1025
Roasbeef merged 5 commits into
lightningnetwork:masterfrom
Roasbeef:incoming-htlc-breach-retribution

Conversation

@Roasbeef
Copy link
Copy Markdown
Member

@Roasbeef Roasbeef commented Apr 5, 2018

In this commit, we fix an existing bug w.r.t to the way we handle certain classes of contract breaches. Before PR this commit, within NewBreachRetribution the order of the keys when generating the sender HTLC script was incorrect. As in this case, the remote party is the sender, their key should be first. However, the order was swapped, meaning that at breach time, our transaction would be rejected as it had the incorrect witness script.

We first include an extension to one of the revocation integration tests to trigger a failure. We do this by sending a new set of HTLCs from Carol to Dave (in addition to the ones from Dave to Carol), such that, the final breached commitment has HTLCs in both directions.

We then including a commit with the fix: swap the ordering of the keys. After this PR, the test extension added in the prior commit now passes.

Fixes #970.

Copy link
Copy Markdown
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.

Woohoo! Nice to get our breach tests tightened up a bit further. Changes LGTM, mostly just minor doc fixes

Comment thread lnd_test.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

acan -> can

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.

Comment thread lnd_test.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the following section (~40 lines) can be replaced with net.SendCoins, no?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Heh, yeh, fixed!

Comment thread lnwallet/channel.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

Comment thread lnd_test.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

she persists her -> he persists his

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.

Comment thread lnd_test.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

she should -> he should

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.

Comment thread lnd_test.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wait -> wait

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.

@Roasbeef Roasbeef force-pushed the incoming-htlc-breach-retribution branch from 9df1267 to f8f8786 Compare April 5, 2018 01:04
Roasbeef added 3 commits April 4, 2018 18:41
…oth directions

In this commit, we extend the testRevokedCloseRetributionRemoteHodl so
that the final broadcast revoked transaction has incoming *and* outgoing
HTLC's. As is, this test fails as there's a lingering bug in the way we
generate htlc resolutions. A follow up commit will remedy this issue.
…ing a breach

In this commit, we fix an existing within lnd. Before this commit,
within NewBreachRetribution the order of the keys when generating the
sender HTLC script was incorrect. As in this case, the remote party is
the sender, their key should be first. However, the order was swapped,
meaning that at breach time, our transaction would be rejected as it had
the incorrect witness script.

The fix is simple: swap the ordering of the keys. After this commit, the
test extension added in the prior commit now passes.
@Roasbeef Roasbeef force-pushed the incoming-htlc-breach-retribution branch from f8f8786 to c393475 Compare April 5, 2018 01:41
halseth
halseth previously approved these changes Apr 5, 2018
Copy link
Copy Markdown
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.

Would prefer an added unit test that shows how the htlc dust output was not properly trimmed before, other than that LGTM.

Comment thread lnwallet/channel.go

// If the HTLC is dust, then we'll skip it as it doesn't have
// an output on the commitment transaction.
if htlcIsDust(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should add a unit test that checks that this is properly fixed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Excellent call! Just push out the tests that led to another bug fix.

Roasbeef added 2 commits April 5, 2018 16:19
…o capacity, not length

In this commit, we fix an existing bug in the NewBreachRetribution
method. Rather than creating the slice to the proper length, we instead
now create it to the proper _capacity_. As we'll now properly filter out
any dust HTLCs, before this commit, even if no HTLCs were added, then
the slice would still have a full length, meaning callers could actually
interact with _blank_ HtlcRetribution structs.

The fix is simple: create the slice with the proper capacity, and append
to the end of it.
Copy link
Copy Markdown
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! ✨

@Roasbeef Roasbeef merged commit 065b39b into lightningnetwork:master Apr 6, 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.

TESTNET: unable to broadcast justice tx ... Witness program hash mismatch

3 participants