@@ -2,7 +2,6 @@ package main
22
33import  (
44	"fmt" 
5- 
65	"github.com/guggero/chantools/lnd" 
76	"github.com/spf13/cobra" 
87)
1615type  dropChannelGraphCommand  struct  {
1716	ChannelDB  string 
1817
18+ 	SingleChannel  uint64 
19+ 
1920	cmd  * cobra.Command 
2021}
2122
@@ -27,17 +28,29 @@ func newDropChannelGraphCommand() *cobra.Command {
2728		Long : `This command removes all graph data from a channel DB, 
2829forcing the lnd node to do a full graph sync. 
2930
31+ Or if a single channel is specified, that channel is purged from the graph 
32+ without removing any other data. 
33+ 
3034CAUTION: Running this command will make it impossible to use the channel DB 
3135with an older version of lnd. Downgrading is not possible and you'll need to 
3236run lnd v0.13.1-beta or later after using this command!'` ,
3337		Example : `chantools dropchannelgraph \ 
34- 	--channeldb ~/.lnd/data/graph/mainnet/channel.db` ,
38+ 	--channeldb ~/.lnd/data/graph/mainnet/channel.db 
39+ 
40+ chantools dropchannelgraph \ 
41+ 	--channeldb ~/.lnd/data/graph/mainnet/channel.db \ 
42+ 	--single_channel 726607861215512345` ,
3543		RunE : cc .Execute ,
3644	}
3745	cc .cmd .Flags ().StringVar (
3846		& cc .ChannelDB , "channeldb" , "" , "lnd channel.db file to dump " + 
3947			"channels from" ,
4048	)
49+ 	cc .cmd .Flags ().Uint64Var (
50+ 		& cc .SingleChannel , "single_channel" , 0 , "the single channel " + 
51+ 			"identified by its short channel ID (CID) to remove " + 
52+ 			"from the graph" ,
53+ 	)
4154
4255	return  cc .cmd 
4356}
@@ -53,20 +66,28 @@ func (c *dropChannelGraphCommand) Execute(_ *cobra.Command, _ []string) error {
5366	}
5467	defer  func () { _  =  db .Close () }()
5568
56- 	rwTx , err  :=  db .BeginReadWriteTx ()
57- 	if  err  !=  nil  {
58- 		return  err 
59- 	}
69+ 	if  c .SingleChannel  !=  0  {
70+ 		log .Infof ("Removing single channel %d" , c .SingleChannel )
71+ 		return  db .ChannelGraph ().DeleteChannelEdges (
72+ 			true , c .SingleChannel ,
73+ 		)
74+ 	} else  {
75+ 		log .Infof ("Dropping all graph related buckets" )
6076
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- 	}
77+ 		rwTx , err  :=  db .BeginReadWriteTx ()
78+ 		if  err  !=  nil  {
79+ 			return  err 
80+ 		}
81+ 		if  err  :=  rwTx .DeleteTopLevelBucket (nodeBucket ); err  !=  nil  {
82+ 			return  err 
83+ 		}
84+ 		if  err  :=  rwTx .DeleteTopLevelBucket (edgeBucket ); err  !=  nil  {
85+ 			return  err 
86+ 		}
87+ 		if  err  :=  rwTx .DeleteTopLevelBucket (graphMetaBucket ); err  !=  nil  {
88+ 			return  err 
89+ 		}
7090
71- 	return  rwTx .Commit ()
91+ 		return  rwTx .Commit ()
92+ 	}
7293}
0 commit comments