mirror of
https://github.com/guggero/chantools
synced 2024-11-11 01:10:42 +00:00
multi: add new dropgraphzombies command
This commit is contained in:
parent
909163b260
commit
f191d1bb91
@ -414,6 +414,7 @@ Available Commands:
|
||||
derivekey Derive a key with a specific derivation path
|
||||
doublespendinputs Tries to double spend the given inputs by deriving the private for the address and sweeping the funds to the given address. This can only be used with inputs that belong to an lnd wallet.
|
||||
dropchannelgraph Remove all graph related data from a channel DB
|
||||
dropgraphzombies Remove all channels identified as zombies from the graph to force a re-sync of the graph
|
||||
dumpbackup Dump the content of a channel.backup file
|
||||
dumpchannels Dump all channel information from an lnd channel database
|
||||
fakechanbackup Fake a channel backup file to attempt fund recovery
|
||||
@ -471,6 +472,7 @@ Legend:
|
||||
| [derivekey](doc/chantools_derivekey.md) | :pencil: Derive a single private/public key from `lnd`'s seed, use to test seed |
|
||||
| [doublespendinputs](doc/chantools_doublespendinputs.md) | :pencil: Tries to double spend the given inputs by deriving the private for the address and sweeping the funds to the given address |
|
||||
| [dropchannelgraph](doc/chantools_dropchannelgraph.md) | (:warning:) Completely drop the channel graph from a `channel.db` to force re-sync |
|
||||
| [dropgraphzombies](doc/chantools_dropgraphzombies.md) | Drop all zombie channels from a `channel.db` to force a graph re-sync |
|
||||
| [dumpbackup](doc/chantools_dumpbackup.md) | :pencil: Show the content of a `channel.backup` file as text |
|
||||
| [dumpchannels](doc/chantools_dumpchannels.md) | Show the content of a `channel.db` file as text |
|
||||
| [fakechanbackup](doc/chantools_fakechanbackup.md) | :pencil: Create a fake `channel.backup` file from public information |
|
||||
|
@ -58,7 +58,7 @@ chantools dropchannelgraph \
|
||||
RunE: cc.Execute,
|
||||
}
|
||||
cc.cmd.Flags().StringVar(
|
||||
&cc.ChannelDB, "channeldb", "", "lnd channel.db file to dump "+
|
||||
&cc.ChannelDB, "channeldb", "", "lnd channel.db file to drop "+
|
||||
"channels from",
|
||||
)
|
||||
cc.cmd.Flags().Uint64Var(
|
||||
|
88
cmd/chantools/dropgraphzombies.go
Normal file
88
cmd/chantools/dropgraphzombies.go
Normal file
@ -0,0 +1,88 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lightninglabs/chantools/lnd"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
zombieBucket = []byte("zombie-index")
|
||||
)
|
||||
|
||||
type dropGraphZombiesCommand struct {
|
||||
ChannelDB string
|
||||
NodeIdentityKey string
|
||||
FixOnly bool
|
||||
|
||||
SingleChannel uint64
|
||||
|
||||
cmd *cobra.Command
|
||||
}
|
||||
|
||||
func newDropGraphZombiesCommand() *cobra.Command {
|
||||
cc := &dropGraphZombiesCommand{}
|
||||
cc.cmd = &cobra.Command{
|
||||
Use: "dropgraphzombies",
|
||||
Short: "Remove all channels identified as zombies from the " +
|
||||
"graph to force a re-sync of the graph",
|
||||
Long: `This command removes all channels that were identified as
|
||||
zombies from the local graph.
|
||||
|
||||
This will cause lnd to re-download all those channels from the network and can
|
||||
be helpful to fix a graph that is out of sync with the network.
|
||||
|
||||
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 ` + lndVersion + ` or later after using this command!'`,
|
||||
Example: `chantools dropgraphzombies \
|
||||
--channeldb ~/.lnd/data/graph/mainnet/channel.db`,
|
||||
RunE: cc.Execute,
|
||||
}
|
||||
cc.cmd.Flags().StringVar(
|
||||
&cc.ChannelDB, "channeldb", "", "lnd channel.db file to drop "+
|
||||
"zombies from",
|
||||
)
|
||||
|
||||
return cc.cmd
|
||||
}
|
||||
|
||||
func (c *dropGraphZombiesCommand) 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: %w", err)
|
||||
}
|
||||
defer func() { _ = db.Close() }()
|
||||
|
||||
log.Infof("Dropping zombie channel bucket")
|
||||
|
||||
rwTx, err := db.BeginReadWriteTx()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
success := false
|
||||
defer func() {
|
||||
if !success {
|
||||
_ = rwTx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
edges := rwTx.ReadWriteBucket(edgeBucket)
|
||||
if edges == nil {
|
||||
return channeldb.ErrGraphNoEdgesFound
|
||||
}
|
||||
|
||||
if err := edges.DeleteNestedBucket(zombieBucket); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
success = true
|
||||
return rwTx.Commit()
|
||||
}
|
@ -103,6 +103,7 @@ func main() {
|
||||
newDeriveKeyCommand(),
|
||||
newDoubleSpendInputsCommand(),
|
||||
newDropChannelGraphCommand(),
|
||||
newDropGraphZombiesCommand(),
|
||||
newDumpBackupCommand(),
|
||||
newDumpChannelsCommand(),
|
||||
newDocCommand(),
|
||||
|
@ -26,6 +26,7 @@ Complete documentation is available at https://github.com/lightninglabs/chantool
|
||||
* [chantools derivekey](chantools_derivekey.md) - Derive a key with a specific derivation path
|
||||
* [chantools doublespendinputs](chantools_doublespendinputs.md) - Tries to double spend the given inputs by deriving the private for the address and sweeping the funds to the given address. This can only be used with inputs that belong to an lnd wallet.
|
||||
* [chantools dropchannelgraph](chantools_dropchannelgraph.md) - Remove all graph related data from a channel DB
|
||||
* [chantools dropgraphzombies](chantools_dropgraphzombies.md) - Remove all channels identified as zombies from the graph to force a re-sync of the graph
|
||||
* [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 fakechanbackup](chantools_fakechanbackup.md) - Fake a channel backup file to attempt fund recovery
|
||||
|
@ -34,7 +34,7 @@ chantools dropchannelgraph \
|
||||
### Options
|
||||
|
||||
```
|
||||
--channeldb string lnd channel.db file to dump channels from
|
||||
--channeldb string lnd channel.db file to drop channels from
|
||||
--fix_only fix an already empty graph by re-adding the own node's channels
|
||||
-h, --help help for dropchannelgraph
|
||||
--node_identity_key string your node's identity public key
|
||||
|
46
doc/chantools_dropgraphzombies.md
Normal file
46
doc/chantools_dropgraphzombies.md
Normal file
@ -0,0 +1,46 @@
|
||||
## chantools dropgraphzombies
|
||||
|
||||
Remove all channels identified as zombies from the graph to force a re-sync of the graph
|
||||
|
||||
### Synopsis
|
||||
|
||||
This command removes all channels that were identified as
|
||||
zombies from the local graph.
|
||||
|
||||
This will cause lnd to re-download all those channels from the network and can
|
||||
be helpful to fix a graph that is out of sync with the network.
|
||||
|
||||
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.16.0-beta or later after using this command!'
|
||||
|
||||
```
|
||||
chantools dropgraphzombies [flags]
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
```
|
||||
chantools dropgraphzombies \
|
||||
--channeldb ~/.lnd/data/graph/mainnet/channel.db
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
```
|
||||
--channeldb string lnd channel.db file to drop zombies from
|
||||
-h, --help help for dropgraphzombies
|
||||
```
|
||||
|
||||
### Options inherited from parent commands
|
||||
|
||||
```
|
||||
-r, --regtest Indicates if regtest parameters should be used
|
||||
-s, --signet Indicates if the public signet 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
|
||||
|
Loading…
Reference in New Issue
Block a user