-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd+doc: add new dropchannelgraph command
- Loading branch information
Showing
5 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|