cmd: add migratedb command

pull/17/head
Oliver Gugger 3 years ago
parent fa62a57e95
commit 729e71f751
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

@ -241,6 +241,10 @@ Your BIP32 HD root key is: xprv9s21ZrQH1...
## Command overview
```text
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/.
Usage:
chantools [command]
@ -255,6 +259,7 @@ Available Commands:
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
help Help about any command
migratedb Apply all recent lnd channel database migrations
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
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
@ -288,6 +293,7 @@ Quick access:
+ [filterbackup](doc/chantools_filterbackup.md)
+ [fixoldbackup](doc/chantools_fixoldbackup.md)
+ [genimportscript](doc/chantools_genimportscript.md)
+ [migratedb](doc/chantools_migratedb.md)
+ [forceclose](doc/chantools_forceclose.md)
+ [removechannel](doc/chantools_removechannel.md)
+ [rescueclosed](doc/chantools_rescueclosed.md)

@ -0,0 +1,52 @@
package main
import (
"fmt"
"github.com/guggero/chantools/lnd"
"github.com/spf13/cobra"
)
type migrateDBCommand struct {
ChannelDB string
cmd *cobra.Command
}
func newMigrateDBCommand() *cobra.Command {
cc := &migrateDBCommand{}
cc.cmd = &cobra.Command{
Use: "migratedb",
Short: "Apply all recent lnd channel database migrations",
Long: `This command opens an lnd channel database in write mode
and applies all recent database migrations to it. This can be used to update
an old database file to be compatible with the current version that chantools
needs to read the database content.
CAUTION: Running this command will make it impossible to use the channel DB
with an older version of lnd. Downgrading is not possible and you'll need to
run lnd v0.12.0-beta or later after using this command!'`,
Example: `chantools migratedb \
--channeldb ~/.lnd/data/graph/mainnet/channel.db`,
RunE: cc.Execute,
}
cc.cmd.Flags().StringVar(
&cc.ChannelDB, "channeldb", "", "lnd channel.db file to "+
"migrate",
)
return cc.cmd
}
func (c *migrateDBCommand) Execute(_ *cobra.Command, _ []string) error {
// Check that we have a channel DB.
if c.ChannelDB == "" {
return fmt.Errorf("channel DB is required")
}
db, err := lnd.OpenDB(c.ChannelDB, false)
if err != nil {
return fmt.Errorf("error opening DB: %v", err)
}
return db.Close()
}

