-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multi: add new dropgraphzombies command
- Loading branch information
Showing
7 changed files
with
140 additions
and
2 deletions.
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
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,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() | ||
} |
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
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,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 | ||
|