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

contractcourt: settle invoice when claiming HTLC on-chain #2075

Merged

Conversation

wpaulino
Copy link
Contributor

In this PR, we extend the htlcSuccessResolver to settle the invoice,
if any, of the corresponding on-chain HTLC sweep. This ensures that the
invoice state is consistent as when claiming the HTLC "off-chain".

Partly addresses #2032 (the receiver side).

@Roasbeef Roasbeef added htlcswitch P2 should be fixed if one has time bug fix contracts labels Oct 19, 2018
@wpaulino wpaulino force-pushed the settle-invoice-on-chain-sweep branch 2 times, most recently from 2156b9d to 08746aa Compare October 19, 2018 23:16
witness_beacon.go Outdated Show resolved Hide resolved
contractcourt/contract_resolvers.go Outdated Show resolved Hide resolved
@wpaulino wpaulino force-pushed the settle-invoice-on-chain-sweep branch 3 times, most recently from 26e6a97 to c647d55 Compare October 22, 2018 20:37
contractcourt/contract_resolvers.go Outdated Show resolved Hide resolved
contractcourt/contract_resolvers.go Outdated Show resolved Hide resolved
if !invoicesResp.Invoices[0].Settled {
t.Fatalf("expected invoice to be settled")
}

Copy link
Contributor

Choose a reason for hiding this comment

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

You could consider adding test coverage on the unit level. In general, I myself prefer to test things only in an integration test if there is really no other option.

I have an (unmerged) contract resolver test for the outgoingcontestresolver, 33c348b.

But I can also imagine that you consider this too much effort in comparison to the size of the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opted for the integration test change as we're interested in making sure that the invoice state is reflected correctly within the database. I guess we could have this done at the unit test level though. Let me know if you'd like to proceed with that instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

We test lots of database behaviour in unit tests. I'd go for that. Integration tests can be so expensive in maintenance over their full lifetimes. Checking flakes, dirty time.sleeps, etc. Maybe ask a second person for an opinion.

@wpaulino wpaulino force-pushed the settle-invoice-on-chain-sweep branch from c647d55 to 0b5a9e9 Compare December 11, 2018 07:58
lnd_test.go Outdated Show resolved Hide resolved
lnd_test.go Outdated Show resolved Hide resolved
@wpaulino
Copy link
Contributor Author

Comments addressed, PTAL @Roasbeef @joostjager

channeldb/invoices.go Outdated Show resolved Hide resolved
contractcourt/contract_resolvers.go Outdated Show resolved Hide resolved
@wpaulino wpaulino force-pushed the settle-invoice-on-chain-sweep branch from ef5c3a8 to 7f672a5 Compare January 22, 2019 00:39
@joostjager
Copy link
Contributor

I still think a unit test would've been more appropriate for this PR (see earlier comment above), but if a second reviewer approves, I am good.

Other than that, LGTM

Roasbeef
Roasbeef previously approved these changes Jan 23, 2019
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.

One style related nit, but other than that, LGTM 🐲

Agree with Joost here that this package could certainly use additional unit tests. I don't think it's worth blocking the merge of this PR as this section is already covered with additional unit tests. Further down the release timeline, if we're in a testing freeze with time to spare, we can circle back and bolster the unit tests in this package. This may be something we want to do in-between 0.6 and the next major release as well, while we gather PRs for the next milestone.

contractcourt/channel_arbitrator.go Show resolved Hide resolved
contractcourt/htlc_success_resolver.go Show resolved Hide resolved
Co-authored-by: Joost Jager <joost.jager@gmail.com>
wpaulino and others added 4 commits January 22, 2019 20:46
In this commit, we extend the remote/receiver chain claim integration
test to assert that the on-disk representation of the invoice on the
receiving side (Carol) is marked as settled due to the claiming the HTLC
on-chain.
Co-authored-by: Joost Jager <joost.jager@gmail.com>
Previously, contract resolvers that needed to publish a second level tx,
did not have access to the original htlc amount.

This commit reconstructs this amount from data that is already persisted
in arbitrator log.

Co-authored-by: Joost Jager <joost.jager@gmail.com>
In this commit, we extend the htlcSuccessResolver to settle the invoice,
if any, of the corresponding on-chain HTLC sweep. This ensures that the
invoice state is consistent as when claiming the HTLC "off-chain".
@wpaulino wpaulino force-pushed the settle-invoice-on-chain-sweep branch from d712219 to 016add6 Compare January 23, 2019 04:48
@Roasbeef Roasbeef merged commit 6c610d9 into lightningnetwork:master Jan 24, 2019
@wpaulino wpaulino deleted the settle-invoice-on-chain-sweep branch January 24, 2019 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix contracts htlcswitch P2 should be fixed if one has time
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants