Skip to content

Commit b07c7b2

Browse files
committed
cmd+doc: add new dropchannelgraph command
1 parent 959dcf3 commit b07c7b2

File tree

5 files changed

+114
-1
lines changed

5 files changed

+114
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ Quick access:
288288
+ [chanbackup](doc/chantools_chanbackup.md)
289289
+ [compactdb](doc/chantools_compactdb.md)
290290
+ [derivekey](doc/chantools_derivekey.md)
291+
+ [dropchannelgraph](chantools_dropchannelgraph.md)
291292
+ [dumpbackup](doc/chantools_dumpbackup.md)
292293
+ [dumpchannels](doc/chantools_dumpchannels.md)
293294
+ [filterbackup](doc/chantools_filterbackup.md)

cmd/chantools/dropchannelgraph.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/guggero/chantools/lnd"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var (
11+
nodeBucket = []byte("graph-node")
12+
edgeBucket = []byte("graph-edge")
13+
graphMetaBucket = []byte("graph-meta")
14+
)
15+
16+
type dropChannelGraphCommand struct {
17+
ChannelDB string
18+
19+
cmd *cobra.Command
20+
}
21+
22+
func newDropChannelGraphCommand() *cobra.Command {
23+
cc := &dropChannelGraphCommand{}
24+
cc.cmd = &cobra.Command{
25+
Use: "dropchannelgraph",
26+
Short: "Remove all graph related data from a channel DB",
27+
Long: `This command removes all graph data from a channel DB,
28+
forcing the lnd node to do a full graph sync.
29+
30+
CAUTION: Running this command will make it impossible to use the channel DB
31+
with an older version of lnd. Downgrading is not possible and you'll need to
32+
run lnd v0.12.0-beta or later after using this command!'`,
33+
Example: `chantools dropchannelgraph \
34+
--channeldb ~/.lnd/data/graph/mainnet/channel.db`,
35+
RunE: cc.Execute,
36+
}
37+
cc.cmd.Flags().StringVar(
38+
&cc.ChannelDB, "channeldb", "", "lnd channel.db file to dump "+
39+
"channels from",
40+
)
41+
42+
return cc.cmd
43+
}
44+
45+
func (c *dropChannelGraphCommand) Execute(_ *cobra.Command, _ []string) error {
46+
// Check that we have a channel DB.
47+
if c.ChannelDB == "" {
48+
return fmt.Errorf("channel DB is required")
49+
}
50+
db, err := lnd.OpenDB(c.ChannelDB, false)
51+
if err != nil {
52+
return fmt.Errorf("error opening rescue DB: %v", err)
53+
}
54+
defer func() { _ = db.Close() }()
55+
56+
rwTx, err := db.BeginReadWriteTx()
57+
if err != nil {
58+
return err
59+
}
60+
61+
if err := rwTx.DeleteTopLevelBucket(nodeBucket); err != nil {
62+
return err
63+
}
64+
if err := rwTx.DeleteTopLevelBucket(edgeBucket); err != nil {
65+
return err
66+
}
67+
if err := rwTx.DeleteTopLevelBucket(graphMetaBucket); err != nil {
68+
return err
69+
}
70+
71+
return rwTx.Commit()
72+
}

cmd/chantools/root.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
const (
2828
defaultAPIURL = "https://blockstream.info/api"
29-
version = "0.8.0"
29+
version = "0.8.1"
3030
na = "n/a"
3131

3232
Commit = ""
@@ -82,6 +82,7 @@ func main() {
8282
newChanBackupCommand(),
8383
newCompactDBCommand(),
8484
newDeriveKeyCommand(),
85+
newDropChannelGraphCommand(),
8586
newDumpBackupCommand(),
8687
newDumpChannelsCommand(),
8788
newDocCommand(),

doc/chantools.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Complete documentation is available at https://github.com/guggero/chantools/.
2121
* [chantools chanbackup](chantools_chanbackup.md) - Create a channel.backup file from a channel database
2222
* [chantools compactdb](chantools_compactdb.md) - Create a copy of a channel.db file in safe/read-only mode
2323
* [chantools derivekey](chantools_derivekey.md) - Derive a key with a specific derivation path
24+
* [chantools dropchannelgraph](chantools_dropchannelgraph.md) - Remove all graph related data from a channel DB
2425
* [chantools dumpbackup](chantools_dumpbackup.md) - Dump the content of a channel.backup file
2526
* [chantools dumpchannels](chantools_dumpchannels.md) - Dump all channel information from an lnd channel database
2627
* [chantools filterbackup](chantools_filterbackup.md) - Filter an lnd channel.backup file and remove certain channels

doc/chantools_dropchannelgraph.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## chantools dropchannelgraph
2+
3+
Remove all graph related data from a channel DB
4+
5+
### Synopsis
6+
7+
This command removes all graph data from a channel DB,
8+
forcing the lnd node to do a full graph sync.
9+
10+
```
11+
chantools dropchannelgraph [flags]
12+
```
13+
14+
### Examples
15+
16+
```
17+
chantools dropchannelgraph \
18+
--channeldb ~/.lnd/data/graph/mainnet/channel.db
19+
```
20+
21+
### Options
22+
23+
```
24+
--channeldb string lnd channel.db file to dump channels from
25+
-h, --help help for dropchannelgraph
26+
```
27+
28+
### Options inherited from parent commands
29+
30+
```
31+
-r, --regtest Indicates if regtest parameters should be used
32+
-t, --testnet Indicates if testnet parameters should be used
33+
```
34+
35+
### SEE ALSO
36+
37+
* [chantools](chantools.md) - Chantools helps recover funds from lightning channels
38+

0 commit comments

Comments
 (0)