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

Implement non-interactive payments by including the preimage in the Sphinx e2e payload #132

Closed
5 tasks
Roasbeef opened this issue Feb 12, 2017 · 8 comments
Closed
5 tasks
Labels
enhancement Improvements to existing features / behaviour intermediate Issues suitable for developers moderately familiar with the codebase and LN onion routing p2p Code related to the peer-to-peer behaviour P4 low prio

Comments

@Roasbeef
Copy link
Member

With the current implementation there are two ways to send a payment to a remote node:

  1. Receive an invoice from them, and fulfill that invoice using the SendPayment RPC.
  2. Both the sender and receiver have been started with the --debug_htlc flag, and the sender sends a payment using the hard-coded "debug" preimage value within the HTLC.

A third mode is possible which is similar to the second payment route, but can be used in a "production" network as it'll properly generate a brand new preimage with each payment. This third mode is what I've been calling "sphinx send" (or "onion send", dunno). In this mode the sender generates the preimage for a targeted payment, and includes the pre-image either in the e2e payload, or the per-hop payload within the Sphinx packet embedded within the outgoing HTLC.

It is important to note, that this mode should not be used for retail or b2c payments. This is due to the fact that one is unable to properly obtain assigned proof-of-payment receipt as the sender generates the pre-image instead of the receiver int his mode. However, for paying a friend of LN, or other cases which don't require a verifiable proof-of-payment, then this mode allows for non-interactive payments. If a remote node accepts such payments (which should be denoted it it's global_features vector), then the node can simply advertise it's public key and that is all that's needed for other modes to send them payments.

Steps To Completion

  • Modify the logic in the routing module to accept an additional attribute to routing.LightningPayment request struct which toggles if a sphinx_send should be attempted or not. If so, then the last per-hop-payload should be modified to include a preimage generated by the sending node.

  • Within the peer struct's htlcManager goroutine, when an incoming HTLC arrives and we're the exit node but we can't find the preimage within the invoiceManager, then the per-hop-payload should be checked for a valid pre-image. If one matches, then that should be used to settle the HTLC, and all logic should proceed as normal.

  • The SendPaymentRequest struct should also be modified to add sphinx_send bool. On the server side, this bool should be passed into routing.LightningPayment request struct.

  • Finally, the additional argument should be added to the lncli tool.

  • A set of bits in the global_features should be allocated to signal knowledge of this new feature. If a user attempts to trigger a sphinx_send to a node that doesn't have these bits advertised, then the payment should fail.

A set of integration tests should be added to ensure the proper propagation and handling of sphinx_send payments within the network.

@Roasbeef Roasbeef added enhancement Improvements to existing features / behaviour intermediate Issues suitable for developers moderately familiar with the codebase and LN onion routing p2p Code related to the peer-to-peer behaviour labels Feb 12, 2017
@BitfuryLightning
Copy link
Contributor

Can I take this?

@Roasbeef
Copy link
Member Author

Roasbeef commented Jun 27, 2017

I consider this issue to be of a rather low priority. It doesn't require any modifications to the spec instead, but instead should be coupled with a signaling mechanism to use the extra bytes in the payload to signal that some, or all of the remaining per-hop payloads are to be decrypted as they're a complete package.

It's worth nothing though, that this feature isn't incompatible with obtaining a signed receipt as the encrypted error replies can slightly abused to (using the extra payload bytes to signal) request a signed invoice for a particular amount, returning the replay over an encapsulated "error".

@Roasbeef
Copy link
Member Author

Adding to the description in the issue, the following change needs to be made in lightning-onion:

  • Rather than _discarding) the currently un-used payload when parsing a sphinx packet, the value should instead be embedded within the HopData as a new field of type []byte

To accompany this change, the htlcswitch.ForwardingInfo struct should be modified to either opaquely embed the unused per-hop data, or create a set of abstractions around the unused payload, the first of which would define the interpretation and parameters for this feature.

We have a choice here w.r.t whether to define a generic extension mechanism now that uses 2-bytes to denote the interpretation of the payload, and then extend the payload over excess hops in the sphinx packet, or just use the 8+8+4+12 bytes to encode the payment pre-image in full.

@stevenroose
Copy link
Contributor

Is there a spec for this so that other implementations can receive these payments?

@andrewshvv
Copy link
Contributor

Hey @stevenroose ! No there is no yet, but I have implementation of it locally.

@meeDamian
Copy link
Contributor

Wouldn't it make more sense to add a requestinvoice method to a spec, that would return a short-lived invoice to a requesting node?

@Roasbeef
Copy link
Member Author

Roasbeef commented Jun 28, 2018 via email

@Roasbeef Roasbeef added the P4 low prio label Jul 10, 2018
@Roasbeef
Copy link
Member Author

Will be fixed by #2455

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements to existing features / behaviour intermediate Issues suitable for developers moderately familiar with the codebase and LN onion routing p2p Code related to the peer-to-peer behaviour P4 low prio
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants