Builder's Guide
Ask or search…

Atomic Multi-path Payments (AMP)

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
Information necessary
Only node ID
Only node ID
Generated by sender, but only known by receiver once all shards are paid
Generated and known by the sender
Each shard carries its own payment hash
All shards use the same payment hash
TLV Onion
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.
Video: Get AMPed: Making Atomic Multi-Path Payments

Get your node ready for AMPs

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

Example: Generate a static donation QR code for your node

Using AMP, we can generate static QR codes that others can pay to, repeatedly.
Prerequisites: You need to run lnd 0.13 or above with accept-amp=1 enabled in your configuration file.
Step 1: Generate an AMP invoice We can create an AMP invoice with the command lncli addinvoice --amp Optionally we can add a (publicly visible) memo or a fixed amount with the --memo="add your memo here" and --amt <amount in satoshis> flags.
Step 2: Turn the invoice into a QR code Your node will return an r_hash, a payment request and a payment address. There are many ways you can use to transform your payment request into a QR code, embed it on your website or add it to your social media. LibreOffice has a built-in functionality, and there are plenty of freely available online tools.
Step 3: Pay a static AMP If your mobile wallet supports payments to AMP invoices, the invoice needs to be scanned and optionally the amount needs to be specified. To pay an AMP invoice from the command line, you only need to execute lncli payinvoice <amp invoice> If the AMP invoice does not contain an amount, you can specify the amount you would like to pay with the --amt flag.

Switch from Keysend to AMP

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> --keysend
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.