description |
---|
Learn how to make use of AMP and send satoshis to a peer without an invoice with keysend. |
Atomic Multi-path Payments are a new type of Lightning payments implemented by lnd in version v0.13.0-beta. As the new payment type is an end-to-end upgrade, it doesn’t require the internal of the network to update before it can be used widely. Instead, only the sender and receiver need to understand the new payment type.
Atomic Multi-path payments differ from existing Multi-path Payments (MPP) in that they are atomic, meaning despite being routed through separate paths. In MPPs, all shards use the same payment hash, making the individual routes easily correlatable and prone to only partial settlement. By contrast AMPs are either settled in full or not settled at all. Using AMP, it is possible to make payments safely by only knowing the public key of the recipient. It is also possible to create invoices that can be used repeatedly, which can be used to implement traditional subscriptions. Such invoices can also be published without security implications, allowing for use cases such as static donation invoices.
Atomic Multi-path Payments | Keysend | |
---|---|---|
Information necessary | Only node ID | Only node ID |
Preimage | Generated by sender, but only known by receiver | Generated and known by the sender |
Multi-path | Each shard carries its own payment hash | All shards use the same payment hash |
TLV Onion | Required | Required |
Static invoices | Allows for static invoices | Does not allow for invoices at all |
In a regular Lightning payment, the payee generates a preimage and transmits its hash as part of the invoice. The Hash Time-lock Contract (HTLC) pays to this hash, and to claim their payment, the payee reveals the preimage, allowing everyone along the route to finalize the payment.
In previous keysend payments, the sender generates the preimage and encrypts it in the onion payload of the payment, allowing the recipient to reveal it to claim their payment. Using AMP, the sender creates a single preimage, to which random values are added for each shard. The recipient is able to compute the original preimage using a XOR operation, meaning they are only able to claim the payment once all HTLCs are locked in, requiring them to claim the payment in full.
For a shard of size two this can be simplified as follows, with k being the preimage, and r being a random number:
* shard_1 = k ^ r
* shard_2 = r
shard_1 xor shard_2 = k ^ r ^ r = k
The information necessary for the recipient node to generate the correct preimages and reveal them to claim their payments is passed on in encrypted form as part of the Onion TLV (Type Length Value). This removes the need for additional interaction between the payer and the payee beyond transmitting a node public key or an invoice.
To be able to make and send Atomic Multi-path Payments, you will need to upgrade your node to LND 0.13 or above.
If you want to be able to receive spontaneous AMPs, you will need to set accept-amp=1
in your lnd.conf
file before starting your upgraded node.
You will be able to pay other AMP-enabled nodes with the command
lncli sendpayment --amt <amount> --dest <recipient’s public key> --amp
Alternatively, you will be able to create an AMP invoice by amending --amp
to the lncli addinvoice
command.
This is especially important for private nodes, as the invoice will include the necessary channel hints that can’t be expressed in the lncli sendpayment
command.
AMP invoices can be static and paid multiple times by switching the payment address in the invoice with a newly generated one. This payment address can be specified manually with the --pay_addr
flag. From lnd 0.14.0
onwards it is no longer necessary to set the --amp-reuse
flag to generate a payment address in LND.
Example usage:
lncli addinvoice --amt <amount in satoshis> --memo=’my first amp’ --amp
lncli payinvoice --pay_req <the amp invoice created by the receiver>
lncli sendpayment --amt <amount in satoshis> --dest <public key of receiver> --amp
lncli payinvoice --pay_req <the amp invoice created by the receiver> --pay_addr <the sha256 hash of a random number>
lncli payinvoice --pay_req <the amp invoice created by the receiver> --amp-reuse
Switching from MPP to AMP is easy. You will have to replace the --key_send
flag with a --amp
flag. You will no longer have to manually generate a preimage as the sender.
old:
lncli sendpayment --dest <destination public key> --amt <amount> --key_send
new:
lncli sendpayment --dest <destination public key> --amt <amount> --amp
If you are currently using keysend over the RPC layer, you will be able to smoothly switch over by simply setting the amp field. It is no longer necessary to manually generate and set a preimage.
{% content-ref url="amp.md" %} amp.md {% endcontent-ref %}