lnd's wallet now features a full set of PSBT functionality, including creating, signing and funding channels with PSBTs.
wallet psbt fundcommand is very similar to
walletcreatefundedpsbtcommand. One main difference is that you can specify a template PSBT in the
lnclivariant that contains the output(s) and optional inputs. Another difference is that for the
lncliexpects the amounts to be in satoshis instead of fractions of a bitcoin.
fundcommand. We again want to send half a coin to
bcrt1qjrdns4f5zwkv29ln86plqzs092yd5fg6nsz8rebut we want to select our inputs manually.
finalizesub command of the wallet:
lndby using a PSBT as the funding transaction. We will use
bitcoindto create and sign the transaction just to keep the example simple. Of course any other PSBT compatible wallet could be used and the process would likely be spread out over multiple signing steps. The goal of this example is not to cover each and every possible edge case but to help users of
lndunderstand what inputs the
03db1e56e5f76bc4018cf6f03d1bb98a7ae96e3f18535e929034f85e7f1ca2b8acby using a PSBT. That means,
lndcan have a wallet balance of
0and is still able to open a channel. We'll jump into an example right away.
lndnode, we know it's after 10 minutes. So as long as the whole process takes less than 10 minutes, everything should work fine.
Wasabifor instance, where the "publish" button is very easy to hit by accident.
--psbtflag in the
openchannelcommand starts an interactive dialog between
lncliand the user. Below the command you see an example output from a regtest setup. Of course all values will be different.
openchannelrunning as is.
bitcoindto create a funding transaction
bitcoind. We'll go ahead and execute it now. The meaning of this command is something like "bitcoind, give me a PSBT that sends the given amount to the given address, choose any input you see fit":
bitcoindhas given us a transaction that would pay
3060satoshi in fees. Fee estimation/calculation can be changed with parameters of the
walletcreatefundedpsbtcommand. To see all options, use
bitcoin-cli help walletcreatefundedpsbt.
lndto create a funding transaction
lndcan also create PSBTs. This assumes a scenario where one instance of
lndonly has public keys (watch only mode) and a secondary, hardened and firewalled
lndinstance has the corresponding private keys. On the watching only mode, the following command can be used to create the funding PSBT:
lnclithat is still waiting for our input.
bitcoindfor this again, but in practice this would now happen on a hardware wallet and perhaps
bitcoindwould only know the public keys and couldn't sign for the transaction itself. Again, this is only an example and can't reflect all real-world use cases.
lndnode model as described in 2b, you can achieve the same result with the following command:
openchanneland feed it into the
--base_psbtparameter of the next
openchannelcommand. This won't work with
bitcoindthough, as it cannot take a PSBT as partial input for the
bitcoin-cliexamples from the command line can be combined into a single command. For example:
openchannel --psbttwo times, combine the funding addresses as shown above, verify the PSBT, sign it and finally paste it into the terminal of the first command.
lndthen goes ahead and finishes the negotiations with peer 1. If successful,
lndpublishes the transaction. In the meantime we paste the same PSBT into the second terminal window. But by now, the peer 2 for channel 2 has timed out our funding flow and aborts the negotiation. Normally this would be fine, we would just not publish the funding transaction. But in the batch case, channel 1 has already published the transaction that contains both channel outputs. But because we never got a signature from peer 2 to spend the funds now locked in a 2-of-2 multisig, the fund are lost (unless peer 2 cooperates in a complicated, manual recovery process).
--no_publishflag for each channel but the very last. This prevents the full batch transaction to be published before each and every single channel has fully completed its funding negotiation.