Skip to content

Commit

Permalink
GITBOOK-426: change request with no subject merged in GitBook
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo Weese authored and gitbook-bot committed May 10, 2024
1 parent 2d8646b commit 89576a4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
* [Sending Payments](lightning-network-tools/lnd/payments.md)
* [Atomic Multi-path Payments (AMP)](lightning-network-tools/lnd/amp.md)
* [Receiving Payments](lightning-network-tools/lnd/receiving.md)
* [Partially Signed Bitcoin Transactions](lightning-network-tools/lnd/psbt.md)
* [Unconfirmed Bitcoin Transactions](lightning-network-tools/lnd/unconfirmed-bitcoin-transactions.md)
* [Channel Fees](lightning-network-tools/lnd/channel-fees.md)
* [Macaroons](lightning-network-tools/lnd/macaroons.md)
Expand All @@ -66,6 +65,8 @@
* [Configuring Tor](lightning-network-tools/lnd/configuring\_tor.md)
* [Enable ‘Neutrino mode’ in Bitcoin Core](lightning-network-tools/lnd/enable-neutrino-mode-in-bitcoin-core.md)
* [Send Messages With Keysend](lightning-network-tools/lnd/send-messages-with-keysend.md)
* [Partially Signed Bitcoin Transactions](lightning-network-tools/lnd/psbt.md)
* [Bulk onchain actions with PSBTs](lightning-network-tools/lnd/bulk-psbt.md)
* [Debugging LND](lightning-network-tools/lnd/debugging\_lnd.md)
* [Fuzzing LND](lightning-network-tools/lnd/fuzz.md)
* [LND and etcd](lightning-network-tools/lnd/etcd.md)
Expand Down
46 changes: 46 additions & 0 deletions lightning-network-tools/lnd/bulk-psbt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
description: >-
PSBTs can be used to batch custom onchain transactions for maximum cost
efficiency, for example to open multiple channels or send to multiple
destinations in one transaction.
---

# Bulk onchain actions with PSBTs

Partially Signed Bitcoin Transactions (PSBTs) are a standardized format to create, edit, amend, and sign Bitcoin transactions. This is useful when creating custom transactions, for example by specifying which inputs to consume, or including non-standard outputs.

An introductory guide to PSBTs and LND [can be found here](psbt.md).

## Bulk channel opens

PSBTs can be used to open multiple channels in a single onchain transaction, similar to lncli batchopenchannel.

To begin, a channel open is initiated using the [OpenChan API](https://lightning.engineering/api-docs/api/lnd/lightning/open-channel-sync#code-samples), specifically the lnrpc.OpenChannelRequest. We specify all the parameters we need for the channel open, such as the channel size (local\_funding\_amount), the peer pubkey (node\_pubkey) and whether the channel shall be announced (private).

For funding\_shim we use lnrpc.PsbtShim and an empty base\_pbst. We must not forget to set no\_publish to true as well.

This will return a PSBT (psbt\_fund.psbt). We repeat the above for the channel parameters of the second channel. This round, we pass the returned PSBT as the base\_psbt, instead of an empty value.

We can repeat this as often as we need. For the final round, we will set no\_publish to false.

To finalize the PSBT, we can use the [FundPsbt](https://lightning.engineering/api-docs/api/lnd/wallet-kit/fund-psbt) call. If you want to use funds held in another application or device, remember to make sure that the wallet’s xpubs have been [imported to LND](https://docs.lightning.engineering/lightning-network-tools/lnd/key\_import).

To sign the transaction, we will have to pass the PSBT either to LND using the [signPsbt](https://lightning.engineering/api-docs/api/lnd/wallet-kit/sign-psbt) RPC call. Alternatively, the PSBT will have to be signed by the external application or wallet.

Now we need the [fundingStateStep](https://lightning.engineering/api-docs/api/lnd/lightning/funding-state-step) API to verify the PSBT using the psbt\_verify call with skip\_finalize set to true for all channels except the last one (1 to n-1). The correct pending\_chan\_id has to be specified each time. This verifies that the transaction contains the correct outputs to fund the channel. These outputs have to be used to create the correct commitment transactions.

Only for the last channel do we repeat the above step with the latest pending\_chan\_id with skip\_finalize set to false.

Finally, we repeat the above step one last time for the first channel, using the latest PSBT, the latest pending\_chan\_id and psbt\_finalize set to true.

## Bulk onchain transactions

The [SendMany](https://lightning.engineering/api-docs/api/lnd/lightning/send-many) API lets you send an onchain transaction with multiple outputs, but it does not let you select specific inputs, and cannot be combined with a channel open.

We begin by calling the [FundPsbt](https://lightning.engineering/api-docs/api/lnd/wallet-kit/fund-psbt) API. We can specify our raw inputs and outputs as part of the raw field. If we want to send this transaction from an external wallet, or have multiple onchain accounts imported to LND, we will also need to specify the account.

Using the PSBT returned in the above step, we call the [FinalizePsbt](https://lightning.engineering/api-docs/api/lnd/wallet-kit/finalize-psbt) API.

The resulting PSBT only needs to be signed. This is done with the [signPsbt](https://lightning.engineering/api-docs/api/lnd/wallet-kit/sign-psbt) RPC call.

Finally, the PSBT needs to be published, which is done with the raw transaction and [PublishTransaction](https://lightning.engineering/api-docs/api/lnd/wallet-kit/publish-transaction).

0 comments on commit 89576a4

Please sign in to comment.