chantools
chantools copied to clipboard
chantools scbforceclose: extract close tx from SCB and sign it
This is part of https://github.com/lightningnetwork/lnd/issues/7658#issuecomment-1774983789 implementation.
This PR depends on https://github.com/lightningnetwork/lnd/pull/8183 (Field chanbackup.Single.CloseTxInputs is needed.)
I added chantools scbforceclose
command, which extracts closing tx from SCB and signs it and optionally broadcasts.
New command:
chantools scbforceclose --help
$ chantools scbforceclose --helpIf you are certain that a node is offline for good (AFTER you've tried SCB!) and a channel is still open, you can use this method to force-close your latest state that you have in your channel.db.
!!! WARNING !!! DANGER !!! WARNING !!!
If you do this and the state that you publish is not the latest state, then the remote node could punish you by taking the whole channel amount if they come online before you can sweep the funds from the time locked (144 - 2000 blocks) transaction or they have a watch tower looking out for them.
This should absolutely be the last resort and you have been warned!
Usage: chantools scbforceclose [flags]
Examples: chantools scbforceclose --multi_file channel.backup
Flags: --apiurl string API URL to use (must be esplora compatible) (default "https://blockstream.info/api") --bip39 read a classic BIP39 seed and passphrase from the terminal instead of asking for lnd seed format or providing the --rootkey flag -h, --help help for scbforceclose --multi_backup string a hex encoded multi-channel backup obtained from exportchanbackup for force-closing channels --multi_file string the path to a single-channel backup file (channel.backup) --publish publish force-closing TX to the chain API instead of just printing the TX --rootkey string BIP32 HD root key of the wallet to use for decrypting the backup and signing tx; leave empty to prompt for lnd 24 word aezeed --single_backup string a hex encoded single channel backup obtained from exportchanbackup for force-closing channels --single_file string the path to a single-channel backup file
Global Flags: -r, --regtest Indicates if regtest parameters should be used -s, --signet Indicates if the public signet parameters should be used -t, --testnet Indicates if testnet parameters should be used
The command extracts closing transactions from SCB, signs and prints them.
Example
Here is an example of using chantools scbforceclose
in testnet to sign a force closing transaction and to publish it.
chantools --testnet scbforceclose --single_backup xxx --publish --apiurl https://blockstream.info/testnet/api
$ chantools --testnet scbforceclose --single_backup xxx --publish --apiurl https://blockstream.info/testnet/api 2023-12-31 18:06:04.121 [INF] CHAN: chantools version v0.12.1 commit Input your 24-word mnemonic separated by spaces: ***Input your cipher seed passphrase (press enter if your seed doesn't have a passphrase):
Found 1 channel backups, 1 of them have close tx.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ If you are certain that a node is offline for good (AFTER you've tried SCB!) and a channel is still open, you can use this method to force-close your latest state that you have in your channel.db.
!!! WARNING !!! DANGER !!! WARNING !!!
If you do this and the state that you publish is not the latest state, then the remote node could punish you by taking the whole channel amount if they come online before you can sweep the funds from the time locked (144 - 2000 blocks) transaction or they have a watch tower looking out for them.
This should absolutely be the last resort and you have been warned! @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Type YES to proceed: YES Signed transactions will be broadcasted automatically. Type YES again to proceed: YES xxx:0 xxxxxxxx
2023-12-31 18:06:28.796 [INF] CHAN: Published TX xxx, response: xxx
(To use --publish
option in testnet, --apiurl should be adjusted. Hopefully newExplorerAPI
from https://github.com/lightninglabs/chantools/pull/107 is fixing this.)
TODOs
- [ ] validate close transaction? Does the fact that it is signed and serialized imply that it is valid. I'm interested in a way to produce such transactions for all the channels just to make sure they are producible from SCB and are valid
- [ ] README for scbforceclose command
- [ ] deduplicate code between createSignDesc and LightningChannel.CreateSignDesc. See https://github.com/lightninglabs/chantools/issues/108
I updated both PRs. Signing now happens in chantools scbforceclose
. I put an example into PR's description.
@guggero Please take another look!
Rebased for LND 0.18, fixed lint warnings. Tested manually.
Thanks for the review! I updated LND PR and this PR. The code producing signed transaction was moved to LND to use it in itest.
I rebased the PR, updated go replace to the latest https://github.com/lightningnetwork/lnd/pull/8183 version.
Also included the suggested patch for dump.go. @guggero I put your name in Author field of the commit.
@starius, remember to re-request review from reviewers when ready