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

invoices: add subscribesingleinvoice #2356

Merged
merged 11 commits into from
Feb 2, 2019

Conversation

joostjager
Copy link
Contributor

@joostjager joostjager commented Dec 20, 2018

This PR allows listening to a notification stream for a single invoice.

Usage

SubscribeSingleInvoice is only available for applications integrating directly with the lnd invoices sub server grpc interface. It is not accessible through lncli.

After registering for single invoice notifications, the caller will immediately receive the current invoice state via the stream. From there onwards, lnd will continue pushing updates as they happen.

If the invoice that is subscribed to doesn't exist yet, the call will still block and start streaming when the invoice is created.

Build

Requires lnd to be built with the invoicesrpc build tag:

make tags="invoicesrpc"

@joostjager joostjager force-pushed the invoices-subserver branch 5 times, most recently from ff5e889 to 6225ced Compare December 20, 2018 22:42
@Roasbeef Roasbeef added database Related to the database/storage of LND payments Related to invoices/payments incomplete WIP PR, not fully finalized, but light review possible enhancement Improvements to existing features / behaviour labels Dec 21, 2018
@joostjager joostjager force-pushed the invoices-subserver branch 4 times, most recently from 6154c5e to 6fe9e32 Compare December 27, 2018 14:52
@joostjager joostjager force-pushed the invoices-subserver branch 3 times, most recently from 3340c88 to 3eedbcf Compare January 3, 2019 18:34
@joostjager joostjager changed the title invoices: add subscribesingleinvoice [no review] invoices: add subscribesingleinvoice Jan 3, 2019
@joostjager joostjager force-pushed the invoices-subserver branch 4 times, most recently from 44baf90 to dedf7fe Compare January 8, 2019 10:38
@Roasbeef Roasbeef requested a review from cfromknecht January 9, 2019 02:16
lnrpc/invoicesrpc/config_default.go Outdated Show resolved Hide resolved
lnrpc/invoicesrpc/config_default.go Outdated Show resolved Hide resolved
lnrpc/invoicesrpc/invoices_server.go Outdated Show resolved Hide resolved
lnrpc/invoicesrpc/log.go Outdated Show resolved Hide resolved
invoices/invoiceregistry.go Show resolved Hide resolved
lnrpc/utils.go Outdated Show resolved Hide resolved
lnrpc/invoicesrpc/config_active.go Show resolved Hide resolved

// Now that we know the full path of the invoices macaroon, we can
// check to see if we need to create it or not.
if !fileExists(macFilePath) && cfg.MacService != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

preferably this logic would also be made into a helper method in lnrpc as well. would you be opposed to doing so and then we can defer a refactoring of other subservers to a later PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gave it a try, but it gets many parameters. I think it may be better to, in a separate pr, have subservers expose some macaroon info and bake the macaroon somewhere else.

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good, thanks!

cmd/lncli/invoicesrpc_default.go Outdated Show resolved Hide resolved
cmd/lncli/invoicesrpc_active.go Outdated Show resolved Hide resolved
@joostjager joostjager force-pushed the invoices-subserver branch 3 times, most recently from 522ad59 to 970984a Compare January 11, 2019 09:56
@joostjager
Copy link
Contributor Author

@cfromknecht PTAL

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.

Thanks @joostjager, few last nits. Otherwise i'd say this about ready to land! 🎉

invoices/invoiceregistry.go Show resolved Hide resolved
invoices/invoiceregistry.go Outdated Show resolved Hide resolved
lnrpc/invoicesrpc/invoices_server.go Outdated Show resolved Hide resolved
lnrpc/invoicesrpc/invoices_server.go Outdated Show resolved Hide resolved
//
// NOTE: This is part of the lnrpc.SubServer interface.
func (s *Server) Stop() error {
close(s.quit)
Copy link
Contributor

Choose a reason for hiding this comment

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

i think it'd be worth protecting this with a compare and swap to prevent us from accidentally closing the same channel twice, as it would lead us to panic during shutdown. Start should be fine though since it's a NOP

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Calling Stop() twice is invalid use of the subserver and adding the compare/swap would camouflage this. We would loose the opportunity to discover the bug of the caller. In general I'd like to avoid defensive code, unless we are dealing with legacy that has become too complicate to reason about and we want to take no risk.

lntypes/hash.go Outdated Show resolved Hide resolved
lntypes/hash.go Outdated Show resolved Hide resolved
lntypes/hash.go Outdated Show resolved Hide resolved
lntypes/preimage.go Show resolved Hide resolved
invoices/invoiceregistry.go Show resolved Hide resolved
invoices/invoiceregistry_test.go Outdated Show resolved Hide resolved
invoices/invoiceregistry_test.go Show resolved Hide resolved
invoices/invoiceregistry_test.go Outdated Show resolved Hide resolved
invoices/invoiceregistry_test.go Outdated Show resolved Hide resolved
invoices/invoiceregistry_test.go Show resolved Hide resolved
@joostjager
Copy link
Contributor Author

Leaktest removed. CLI command removed.

PTAL @halseth @Roasbeef @cfromknecht

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

Needs a go mod tidy, but other than that, LGTM 🐣

go.sum Outdated Show resolved Hide resolved
@joostjager
Copy link
Contributor Author

Stale review dismissed, ptal

@joostjager joostjager force-pushed the invoices-subserver branch 2 times, most recently from 0f2ab5b to b640b48 Compare January 30, 2019 07:46
Roasbeef
Roasbeef previously approved these changes Jan 30, 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.

LGTM 🌶

cfromknecht
cfromknecht previously approved these changes Feb 1, 2019
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 📈

invoices/invoiceregistry_test.go Outdated Show resolved Hide resolved
This commit adds new hash and preimage types. These types are
similar to chainhash.Hash, except for that string representations
are not reversed.

The reason for adding dedicated types and not use [32]byte, is to
facilitate logging (%v displays as hex string) and have
standard methods to convert from byte slice and string with a
length check.
Previously chainhash.Hash was used, which converts to/from string in
reversed format. Payment hashes and preimages are supposed to be
non-reversed.
Sub server implementation is still empty. This is a preparatory
step for adding invoice functionality.
@halseth
Copy link
Contributor

halseth commented Feb 1, 2019

Needs a rebase!

Without this addition, sub servers cannot import google annotations
in their proto files.
As a preparation for subscribing to single invoices, InvoiceRegistry
needs to become aware of settling a settled invoice.
As a preparation for reusing the marshall code in the invoices sub
server.
@joostjager joostjager dismissed stale reviews from cfromknecht and Roasbeef via c049173 February 1, 2019 08:46
@joostjager
Copy link
Contributor Author

@halseth @cfromknecht @Roasbeef

Rebased, ptal

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 4af857f into lightningnetwork:master Feb 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database Related to the database/storage of LND enhancement Improvements to existing features / behaviour incomplete WIP PR, not fully finalized, but light review possible payments Related to invoices/payments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants