Skip to content

Commit

Permalink
cmd+doc: add new dropchannelgraph command
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Jan 5, 2021
1 parent 959dcf3 commit b07c7b2
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ Quick access:
+ [chanbackup](doc/chantools_chanbackup.md)
+ [compactdb](doc/chantools_compactdb.md)
+ [derivekey](doc/chantools_derivekey.md)
+ [dropchannelgraph](chantools_dropchannelgraph.md)
+ [dumpbackup](doc/chantools_dumpbackup.md)
+ [dumpchannels](doc/chantools_dumpchannels.md)
+ [filterbackup](doc/chantools_filterbackup.md)
Expand Down
72 changes: 72 additions & 0 deletions cmd/chantools/dropchannelgraph.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package main

import (
"fmt"

"github.com/guggero/chantools/lnd"
"github.com/spf13/cobra"
)

var (
nodeBucket = []byte("graph-node")
edgeBucket = []byte("graph-edge")
graphMetaBucket = []byte("graph-meta")
)

type dropChannelGraphCommand struct {
ChannelDB string

cmd *cobra.Command
}

func newDropChannelGraphCommand() *cobra.Command {
cc := &dropChannelGraphCommand{}
cc.cmd = &cobra.Command{
Use: "dropchannelgraph",
Short: "Remove all graph related data from a channel DB",
Long: `This command removes all graph data from a channel DB,
forcing the lnd node to do a full graph sync.
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 dropchannelgraph \
--channeldb ~/.lnd/data/graph/mainnet/channel.db`,
RunE: cc.Execute,
}
cc.cmd.Flags().StringVar(
&cc.ChannelDB, "channeldb", "", "lnd channel.db file to dump "+
"channels from",
)

return cc.cmd
}

func (c *dropChannelGraphCommand) 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 rescue DB: %v", err)
}
defer func() { _ = db.Close() }()

rwTx, err := db.BeginReadWriteTx()
if err != nil {
return err
}

if err := rwTx.DeleteTopLevelBucket(nodeBucket); err != nil {
return err
}
if err := rwTx.DeleteTopLevelBucket(edgeBucket); err != nil {
return err
}
if err := rwTx.DeleteTopLevelBucket(graphMetaBucket); err != nil {
return err
}

return rwTx.Commit()
}
3 changes: 2 additions & 1 deletion cmd/chantools/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

const (
defaultAPIURL = "https://blockstream.info/api"
version = "0.8.0"
version = "0.8.1"
na = "n/a"

Commit = ""
Expand Down Expand Up @@ -82,6 +82,7 @@ func main() {
newChanBackupCommand(),
newCompactDBCommand(),
newDeriveKeyCommand(),
newDropChannelGraphCommand(),
newDumpBackupCommand(),
newDumpChannelsCommand(),
newDocCommand(),
Expand Down
1 change: 1 addition & 0 deletions doc/chantools.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Complete documentation is available at https://github.com/guggero/chantools/.
* [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 dropchannelgraph](chantools_dropchannelgraph.md) - Remove all graph related data from a channel DB
* [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
Expand Down
38 changes: 38 additions & 0 deletions doc/chantools_dropchannelgraph.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## chantools dropchannelgraph

Remove all graph related data from a channel DB

### Synopsis

This command removes all graph data from a channel DB,
forcing the lnd node to do a full graph sync.

```
chantools dropchannelgraph [flags]
```

### Examples

```
chantools dropchannelgraph \
--channeldb ~/.lnd/data/graph/mainnet/channel.db
```

### Options

```
--channeldb string lnd channel.db file to dump channels from
-h, --help help for dropchannelgraph
```

### 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

0 comments on commit b07c7b2

Please sign in to comment.