* [Seed and passphrase input](#seed-and-passphrase-input)
* [Seed and passphrase input](#seed-and-passphrase-input)
* [Command overview](#command-overview)
* [Command overview](#command-overview)
* [Commands](#commands)
* [Commands](#commands)
+ [chanbackup](#chanbackup)
+ [compactdb](#compactdb)
+ [derivekey](#derivekey)
+ [dumpbackup](#dumpbackup)
+ [dumpchannels](#dumpchannels)
+ [filterbackup](#filterbackup)
+ [fixoldbackup](#fixoldbackup)
+ [genimportscript](#genimportscript)
+ [forceclose](#forceclose)
+ [removechannel](#removechannel)
+ [rescueclosed](#rescueclosed)
+ [rescuefunding](#rescuefunding)
+ [showrootkey](#showrootkey)
+ [signrescuefunding](#signrescuefunding)
+ [summary](#summary)
+ [sweeptimelock](#sweeptimelock)
+ [sweeptimelockmanual](#sweeptimelockmanual)
+ [vanitygen](#vanitygen)
+ [walletinfo](#walletinfo)
This tool provides helper functions that can be used to rescue funds locked in
This tool provides helper functions that can be used to rescue funds locked in
`lnd` channels in case `lnd` itself cannot run properly anymore.
`lnd` channels in case `lnd` itself cannot run properly anymore.
@ -83,7 +64,7 @@ file based backup or the recovered file from the crashed node).
[this](https://github.com/lightningnetwork/lnd/issues/3473) or
[this](https://github.com/lightningnetwork/lnd/issues/3473) or
[this](https://github.com/lightningnetwork/lnd/issues/4102), it is possible
[this](https://github.com/lightningnetwork/lnd/issues/4102), it is possible
that a simple compaction (a full copy in safe mode) can solve your problem.
that a simple compaction (a full copy in safe mode) can solve your problem.
See [`chantools compactdb`](#compactdb).
See [`chantools compactdb`](doc/chantools_compactdb.md).
<br/><br/>
<br/><br/>
If that doesn't work and you need to continue the recovery, make sure you can
If that doesn't work and you need to continue the recovery, make sure you can
at least extract the `channel.backup` file and if somehow possible any version
at least extract the `channel.backup` file and if somehow possible any version
@ -164,7 +145,7 @@ file based backup or the recovered file from the crashed node).
`chantools` thinks are still open. This is achieved by publishing the latest
`chantools` thinks are still open. This is achieved by publishing the latest
known channel state of the `channel.db` file.
known channel state of the `channel.db` file.
<br/>**Please read the full warning text of the
<br/>**Please read the full warning text of the
[`forceclose` command below](#forceclose) as this command can put
[`forceclose` command below](doc/chantools_forceclose.md) as this command can put
your funds at risk** if the state in the channel DB is not the most recent
your funds at risk** if the state in the channel DB is not the most recent
one. This command should only be executed for channels where the remote peer
one. This command should only be executed for channels where the remote peer
is not online anymore.
is not online anymore.
@ -261,537 +242,60 @@ Your BIP32 HD root key is: xprv9s21ZrQH1...
```text
```text
Usage:
Usage:
chantools [OPTIONS] <command>
chantools [command]
Application Options:
Available Commands:
--testnet Set to true if testnet parameters should be used.
chanbackup Create a channel.backup file from a channel database
--apiurl= API URL to use (must be esplora compatible). (default: https://blockstream.info/api)
compactdb Create a copy of a channel.db file in safe/read-only mode
--listchannels= The channel input is in the format of lncli's listchannels format. Specify '-' to read from stdin.
derivekey Derive a key with a specific derivation path
--pendingchannels= The channel input is in the format of lncli's pendingchannels format. Specify '-' to read from stdin.
dumpbackup Dump the content of a channel.backup file
--fromsummary= The channel input is in the format of this tool's channel summary. Specify '-' to read from stdin.
dumpchannels Dump all channel information from an lnd channel database
--fromchanneldb= The channel input is in the format of an lnd channel.db file.
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)
Help Options:
forceclose Force-close the last state that is in the channel.db provided
-h, --help Show this help message
genimportscript Generate a script containing the on-chain keys of an lnd wallet that can be imported into other software like bitcoind
help Help about any command
Available commands:
removechannel Remove a single channel from the given channel DB
chanbackup Create a channel.backup file from a channel database.
rescueclosed Try finding the private keys for funds that are in outputs of remotely force-closed channels
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.
rescuefunding Rescue funds locked in a funding multisig output that never resulted in a proper channel; this is the command the initiator of the channel needs to run
derivekey Derive a key with a specific derivation path from the BIP32 HD root key.
showrootkey Extract and show the BIP32 HD root key from the 24 word lnd aezeed
dumpbackup Dump the content of a channel.backup file.
signrescuefunding Rescue funds locked in a funding multisig output that never resulted in a proper channel; this is the command the remote node (the non-initiator) of the channel needs to run
dumpchannels Dump all channel information from lnd's channel database.
summary Compile a summary about the current state of channels
filterbackup Filter an lnd channel.backup file and remove certain channels.
sweeptimelock Sweep the force-closed state after the time lock has expired
fixoldbackup Fixes an old channel.backup file that is affected by the lnd issue #3881 (unable to derive shachain root key).
sweeptimelockmanual Sweep the force-closed state of a single channel manually if only a channel backup file is available
forceclose Force-close the last state that is in the channel.db provided.
vanitygen Generate a seed with a custom lnd node identity public key that starts with the given prefix
genimportscript Generate a script containing the on-chain keys of an lnd wallet that can be imported into other software like bitcoind.
walletinfo Shows info about an lnd wallet.db file and optionally extracts the BIP32 HD root key
removechannel Remove a single channel from the given channel DB.
rescueclosed Try finding the private keys for funds that are in outputs of remotely force-closed channels.
Flags:
rescuefunding Rescue funds locked in a funding multisig output that never resulted in a proper channel. This is the command the initiator of the channel needs to run.
-h, --help help for chantools
showrootkey Extract and show the BIP32 HD root key from the 24 word lnd aezeed.
-r, --regtest Indicates if regtest parameters should be used
signrescuefunding Rescue funds locked in a funding multisig output that never resulted in a proper channel. This is the command the remote node (the non-initiator) of the channel needs to run.
-t, --testnet Indicates if testnet parameters should be used
summary Compile a summary about the current state of channels.
sweeptimelock Sweep the force-closed state after the time lock has expired.
Use "chantools [command] --help" for more information about a command.
sweeptimelockmanual Sweep the force-closed state of a single channel manually if only a channel backup file is available
vanitygen Generate a seed with a custom lnd node identity public key that starts with the given prefix.
walletinfo Shows relevant information about an lnd wallet.db file and optionally extracts the BIP32 HD root key.
```
```
## Commands
## Commands
### chanbackup
Detailed documentation for each sub command is available in the
--rootkey= BIP32 HD root key to use. Leave empty to prompt for lnd 24 word aezeed.
--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')
--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
from an `lnd` 24 word aezeed wallet. That script can then be imported into other
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.
* `bitcoin-importwallet`: Creates a text output that is compatible with
--rootkey= BIP32 HD root key to use. Leave empty to prompt for lnd 24 word aezeed.
--channeldb= The lnd channel.db file to rescue a channel from. Must contain the pending channel specified with --channelpoint.
--channelpoint= The funding transaction outpoint of the channel to rescue (<txid>:<txindex>) as it is recorded in the DB.
--confirmedchannelpoint= The channel outpoint that got confirmed on chain (<txid>:<txindex>). Normally this is the same as the --channelpoint so it will be set to that value if this is left empty.
--sweepaddr= The address to sweep the rescued funds to.
--satperbyte= The fee rate to use in satoshis/vByte.
```
This is part 1 of a two phase process to rescue a channel funding output that
was created on chain by accident but never resulted in a proper channel and no
commitment transactions exist to spend the funds locked in the 2-of-2 multisig.
**You need the cooperation of the channel partner (remote node) for this to
work**! They need to run the second command of this process:
[`signrescuefunding`](#signrescuefunding)
Example command (run against the channel DB of the initiator node):
Chantools helps recover funds from lightning channels
### Synopsis
This tool provides helper functions that can be used rescue
funds locked in lnd channels in case lnd itself cannot run
properly anymore.
Complete documentation is available at https://github.com/guggero/chantools/.
### Options
```
-h, --help help for chantools
-r, --regtest Indicates if regtest parameters should be used
-t, --testnet Indicates if testnet parameters should be used
```
### SEE ALSO
* [chantools chanbackup](chantools_chanbackup.md) - Create a channel.backup file from a channel database
* [chantools compactdb](chantools_compactdb.md) - Create a copy of a channel.db file in safe/read-only mode
* [chantools derivekey](chantools_derivekey.md) - Derive a key with a specific derivation path
* [chantools dumpbackup](chantools_dumpbackup.md) - Dump the content of a channel.backup file
* [chantools dumpchannels](chantools_dumpchannels.md) - Dump all channel information from an lnd channel database
* [chantools filterbackup](chantools_filterbackup.md) - Filter an lnd channel.backup file and remove certain channels
* [chantools fixoldbackup](chantools_fixoldbackup.md) - Fixes an old channel.backup file that is affected by the lnd issue #3881 (unable to derive shachain root key)
* [chantools forceclose](chantools_forceclose.md) - Force-close the last state that is in the channel.db provided
* [chantools genimportscript](chantools_genimportscript.md) - Generate a script containing the on-chain keys of an lnd wallet that can be imported into other software like bitcoind
* [chantools removechannel](chantools_removechannel.md) - Remove a single channel from the given channel DB
* [chantools rescueclosed](chantools_rescueclosed.md) - Try finding the private keys for funds that are in outputs of remotely force-closed channels
* [chantools rescuefunding](chantools_rescuefunding.md) - Rescue funds locked in a funding multisig output that never resulted in a proper channel; this is the command the initiator of the channel needs to run
* [chantools showrootkey](chantools_showrootkey.md) - Extract and show the BIP32 HD root key from the 24 word lnd aezeed
* [chantools signrescuefunding](chantools_signrescuefunding.md) - Rescue funds locked in a funding multisig output that never resulted in a proper channel; this is the command the remote node (the non-initiator) of the channel needs to run
* [chantools summary](chantools_summary.md) - Compile a summary about the current state of channels
* [chantools sweeptimelock](chantools_sweeptimelock.md) - Sweep the force-closed state after the time lock has expired
* [chantools sweeptimelockmanual](chantools_sweeptimelockmanual.md) - Sweep the force-closed state of a single channel manually if only a channel backup file is available
* [chantools vanitygen](chantools_vanitygen.md) - Generate a seed with a custom lnd node identity public key that starts with the given prefix
* [chantools walletinfo](chantools_walletinfo.md) - Shows info about an lnd wallet.db file and optionally extracts the BIP32 HD root key
Generate a script containing the on-chain keys of an lnd wallet that can be imported into other software like bitcoind
```
chantools genimportscript [flags]
```
### Options
```
--bip39 read a classic BIP39 seed and passphrase from the terminal instead of asking for lnd seed format or providing the --rootkey flag
--derivationpath string 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
--format string format of the generated import script; currently supported are: bitcoin-importwallet, bitcoin-cli and bitcoin-cli-watchonly (default "bitcoin-importwallet")
-h, --help help for genimportscript
--lndpaths use all derivation paths that lnd used; results in a large number of results; cannot be used in conjunction with --derivationpath
--recoverywindow uint32 number of keys to scan per internal/external branch; output will consist of double this amount of keys (default 2500)
--rescanfrom uint32 block number to rescan from; will be set automatically from the wallet birthday if the lnd 24 word aezeed is entered (default 500000)
--rootkey string BIP32 HD root key of the wallet to use for decrypting the backup; leave empty to prompt for lnd 24 word aezeed
```
### Options inherited from parent commands
```
-r, --regtest Indicates if regtest parameters should be used
-t, --testnet Indicates if testnet parameters should be used
```
### SEE ALSO
* [chantools](chantools.md) - Chantools helps recover funds from lightning channels
Rescue funds locked in a funding multisig output that never resulted in a proper channel; this is the command the initiator of the channel needs to run
```
chantools rescuefunding [flags]
```
### Options
```
--bip39 read a classic BIP39 seed and passphrase from the terminal instead of asking for lnd seed format or providing the --rootkey flag
--channeldb string lnd channel.db file to rescue a channel from; must contain the pending channel specified with --channelpoint
--channelpoint string funding transaction outpoint of the channel to rescue (<txid>:<txindex>) as it is recorded in the DB
--confirmedchannelpoint string channel outpoint that got confirmed on chain (<txid>:<txindex>); normally this is the same as the --channelpoint so it will be set to that value ifthis is left empty
--feerate uint16 fee rate to use for the sweep transaction in sat/vByte (default 2)
-h, --help help for rescuefunding
--rootkey string BIP32 HD root key of the wallet to use for deriving keys; leave empty to prompt for lnd 24 word aezeed
--sweepaddr string address to sweep the funds to
```
### Options inherited from parent commands
```
-r, --regtest Indicates if regtest parameters should be used
-t, --testnet Indicates if testnet parameters should be used
```
### SEE ALSO
* [chantools](chantools.md) - Chantools helps recover funds from lightning channels
Rescue funds locked in a funding multisig output that never resulted in a proper channel; this is the command the remote node (the non-initiator) of the channel needs to run
```
chantools signrescuefunding [flags]
```
### Options
```
-h, --help help for signrescuefunding
--psbt string Partially Signed Bitcoin Transaction that was provided by the initiator of the channel to rescue
```
### Options inherited from parent commands
```
-r, --regtest Indicates if regtest parameters should be used
-t, --testnet Indicates if testnet parameters should be used
```
### SEE ALSO
* [chantools](chantools.md) - Chantools helps recover funds from lightning channels