Browse Source

Add closed channels to dumpchannels command

pull/17/head v0.3.0
Oliver Gugger 1 year ago
parent
commit
a95f475c6a
No known key found for this signature in database GPG Key ID: 8E4256593F177720
8 changed files with 95 additions and 16 deletions
  1. +2
    -1
      cmd/chantools/chanbackup.go
  2. +25
    -4
      cmd/chantools/dumpchannels.go
  3. +2
    -1
      cmd/chantools/forceclose.go
  4. +2
    -2
      cmd/chantools/main.go
  5. +2
    -1
      cmd/chantools/rescueclosed.go
  6. +59
    -4
      dump/dump.go
  7. +1
    -1
      go.mod
  8. +2
    -2
      go.sum

+ 2
- 1
cmd/chantools/chanbackup.go View File

@ -46,7 +46,8 @@ func (c *chanBackupCommand) Execute(_ []string) error {
return fmt.Errorf("channel DB is required")
}
db, err := channeldb.Open(
path.Dir(c.ChannelDB), channeldb.OptionSetSyncFreelist(true),
path.Dir(c.ChannelDB), path.Base(c.ChannelDB),
channeldb.OptionSetSyncFreelist(true),
channeldb.OptionReadOnly(true),
)
if err != nil {

+ 25
- 4
cmd/chantools/dumpchannels.go View File

@ -11,6 +11,7 @@ import (
type dumpChannelsCommand struct {
ChannelDB string `long:"channeldb" description:"The lnd channel.db file to dump the channels from."`
Closed bool `long:"closed" description:"Dump all closed channels instead of all open channels."`
}
func (c *dumpChannelsCommand) Execute(_ []string) error {
@ -21,22 +22,27 @@ func (c *dumpChannelsCommand) Execute(_ []string) error {
return fmt.Errorf("channel DB is required")
}
db, err := channeldb.Open(
path.Dir(c.ChannelDB), channeldb.OptionSetSyncFreelist(true),
path.Dir(c.ChannelDB), path.Base(c.ChannelDB),
channeldb.OptionSetSyncFreelist(true),
channeldb.OptionReadOnly(true),
)
if err != nil {
return fmt.Errorf("error opening rescue DB: %v", err)
}
return dumpChannelInfo(db)
if c.Closed {
return dumpClosedChannelInfo(db)
}
return dumpOpenChannelInfo(db)
}
func dumpChannelInfo(chanDb *channeldb.DB) error {
func dumpOpenChannelInfo(chanDb *channeldb.DB) error {
channels, err := chanDb.FetchAllChannels()
if err != nil {
return err
}
dumpChannels, err := dump.ChannelDump(channels, chainParams)
dumpChannels, err := dump.OpenChannelDump(channels, chainParams)
if err != nil {
return fmt.Errorf("error converting to dump format: %v", err)
}
@ -44,3 +50,18 @@ func dumpChannelInfo(chanDb *channeldb.DB) error {
spew.Dump(dumpChannels)
return nil
}
func dumpClosedChannelInfo(chanDb *channeldb.DB) error {
channels, err := chanDb.FetchClosedChannels(false)
if err != nil {
return err
}
dumpChannels, err := dump.ClosedChannelDump(channels, chainParams)
if err != nil {
return fmt.Errorf("error converting to dump format: %v", err)
}
spew.Dump(dumpChannels)
return nil
}

+ 2
- 1
cmd/chantools/forceclose.go View File

@ -50,7 +50,8 @@ func (c *forceCloseCommand) Execute(_ []string) error {
return fmt.Errorf("rescue DB is required")
}
db, err := channeldb.Open(
path.Dir(c.ChannelDB), channeldb.OptionSetSyncFreelist(true),
path.Dir(c.ChannelDB), path.Base(c.ChannelDB),
channeldb.OptionSetSyncFreelist(true),
channeldb.OptionReadOnly(true),
)
if err != nil {

+ 2
- 2
cmd/chantools/main.go View File

@ -23,7 +23,7 @@ import (
const (
defaultAPIURL = "https://blockstream.info/api"
version = "0.2.0"
version = "0.3.0"
)
var (
@ -170,7 +170,7 @@ func parseInputType(cfg *config) ([]*dataformat.SummaryEntry, error) {
case cfg.FromChannelDB != "":
db, err := channeldb.Open(
path.Dir(cfg.FromChannelDB),
path.Dir(cfg.FromChannelDB), path.Base(cfg.FromChannelDB),
channeldb.OptionSetSyncFreelist(true),
channeldb.OptionReadOnly(true),
)

+ 2
- 1
cmd/chantools/rescueclosed.go View File

@ -61,7 +61,8 @@ func (c *rescueClosedCommand) Execute(_ []string) error {
return fmt.Errorf("rescue DB is required")
}
db, err := channeldb.Open(
path.Dir(c.ChannelDB), channeldb.OptionSetSyncFreelist(true),
path.Dir(c.ChannelDB), path.Base(c.ChannelDB),
channeldb.OptionSetSyncFreelist(true),
channeldb.OptionReadOnly(true),
)
if err != nil {

+ 59
- 4
dump/dump.go View File

@ -73,6 +73,26 @@ type OpenChannel struct {
RemoteShutdownScript lnwire.DeliveryAddress
}
// ClosedChannel is the information we want to dump from a closed channel in
// lnd's channel DB. See `channeldb.ChannelCloseSummary` for information about
// the fields.
type ClosedChannel struct {
ChanPoint string
ShortChanID lnwire.ShortChannelID
ChainHash chainhash.Hash
ClosingTXID string
RemotePub string
Capacity btcutil.Amount
CloseHeight uint32
SettledBalance btcutil.Amount
TimeLockedBalance btcutil.Amount
CloseType string
IsPending bool
RemoteCurrentRevocation string
RemoteNextRevocation string
LocalChanConfig ChannelConfig
}
// ChannelConfig is the information we want to dump from a channel
// configuration. See `channeldb.ChannelConfig` for more information about the
// fields.
@ -92,10 +112,10 @@ type KeyDescriptor struct {
PubKey string
}
// ChannelDump converts the channels in the given channel DB into a dumpable
// format.
func ChannelDump(channels []*channeldb.OpenChannel, params *chaincfg.Params) (
[]OpenChannel, error) {
// OpenChannelDump converts the open channels in the given channel DB into a
// dumpable format.
func OpenChannelDump(channels []*channeldb.OpenChannel,
params *chaincfg.Params) ([]OpenChannel, error) {
dumpChannels := make([]OpenChannel, len(channels))
for idx, channel := range channels {
@ -154,6 +174,41 @@ func ChannelDump(channels []*channeldb.OpenChannel, params *chaincfg.Params) (
return dumpChannels, nil
}
// ClosedChannelDump converts the closed channels in the given channel DB into a
// dumpable format.
func ClosedChannelDump(channels []*channeldb.ChannelCloseSummary,
params *chaincfg.Params) ([]ClosedChannel, error) {
dumpChannels := make([]ClosedChannel, len(channels))
for idx, channel := range channels {
dumpChannels[idx] = ClosedChannel{
ChanPoint: channel.ChanPoint.String(),
ShortChanID: channel.ShortChanID,
ChainHash: channel.ChainHash,
ClosingTXID: channel.ClosingTXID.String(),
RemotePub: PubKeyToString(channel.RemotePub),
Capacity: channel.Capacity,
CloseHeight: channel.CloseHeight,
SettledBalance: channel.SettledBalance,
TimeLockedBalance: channel.TimeLockedBalance,
CloseType: fmt.Sprintf(
"%d", channel.CloseType,
),
IsPending: channel.IsPending,
RemoteCurrentRevocation: PubKeyToString(
channel.RemoteCurrentRevocation,
),
RemoteNextRevocation: PubKeyToString(
channel.RemoteNextRevocation,
),
LocalChanConfig: ToChannelConfig(
params, channel.LocalChanConfig,
),
}
}
return dumpChannels, nil
}
// BackupDump converts the given multi backup into a dumpable format.
func BackupDump(multi *chanbackup.Multi, params *chaincfg.Params) []BackupSingle {

+ 1
- 1
go.mod View File

@ -21,6 +21,6 @@ require (
gopkg.in/yaml.v2 v2.2.3 // indirect
)
replace github.com/lightningnetwork/lnd => github.com/guggero/lnd v0.9.0-beta-rc1.0.20200307101759-2650bff06031
replace github.com/lightningnetwork/lnd => github.com/guggero/lnd v0.9.0-beta-rc4.0.20200826102054-8c9171307182
go 1.13

+ 2
- 2
go.sum View File

@ -97,8 +97,8 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92Bcuy
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.8.6 h1:XvND7+MPP7Jp+JpqSZ7naSl5nVZf6k0LbL1V3EKh0zc=
github.com/grpc-ecosystem/grpc-gateway v1.8.6/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/guggero/lnd v0.9.0-beta-rc1.0.20200307101759-2650bff06031 h1:G7UpjWLXdmFi1gYVidq6c/EJaH/eX0HixAOVxxAT/K0=
github.com/guggero/lnd v0.9.0-beta-rc1.0.20200307101759-2650bff06031/go.mod h1:bMBXSbO0hwk9HmZSbI04SDTHxTK/iEOvzfzQkNSIJmU=
github.com/guggero/lnd v0.9.0-beta-rc4.0.20200826102054-8c9171307182 h1:VMQ3vCjVGhT1k1agfGMEDbtqtw6xpXGfgO3xaQ/TyLM=
github.com/guggero/lnd v0.9.0-beta-rc4.0.20200826102054-8c9171307182/go.mod h1:bMBXSbO0hwk9HmZSbI04SDTHxTK/iEOvzfzQkNSIJmU=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc=

Loading…
Cancel
Save