@ -24,7 +24,16 @@ func newRemoveChannelCommand() *cobra.Command {
cc.cmd = &cobra.Command{
Use: "removechannel",
Short: "Remove a single channel from the given channel DB",
Example: `chantools --channeldb ~/.lnd/data/graph/mainnet/channel.db \
Long: `Opens the given channel DB in write mode and removes one
single channel from it. This means giving up on any state (and therefore coins)
of that channel and should only be used if the funding transaction of the
channel was never confirmed on chain!
CAUTION: Running this command will make it impossible to use the channel DB
with an older version of lnd. Downgrading is not possible and you'll need to
run lnd v0.12.0-beta or later after using this command!`,
Example: `chantools removechannel \
--channeldb ~/.lnd/data/graph/mainnet/channel.db \
--channel 3149764effbe82718b280de425277e5e7b245a4573aa4a0203ac12cee1c37816:0`,
RunE: cc.Execute,
}

@ -26,7 +26,7 @@ import (
const (
defaultAPIURL = "https://blockstream.info/api"
version = "0.7.1"
version = "0.8.0"
Commit = ""
)
@ -88,6 +88,7 @@ func init() {
newFixOldBackupCommand(),
newForceCloseCommand(),
newGenImportScriptCommand(),
newMigrateDBCommand(),
newRemoveChannelCommand(),
newRescueClosedCommand(),
newRescueFundingCommand(),
@ -146,7 +147,7 @@ func (r *rootKey) readWithBirthday() (*hdkeychain.ExtendedKey, time.Time,
case r.BIP39:
extendedKey, err := btc.ReadMnemonicFromTerminal(chainParams)
return extendedKey, time.Unix(0, 0), err
default:
return lnd.ReadAezeed(chainParams)
}

@ -27,6 +27,7 @@ Complete documentation is available at https://github.com/guggero/chantools/.
* [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 migratedb](chantools_migratedb.md) - Apply all recent lnd channel database migrations
* [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

@ -0,0 +1,44 @@
## chantools migratedb
Apply all recent lnd channel database migrations
### Synopsis
This command opens an lnd channel database in write mode
and applies all recent database migrations to it. This can be used to update
an old database file to be compatible with the current version that chantools
needs to read the database content.
CAUTION: Running this command will make it impossible to use the channel DB
with an older version of lnd. Downgrading is not possible and you'll need to
run lnd v0.12.0-beta or later after using this command!'
```
chantools migratedb [flags]
```
### Examples
```
chantools migratedb \
--channeldb ~/.lnd/data/graph/mainnet/channel.db
```
### Options
```
--channeldb string lnd channel.db file to migrate
-h, --help help for migratedb
```
### 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

@ -2,6 +2,17 @@
Remove a single channel from the given channel DB
### Synopsis
Opens the given channel DB in write mode and removes one
single channel from it. This means giving up on any state (and therefore coins)
of that channel and should only be used if the funding transaction of the
channel was never confirmed on chain!
CAUTION: Running this command will make it impossible to use the channel DB
with an older version of lnd. Downgrading is not possible and you'll need to
run lnd v0.12.0-beta or later after using this command!
```
chantools removechannel [flags]
```
@ -9,7 +20,8 @@ chantools removechannel [flags]
### Examples
```
chantools --channeldb ~/.lnd/data/graph/mainnet/channel.db \
chantools removechannel \
--channeldb ~/.lnd/data/graph/mainnet/channel.db \
--channel 3149764effbe82718b280de425277e5e7b245a4573aa4a0203ac12cee1c37816:0
```

@ -22,6 +22,6 @@ require (
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899
)
replace github.com/lightningnetwork/lnd => github.com/guggero/lnd v0.11.1-beta.rc5.0.20201214225837-5a6d8ff78da4
replace github.com/lightningnetwork/lnd => github.com/guggero/lnd v0.11.0-beta.rc4.0.20210101121045-2ae6e51765fe
go 1.13

@ -306,6 +306,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.14.3 h1:OCJlWkOUoTnl0neNGlf4fUm3TmbEtguw7vR+nGtnDjY=
github.com/grpc-ecosystem/grpc-gateway v1.14.3/go.mod h1:6CwZWGDSPRJidgKAtJVvND6soZe6fT7iteq8wDPdhb0=
github.com/guggero/lnd v0.11.0-beta.rc4.0.20210101121045-2ae6e51765fe h1:jALvgjIGF31xvEInOdMZgyM3BdwkLlUUHdz6H11cWp8=
github.com/guggero/lnd v0.11.0-beta.rc4.0.20210101121045-2ae6e51765fe/go.mod h1:2GyP1IG1kXV5Af/LOCxnXfux1OP3fAGr8zptS5PB2YI=
github.com/guggero/lnd v0.11.1-beta.rc5.0.20201214225837-5a6d8ff78da4 h1:jdsGb7+DPYJnMTx6/HmOVbUFXWls39ZhsasrLRbMyJY=
github.com/guggero/lnd v0.11.1-beta.rc5.0.20201214225837-5a6d8ff78da4/go.mod h1:PGIgxy8aH70Li33YVYkHSaCM8m8LjEevk5h1Dpldrr4=
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
@ -397,10 +399,13 @@ github.com/lightninglabs/neutrino v0.11.0 h1:lPpYFCtsfJX2W5zI4pWycPmbbBdr7zU+Baf
github.com/lightninglabs/neutrino v0.11.0/go.mod h1:CuhF0iuzg9Sp2HO6ZgXgayviFTn1QHdSTJlMncK80wg=
github.com/lightninglabs/neutrino v0.11.1-0.20200316235139-bffc52e8f200 h1:j4iZ1XlUAPQmW6oSzMcJGILYsRHNs+4O3Gk+2Ms5Dww=
github.com/lightninglabs/neutrino v0.11.1-0.20200316235139-bffc52e8f200/go.mod h1:MlZmoKa7CJP3eR1s5yB7Rm5aSyadpKkxqAwLQmog7N0=
github.com/lightninglabs/neutrino v0.11.1-0.20201210023533-e1978372d15e h1:K5LCCnSAk3NVT/aCy8wNPv0I5JfyLgijg1VX8Gz306E=
github.com/lightninglabs/neutrino v0.11.1-0.20201210023533-e1978372d15e/go.mod h1:KDWfQDKp+CFBxO1t2NRmWuagTY2sYIjpHB1k5vrojTI=
github.com/lightninglabs/protobuf-hex-display v1.3.3-0.20191212020323-b444784ce75d/go.mod h1:KDb67YMzoh4eudnzClmvs2FbiLG9vxISmLApUkCa4uI=
github.com/lightningnetwork/lightning-onion v1.0.2-0.20200501022730-3c8c8d0b89ea h1:oCj48NQ8u7Vz+MmzHqt0db6mxcFZo3Ho7M5gCJauY/k=
github.com/lightningnetwork/lightning-onion v1.0.2-0.20200501022730-3c8c8d0b89ea/go.mod h1:rigfi6Af/KqsF7Za0hOgcyq2PNH4AN70AaMRxcJkff4=
github.com/lightningnetwork/lnd/cert v1.0.2/go.mod h1:fmtemlSMf5t4hsQmcprSoOykypAPp+9c+0d0iqTScMo=
github.com/lightningnetwork/lnd/cert v1.0.3/go.mod h1:3MWXVLLPI0Mg0XETm9fT4N9Vyy/8qQLmaM5589bEggM=
github.com/lightningnetwork/lnd/clock v1.0.1 h1:QQod8+m3KgqHdvVMV+2DRNNZS1GRFir8mHZYA+Z2hFo=
github.com/lightningnetwork/lnd/clock v1.0.1/go.mod h1:KnQudQ6w0IAMZi1SgvecLZQZ43ra2vpDNj7H/aasemg=
github.com/lightningnetwork/lnd/queue v1.0.1 h1:jzJKcTy3Nj5lQrooJ3aaw9Lau3I0IwvQR5sqtjdv2R0=

Loading…
Cancel
Save