Skip to content

Create ExternalPreimage flag on Invoices#3

Merged
treygriffith merged 2 commits into
k#epic/cross-chain-preimagefrom
k#feature/ext-preimage-invoice
Jul 2, 2018
Merged

Create ExternalPreimage flag on Invoices#3
treygriffith merged 2 commits into
k#epic/cross-chain-preimagefrom
k#feature/ext-preimage-invoice

Conversation

@treygriffith
Copy link
Copy Markdown
Member

This change adds an ExternalPreimage indicator on Invoices, and updates the AddInvoice RPC to be able to set that flag.

When this indicator is set, the user must include an r_hash, which will now be persisted with the Invoice. ExternalPreimage invoices are meant for invoices where the preimage is not stored locally in the LND instance's storage, but offsite in another system.

Actually using these invoices in a payment flow is forthcoming in another change.

This modifies the Invoice schema to include an indicator of
whether the preimage for a given invoice is stored locally or
if it is stored externally.

For externally stored preimages, the Payment Hash of the Invoice
is persisted with it, since it needs to be accessed by other users
and it can no longer be generated from the PaymentPreimage.
Adds a boolean indicator ExternalPreimage to the AddInvoice RPC
to allow for consumers to create invoices that reference external
preimages.

Also adds ExternalPreimage to Invoices that are sent in response
to various RPC calls.
Comment thread lnrpc/rpc.swagger.json
"format": "boolean",
"description": "/ Whether this invoice should include routing hints for private channels."
},
"external_preimage": {
Copy link
Copy Markdown

@dannypaz dannypaz Jun 28, 2018

Choose a reason for hiding this comment

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

Just so we know, was this updated from the cli util? #7 in usage https://github.com/grpc-ecosystem/grpc-gateway#usage

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.

yes it was - the only file I updated directly was rpc.proto

Comment thread channeldb/invoice_test.go
}
if !reflect.DeepEqual(fakeExternalPreimageInvoice, dbExternalPreimageInvoice) {
t.Fatalf("invoice fetched from db doesn't match original %v vs %v",
spew.Sdump(fakeExternalPreimageInvoice), spew.Sdump(dbExternalPreimageInvoice))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does this log show up correctly if its wrong? (id imagine this is a huge log)

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.

Yes, but only for failed tests cases.

Comment thread channeldb/invoices.go
} else {
if bytes.Equal(i.Terms.PaymentPreimage[:], zeroPreimage[:]) {
return zeroHash, fmt.Errorf("Invoices must have a preimage or" +
"use ExternalPreimages")
Copy link
Copy Markdown

@dannypaz dannypaz Jun 29, 2018

Choose a reason for hiding this comment

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

[nit] This message is clear if you have a context. A clearer message could be "Invoices must have a preimage or ExternalPreimages must be set to true"

Comment thread channeldb/invoices.go
return err
}

paymentHash, err := getPaymentHash(i)
Copy link
Copy Markdown

@dannypaz dannypaz Jun 29, 2018

Choose a reason for hiding this comment

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

Did you see any good reason for why err is in the second position for these returned values? I was surprised that these were switched?

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.

It's just a golang convention: https://gobyexample.com/errors

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hah oh jeez (my mind is blown)

@dannypaz
Copy link
Copy Markdown

@treygriffith this LGTM. Did we want to setup CI for this repo?

@treygriffith treygriffith merged commit 4deb116 into k#epic/cross-chain-preimage Jul 2, 2018
@treygriffith treygriffith deleted the k#feature/ext-preimage-invoice branch July 2, 2018 02:38
treygriffith added a commit that referenced this pull request Jul 3, 2018
This change adds a gRPC protobuf file and client to lnd for retrieving
external preimages (see #3).

It also adds a thin wrapper around the gRPC client in order to lazily
connect to the server and reuse connections where possible. It also
wraps the streaming API of the request feel more like a request/response
pattern.

It initializes this client in the server initialization, and provides it
to each created Link as part of the ChannelLinkConfig, in anticipation of
its use in the exitHop.
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.

2 participants