2
0
mirror of https://github.com/guggero/chantools synced 2024-11-07 03:20:43 +00:00
chantools/README.md

443 lines
16 KiB
Markdown
Raw Normal View History

2019-11-24 11:32:59 +00:00
# Channel tools
2019-11-09 14:41:31 +00:00
2020-01-04 11:19:42 +00:00
## Index
* [Installation](#installation)
* [Overview](#overview)
* [Commands](#commands)
2020-03-03 21:13:20 +00:00
+ [chanbackup](#chanbackup)
2020-03-24 19:05:34 +00:00
+ [compactdb](#compactdb)
2020-01-04 23:35:08 +00:00
+ [derivekey](#derivekey)
2020-01-04 11:19:42 +00:00
+ [dumpbackup](#dumpbackup)
+ [dumpchannels](#dumpchannels)
2020-01-04 23:33:43 +00:00
+ [filterbackup](#filterbackup)
2020-01-06 16:21:29 +00:00
+ [fixoldbackup](#fixoldbackup)
2020-02-02 16:43:30 +00:00
+ [genimportscript](#genimportscript)
2020-01-04 11:19:42 +00:00
+ [forceclose](#forceclose)
+ [rescueclosed](#rescueclosed)
+ [rescuefunding](#rescuefunding)
2020-01-04 11:19:42 +00:00
+ [showrootkey](#showrootkey)
+ [summary](#summary)
+ [sweeptimelock](#sweeptimelock)
2020-02-02 18:56:05 +00:00
+ [walletinfo](#walletinfo)
2020-01-04 11:19:42 +00:00
2019-12-28 15:04:36 +00:00
This tool provides helper functions that can be used to rescue funds locked in
2020-02-02 18:56:05 +00:00
`lnd` channels in case `lnd` itself cannot run properly any more.
2019-11-09 14:41:31 +00:00
2019-12-07 14:21:08 +00:00
**WARNING**: This tool was specifically built for a certain rescue operation and
might not be well-suited for your use case. Or not all edge cases for your needs
are coded properly. Please look at the code to understand what it does before
you use it for anything serious.
2020-02-02 18:56:05 +00:00
**WARNING 2**: This tool will query public block explorer APIs for some of the
commands, your privacy might not be preserved. Use at your own risk or supply
a private API URL with `--apiurl`.
2019-12-07 14:21:08 +00:00
2020-01-03 10:30:18 +00:00
## Installation
To install this tool, make sure you have `go 1.13.x` (or later) and `make`
installed and run the following command:
```bash
make install
```
2019-12-07 14:21:08 +00:00
## Overview
```text
Usage:
chantools [OPTIONS] <command>
Application Options:
2020-01-03 10:30:18 +00:00
--testnet Set to true if testnet parameters should be used.
2019-12-07 14:21:08 +00:00
--apiurl= API URL to use (must be esplora compatible). (default: https://blockstream.info/api)
--listchannels= The channel input is in the format of lncli's listchannels format. Specify '-' to read from stdin.
--pendingchannels= The channel input is in the format of lncli's pendingchannels format. Specify '-' to read from stdin.
--fromsummary= The channel input is in the format of this tool's channel summary. Specify '-' to read from stdin.
--fromchanneldb= The channel input is in the format of an lnd channel.db file.
Help Options:
-h, --help Show this help message
Available commands:
2020-03-03 21:13:20 +00:00
chanbackup Create a channel.backup file from a channel database.
2020-03-24 19:05:34 +00:00
compactdb Open a source channel.db database file in safe/read-only mode and copy it to a fresh database, compacting it in the process.
2020-02-02 16:43:30 +00:00
derivekey Derive a key with a specific derivation path from the BIP32 HD root key.
dumpbackup Dump the content of a channel.backup file.
dumpchannels Dump all channel information from lnd's channel database.
filterbackup Filter an lnd channel.backup file and remove certain channels.
fixoldbackup Fixes an old channel.backup file that is affected by the lnd issue #3881 (unable to derive shachain root key).
forceclose Force-close the last state that is in the channel.db provided.
genimportscript Generate a script containing the on-chain keys of an lnd wallet that can be imported into other software like bitcoind.
rescueclosed Try finding the private keys for funds that are in outputs of remotely force-closed channels.
rescuefunding Rescue funds locked in a funding multisig output that never resulted in a proper channel.
2020-02-02 16:43:30 +00:00
showrootkey Extract and show the BIP32 HD root key from the 24 word lnd aezeed.
summary Compile a summary about the current state of channels.
sweeptimelock Sweep the force-closed state after the time lock has expired.
2020-02-02 18:56:05 +00:00
walletinfo Shows relevant information about an lnd wallet.db file and optionally extracts the BIP32 HD root key.
2019-12-07 14:21:08 +00:00
```
2020-01-04 11:19:42 +00:00
## Commands
2020-03-03 21:13:20 +00:00
### chanbackup
```text
Usage:
chantools [OPTIONS] chanbackup [chanbackup-OPTIONS]
[chanbackup command options]
--rootkey= BIP32 HD root key of the wallet that should be used to create the backup. Leave empty to prompt for lnd 24 word aezeed.
--channeldb= The lnd channel.db file to create the backup from.
--multi_file= The lnd channel.backup file to create.
```
This command creates a new channel.backup from a channel.db file.
Example command:
```bash
chantools chanbackup --rootkey xprvxxxxxxxxxx \
--channeldb ~/.lnd/data/graph/mainnet/channel.db \
--multi_file new_channel_backup.backup
```
2020-03-24 19:05:34 +00:00
### compactdb
```text
Usage:
chantools [OPTIONS] compactdb [compactdb-OPTIONS]
[compactdb command options]
--txmaxsize= Maximum transaction size. (default 65536)
--sourcedb= The lnd channel.db file to create the database backup from.
--destdb= The lnd new channel.db file to copy the compacted database to.
```
This command opens a database in read-only mode and tries to create a copy of it
to a destination file, compacting it in the process.
Example command:
```bash
chantools compactdb --sourcedb ~/.lnd/data/graph/mainnet/channel.db \
--destdb ./results/compacted.db
```
2020-01-04 12:11:11 +00:00
### derivekey
```text
Usage:
chantools [OPTIONS] derivekey [derivekey-OPTIONS]
[derivekey command options]
--rootkey= BIP32 HD root key to derive the key from. Leave empty to prompt for lnd 24 word aezeed.
2020-01-04 12:11:11 +00:00
--path= The BIP32 derivation path to derive. Must start with "m/".
--neuter Do not output the private key, just the public key.
```
This command derives a single key with the given BIP32 derivation path from the
root key and prints it to the console. Make sure to escape apostrophes in the
derivation path.
Example command:
```bash
chantools derivekey --rootkey xprvxxxxxxxxxx --path m/1017\'/0\'/5\'/0/0 \
--neuter
```
2020-01-04 11:19:42 +00:00
### dumpbackup
2019-12-07 14:21:08 +00:00
```text
Usage:
2020-01-04 11:19:42 +00:00
chantools [OPTIONS] dumpbackup [dumpbackup-OPTIONS]
2019-12-07 14:21:08 +00:00
2020-01-04 11:19:42 +00:00
[dumpbackup command options]
--rootkey= BIP32 HD root key of the wallet that was used to create the backup. Leave empty to prompt for lnd 24 word aezeed.
2020-01-04 11:19:42 +00:00
--multi_file= The lnd channel.backup file to dump.
2019-12-07 14:21:08 +00:00
```
2020-01-04 11:19:42 +00:00
This command dumps all information that is inside a `channel.backup` file in a
human readable format.
Example command:
2019-12-07 14:21:08 +00:00
```bash
2020-01-04 11:19:42 +00:00
chantools dumpbackup --rootkey xprvxxxxxxxxxx \
--multi_file ~/.lnd/data/chain/bitcoin/mainnet/channel.backup
2019-12-07 14:21:08 +00:00
```
2020-01-04 11:19:42 +00:00
### dumpchannels
2019-12-07 14:21:08 +00:00
```text
Usage:
2020-01-04 11:19:42 +00:00
chantools [OPTIONS] dumpchannels [dumpchannels-OPTIONS]
2019-12-07 14:21:08 +00:00
2020-01-04 11:19:42 +00:00
[dumpchannels command options]
--channeldb= The lnd channel.db file to dump the channels from.
2019-12-07 14:21:08 +00:00
```
2020-01-04 11:19:42 +00:00
This command dumps all open and pending channels from the given lnd `channel.db`
file in a human readable format.
2019-12-07 14:21:08 +00:00
Example command:
```bash
2020-01-04 11:19:42 +00:00
chantools dumpchannels --channeldb ~/.lnd/data/graph/mainnet/channel.db
2019-12-07 14:21:08 +00:00
```
2020-01-04 23:33:43 +00:00
### filterbackup
```text
Usage:
chantools [OPTIONS] filterbackup [filterbackup-OPTIONS]
[filterbackup command options]
--rootkey= BIP32 HD root key of the wallet that was used to create the backup. Leave empty to prompt for lnd 24 word aezeed.
--multi_file= The lnd channel.backup file to filter.
--discard= A comma separated list of channel funding outpoints (format <fundingTXID>:<index>) to remove from the backup file.
```
2020-02-02 18:56:05 +00:00
Filter an `lnd` `channel.backup` file by removing certain channels (identified by
2020-01-04 23:33:43 +00:00
their funding transaction outpoints).
Example command:
```bash
chantools filterbackup --rootkey xprvxxxxxxxxxx \
--multi_file ~/.lnd/data/chain/bitcoin/mainnet/channel.backup \
--discard 2abcdef2b2bffaaa...db0abadd:1,4abcdef2b2bffaaa...db8abadd:0
```
2020-01-06 16:21:29 +00:00
### fixoldbackup
```text
Usage:
chantools [OPTIONS] fixoldbackup [fixoldbackup-OPTIONS]
[fixoldbackup command options]
--rootkey= BIP32 HD root key of the wallet that was used to create the backup. Leave empty to prompt for lnd 24 word aezeed.
--multi_file= The lnd channel.backup file to fix.
```
2020-02-02 18:56:05 +00:00
Fixes an old channel.backup file that is affected by the `lnd` issue
2020-01-06 16:21:29 +00:00
[#3881](https://github.com/lightningnetwork/lnd/issues/3881) (<code>[lncli]
unable to restore chan backups: rpc error: code = Unknown desc = unable
to unpack chan backup: unable to derive shachain root key: unable to derive
private key</code>).
Example command:
```bash
chantools fixoldbackup --rootkey xprvxxxxxxxxxx \
--multi_file ~/.lnd/data/chain/bitcoin/mainnet/channel.backup
```
2020-01-04 11:19:42 +00:00
### forceclose
2019-12-07 14:21:08 +00:00
```text
Usage:
chantools [OPTIONS] forceclose [forceclose-OPTIONS]
[forceclose command options]
--rootkey= BIP32 HD root key to use. Leave empty to prompt for lnd 24 word aezeed.
2019-12-07 14:21:08 +00:00
--channeldb= The lnd channel.db file to use for force-closing channels.
--publish Should the force-closing TX be published to the chain API?
```
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!**
Example command:
```bash
chantools --fromsummary results/summary-xxxx-yyyy.json \
forceclose \
--channeldb ~/.lnd/data/graph/mainnet/channel.db \
--rootkey xprvxxxxxxxxxx \
--publish
```
2020-02-02 16:43:30 +00:00
### genimportscript
```text
Usage:
chantools [OPTIONS] genimportscript [genimportscript-OPTIONS]
[genimportscript command options]
--rootkey= BIP32 HD root key to use. Leave empty to prompt for lnd 24 word aezeed.
2020-04-02 08:27:38 +00:00
--format= The format of the generated import script. Currently supported are: bitcoin-cli, bitcoin-cli-watchonly, bitcoin-importwallet.
--lndpaths Use all derivation paths that lnd uses. Results in a large number of results. Cannot be used in conjunction with --derivationpath.
--derivationpath= Use one specific derivation path. Specify the first levels of the derivation path before any internal/external branch. Cannot be used in conjunction with --lndpaths. (default m/84'/0'/0')
2020-02-02 16:43:30 +00:00
--recoverywindow= The number of keys to scan per internal/external branch. The output will consist of double this amount of keys. (default 2500)
--rescanfrom= The block number to rescan from. Will be set automatically from the wallet birthday if the lnd 24 word aezeed is entered. (default 500000)
```
Generates a script that contains all on-chain private (or public) keys derived
2020-02-02 18:56:05 +00:00
from an `lnd` 24 word aezeed wallet. That script can then be imported into other
2020-02-02 16:43:30 +00:00
software like bitcoind.
The following script formats are currently supported:
* `bitcoin-cli`: Creates a list of `bitcoin-cli importprivkey` commands that can
be used in combination with a `bitcoind` full node to recover the funds locked
in those private keys.
* `bitcoin-cli-watchonly`: Does the same as `bitcoin-cli` but with the
`bitcoin-cli importpubkey` command. That means, only the public keys are
imported into `bitcoind` to watch the UTXOs of those keys. The funds cannot be
spent that way as they are watch-only.
2020-02-02 18:56:05 +00:00
* `bitcoin-importwallet`: Creates a text output that is compatible with
`bitcoind`'s `importwallet command.
2020-02-02 16:43:30 +00:00
Example command:
```bash
chantools genimportscript --format bitcoin-cli --recoverywindow 5000
```
2020-01-04 11:19:42 +00:00
### rescueclosed
2019-12-07 14:21:08 +00:00
```text
Usage:
2020-01-04 11:19:42 +00:00
chantools [OPTIONS] rescueclosed [rescueclosed-OPTIONS]
2019-12-07 14:21:08 +00:00
2020-01-04 11:19:42 +00:00
[rescueclosed command options]
--rootkey= BIP32 HD root key to use. Leave empty to prompt for lnd 24 word aezeed.
2020-01-04 11:19:42 +00:00
--channeldb= The lnd channel.db file to use for rescuing force-closed channels.
2019-12-07 14:21:08 +00:00
```
2020-01-04 11:19:42 +00:00
If channels have already been force-closed by the remote peer, this command
tries to find the private keys to sweep the funds from the output that belongs
to our side. This can only be used if we have a channel DB that contains the
latest commit point. Normally you would use SCB to get the funds from those
channels. But this method can help if the other node doesn't know about the
channels any more but we still have the channel.db from the moment they
force-closed.
2019-12-07 14:21:08 +00:00
Example command:
```bash
2020-01-04 11:19:42 +00:00
chantools --fromsummary results/summary-xxxx-yyyy.json \
rescueclosed \
--channeldb ~/.lnd/data/graph/mainnet/channel.db \
--rootkey xprvxxxxxxxxxx
2019-12-07 14:21:08 +00:00
```
2019-12-28 15:04:36 +00:00
### rescuefunding
```text
Usage:
chantools [OPTIONS] rescuefunding [rescuefunding-OPTIONS]
[rescuefunding command options]
--rootkey= BIP32 HD root (m/) key to derive the key for our node from.
--othernodepub= The extended public key (xpub) of the other node's multisig branch (m/1017'/<coin_type>'/0'/0).
--fundingaddr= The bech32 script address of the funding output where the coins to be spent are locked in.
--fundingoutpoint= The funding transaction outpoint (<txid>:<txindex>).
--fundingamount= The exact amount in satoshis that is locked in the funding output.
--sweepaddr= The address to sweep the rescued funds to.
--satperbyte= The fee rate to use in satoshis/vByte.
```
**This command is not fully implemented yet and only listed here as a placeholder.**
2020-01-04 11:19:42 +00:00
### showrootkey
2020-02-02 18:56:05 +00:00
This command converts the 24 word `lnd` aezeed phrase and password to the BIP32
2020-01-04 11:19:42 +00:00
HD root key that is used as the `rootkey` parameter in other commands of this
tool.
Example command:
```bash
chantools showrootkey
```
### summary
2019-12-28 15:04:36 +00:00
```text
Usage:
2020-01-04 11:19:42 +00:00
chantools [OPTIONS] summary
2019-12-28 15:04:36 +00:00
```
2020-01-04 11:19:42 +00:00
From a list of channels, find out what their state is by querying the funding
transaction on a block explorer API.
2019-12-28 15:04:36 +00:00
2020-01-04 11:19:42 +00:00
Example command 1:
2019-12-28 15:04:36 +00:00
```bash
2020-01-04 11:19:42 +00:00
lncli listchannels | chantools --listchannels - summary
2019-12-28 15:04:36 +00:00
```
2020-01-03 10:30:18 +00:00
2020-01-04 11:19:42 +00:00
Example command 2:
2020-01-03 10:30:18 +00:00
```bash
2020-01-04 11:19:42 +00:00
chantools --fromchanneldb ~/.lnd/data/graph/mainnet/channel.db
2020-01-03 10:30:18 +00:00
```
2020-01-04 11:19:42 +00:00
### sweeptimelock
2020-01-03 10:30:18 +00:00
```text
Usage:
2020-01-04 11:19:42 +00:00
chantools [OPTIONS] sweeptimelock [sweeptimelock-OPTIONS]
2020-01-03 10:30:18 +00:00
2020-01-04 11:19:42 +00:00
[sweeptimelock command options]
--rootkey= BIP32 HD root key to use. Leave empty to prompt for lnd 24 word aezeed.
2020-01-04 11:19:42 +00:00
--publish Should the sweep TX be published to the chain API?
--sweepaddr= The address the funds should be sweeped to
--maxcsvlimit= Maximum CSV limit to use. (default 2000)
2020-01-03 10:30:18 +00:00
```
2020-01-04 11:19:42 +00:00
Use this command to sweep the funds from channels that you force-closed with the
`forceclose` command. You **MUST** use the result file that was created with the
`forceclose` command, otherwise it won't work. You also have to wait until the
highest time lock (can be up to 2000 blocks which is more than two weeks) of all
the channels has passed. If you only want to sweep channels that have the
default CSV limit of 1 day, you can set the `--maxcsvlimit` parameter to 144.
2020-01-03 10:30:18 +00:00
Example command:
```bash
2020-01-04 11:19:42 +00:00
chantools --fromsummary results/forceclose-xxxx-yyyy.json \
sweeptimelock
--rootkey xprvxxxxxxxxxx \
--publish \
--sweepaddr bc1q.....
```
2020-02-02 18:56:05 +00:00
### walletinfo
```text
Usage:
chantools [OPTIONS] walletinfo [walletinfo-OPTIONS]
[walletinfo command options]
--walletdb= The lnd wallet.db file to dump the contents from.
--withrootkey Should the BIP32 HD root key of the wallet be printed to standard out?
```
Shows some basic information about an `lnd` `wallet.db` file, like the node
identity the wallet belongs to, how many on-chain addresses are used and, if
enabled with `--withrootkey` the BIP32 HD root key of the wallet. The latter can
be useful to recover funds from a wallet if the wallet password is still known
but the seed was lost. **The 24 word seed phrase itself cannot be extracted**
because it is hashed into the extended HD root key before storing it in the
`wallet.db`.
Example command:
```bash
chantools walletinfo \
--walletdb ~/.lnd/data/chain/bitcoin/mainnet/wallet.db \
--withrootkey
```