lnwallet+test: properly generate the sender HTLC script in a contract breach scenario#1025
Conversation
cfromknecht
left a comment
There was a problem hiding this comment.
Woohoo! Nice to get our breach tests tightened up a bit further. Changes LGTM, mostly just minor doc fixes
There was a problem hiding this comment.
I think the following section (~40 lines) can be replaced with net.SendCoins, no?
There was a problem hiding this comment.
she persists her -> he persists his
There was a problem hiding this comment.
she should -> he should
9df1267 to
f8f8786
Compare
…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.
f8f8786 to
c393475
Compare
halseth
left a comment
There was a problem hiding this comment.
Would prefer an added unit test that shows how the htlc dust output was not properly trimmed before, other than that LGTM.
|
|
||
| // If the HTLC is dust, then we'll skip it as it doesn't have | ||
| // an output on the commitment transaction. | ||
| if htlcIsDust( |
There was a problem hiding this comment.
Should add a unit test that checks that this is properly fixed.
There was a problem hiding this comment.
Excellent call! Just push out the tests that led to another bug fix.
…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.
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.