Skip to content

Commit 29bed90

Browse files
committed
multi: compile-time dependency of lnd to 0.19.0
Important notes. - channeldb was split to channeldb and graphdb - chanbackup.NewMultiFile got additional argument noBackupArchive, I pass false - Go updated to 1.23.6 - golangci-lint updated to v1.64.5
1 parent b8cb81a commit 29bed90

36 files changed

+643
-571
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ env:
1616
# go needs absolute directories, using the $HOME variable doesn't work here.
1717
GOCACHE: /home/runner/work/go/pkg/build
1818
GOPATH: /home/runner/work/go
19-
GO_VERSION: 1.22.6
19+
GO_VERSION: 1.23.6
2020

2121
jobs:
2222
########################

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ $ sudo mv chantools-*/chantools /usr/local/bin/
3939

4040
If there isn't a pre-built binary for your operating system or architecture
4141
available or you want to build `chantools` from source for another reason, you
42-
need to make sure you have `go 1.22.3` (or later) and `make` installed and can
42+
need to make sure you have `go 1.23.6` (or later) and `make` installed and can
4343
then run the following commands:
4444

4545
```bash

btc/summary.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package btc
33
import (
44
"errors"
55

6-
"github.com/btcsuite/btclog"
6+
"github.com/btcsuite/btclog/v2"
77
"github.com/lightninglabs/chantools/dataformat"
88
)
99

cmd/chantools/chanbackup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ func (c *chanBackupCommand) Execute(_ *cobra.Command, _ []string) error {
5858
if c.ChannelDB == "" {
5959
return errors.New("channel DB is required")
6060
}
61-
db, err := lnd.OpenDB(c.ChannelDB, true)
61+
db, _, err := lnd.OpenDB(c.ChannelDB, true)
6262
if err != nil {
6363
return fmt.Errorf("error opening rescue DB: %w", err)
6464
}
65-
multiFile := chanbackup.NewMultiFile(c.MultiFile)
65+
multiFile := chanbackup.NewMultiFile(c.MultiFile, noBackupArchive)
6666
keyRing := &lnd.HDKeyRing{
6767
ExtendedKey: extendedKey,
6868
ChainParams: chainParams,

cmd/chantools/deletepayments.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ func (c *deletePaymentsCommand) Execute(_ *cobra.Command, _ []string) error {
4848
if c.ChannelDB == "" {
4949
return errors.New("channel DB is required")
5050
}
51-
db, err := lnd.OpenDB(c.ChannelDB, false)
51+
db, _, err := lnd.OpenDB(c.ChannelDB, false)
5252
if err != nil {
5353
return fmt.Errorf("error opening rescue DB: %w", err)
5454
}
5555
defer func() { _ = db.Close() }()
5656

57-
return db.DeletePayments(c.FailedOnly, false)
57+
_, err = db.DeletePayments(c.FailedOnly, false)
58+
59+
return err
5860
}

cmd/chantools/dropchannelgraph.go

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,13 @@ import (
1313
"github.com/lightninglabs/chantools/lnd"
1414
"github.com/lightningnetwork/lnd/chainreg"
1515
"github.com/lightningnetwork/lnd/channeldb"
16-
"github.com/lightningnetwork/lnd/channeldb/models"
16+
graphdb "github.com/lightningnetwork/lnd/graph/db"
17+
"github.com/lightningnetwork/lnd/graph/db/models"
1718
"github.com/lightningnetwork/lnd/keychain"
1819
"github.com/lightningnetwork/lnd/lnwire"
1920
"github.com/spf13/cobra"
2021
)
2122

22-
var (
23-
nodeBucket = []byte("graph-node")
24-
edgeBucket = []byte("graph-edge")
25-
graphMetaBucket = []byte("graph-meta")
26-
)
27-
2823
type dropChannelGraphCommand struct {
2924
ChannelDB string
3025
NodeIdentityKey string
@@ -85,11 +80,11 @@ func (c *dropChannelGraphCommand) Execute(_ *cobra.Command, _ []string) error {
8580
if c.ChannelDB == "" {
8681
return errors.New("channel DB is required")
8782
}
88-
db, err := lnd.OpenDB(c.ChannelDB, false)
83+
channelDB, graphDB, err := lnd.OpenDB(c.ChannelDB, false)
8984
if err != nil {
90-
return fmt.Errorf("error opening rescue DB: %w", err)
85+
return fmt.Errorf("error opening channel DB: %w", err)
9186
}
92-
defer func() { _ = db.Close() }()
87+
defer func() { _ = channelDB.Close() }()
9388

9489
if c.NodeIdentityKey == "" {
9590
return errors.New("node identity key is required")
@@ -107,7 +102,7 @@ func (c *dropChannelGraphCommand) Execute(_ *cobra.Command, _ []string) error {
107102

108103
if c.SingleChannel != 0 {
109104
log.Infof("Removing single channel %d", c.SingleChannel)
110-
return db.ChannelGraph().DeleteChannelEdges(
105+
return graphDB.DeleteChannelEdges(
111106
true, false, c.SingleChannel,
112107
)
113108
}
@@ -116,35 +111,20 @@ func (c *dropChannelGraphCommand) Execute(_ *cobra.Command, _ []string) error {
116111
if !c.FixOnly {
117112
log.Infof("Dropping all graph related buckets")
118113

119-
rwTx, err := db.BeginReadWriteTx()
120-
if err != nil {
121-
return err
122-
}
123-
if err := rwTx.DeleteTopLevelBucket(nodeBucket); err != nil {
124-
return err
125-
}
126-
if err := rwTx.DeleteTopLevelBucket(edgeBucket); err != nil {
127-
return err
128-
}
129-
if err := rwTx.DeleteTopLevelBucket(graphMetaBucket); err != nil {
130-
return err
131-
}
132-
133-
if err := rwTx.Commit(); err != nil {
134-
return err
135-
}
114+
return graphDB.Wipe()
136115
}
137116

138-
return insertOwnNodeAndChannels(idKey, db)
117+
return insertOwnNodeAndChannels(idKey, channelDB, graphDB)
139118
}
140119

141-
func insertOwnNodeAndChannels(idKey *btcec.PublicKey, db *channeldb.DB) error {
142-
openChannels, err := db.ChannelStateDB().FetchAllOpenChannels()
120+
func insertOwnNodeAndChannels(idKey *btcec.PublicKey, channelDB *channeldb.DB,
121+
graphDB *graphdb.ChannelGraph) error {
122+
123+
openChannels, err := channelDB.ChannelStateDB().FetchAllOpenChannels()
143124
if err != nil {
144125
return fmt.Errorf("error fetching open channels: %w", err)
145126
}
146127

147-
graph := db.ChannelGraph()
148128
for _, openChan := range openChannels {
149129
edge, update, err := newChanAnnouncement(
150130
idKey, openChan.IdentityPub,
@@ -159,11 +139,11 @@ func insertOwnNodeAndChannels(idKey *btcec.PublicKey, db *channeldb.DB) error {
159139
err)
160140
}
161141

162-
if err := graph.AddChannelEdge(edge); err != nil {
142+
if err := graphDB.AddChannelEdge(edge); err != nil {
163143
log.Warnf("Not adding channel edge %v because of "+
164144
"error: %v", edge.ChannelPoint, err)
165145
}
166-
if err := graph.UpdateEdgePolicy(update); err != nil {
146+
if err := graphDB.UpdateEdgePolicy(update); err != nil {
167147
log.Warnf("Not updating edge policy %v because of "+
168148
"error: %v", update.ChannelID, err)
169149
}
@@ -184,7 +164,7 @@ func newChanAnnouncement(localPubKey, remotePubKey *btcec.PublicKey,
184164
// The unconditional section of the announcement is the ShortChannelID
185165
// itself which compactly encodes the location of the funding output
186166
// within the blockchain.
187-
chanAnn := &lnwire.ChannelAnnouncement{
167+
chanAnn := &lnwire.ChannelAnnouncement1{
188168
ShortChannelID: shortChanID,
189169
Features: lnwire.NewRawFeatureVector(),
190170
ChainHash: chainHash,
@@ -248,7 +228,7 @@ func newChanAnnouncement(localPubKey, remotePubKey *btcec.PublicKey,
248228

249229
// We announce the channel with the default values. Some of
250230
// these values can later be changed by crafting a new ChannelUpdate.
251-
chanUpdateAnn := &lnwire.ChannelUpdate{
231+
chanUpdateAnn := &lnwire.ChannelUpdate1{
252232
ShortChannelID: shortChanID,
253233
ChainHash: chainHash,
254234
Timestamp: uint32(time.Now().Unix()),

cmd/chantools/dropgraphzombies.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import (
55
"fmt"
66

77
"github.com/lightninglabs/chantools/lnd"
8-
"github.com/lightningnetwork/lnd/channeldb"
8+
graphdb "github.com/lightningnetwork/lnd/graph/db"
99
"github.com/spf13/cobra"
1010
)
1111

1212
var (
13+
edgeBucket = []byte("graph-edge")
1314
zombieBucket = []byte("zombie-index")
1415
)
1516

@@ -55,7 +56,7 @@ func (c *dropGraphZombiesCommand) Execute(_ *cobra.Command, _ []string) error {
5556
if c.ChannelDB == "" {
5657
return errors.New("channel DB is required")
5758
}
58-
db, err := lnd.OpenDB(c.ChannelDB, false)
59+
db, _, err := lnd.OpenDB(c.ChannelDB, false)
5960
if err != nil {
6061
return fmt.Errorf("error opening rescue DB: %w", err)
6162
}
@@ -77,13 +78,14 @@ func (c *dropGraphZombiesCommand) Execute(_ *cobra.Command, _ []string) error {
7778

7879
edges := rwTx.ReadWriteBucket(edgeBucket)
7980
if edges == nil {
80-
return channeldb.ErrGraphNoEdgesFound
81+
return graphdb.ErrGraphNoEdgesFound
8182
}
8283

8384
if err := edges.DeleteNestedBucket(zombieBucket); err != nil {
8485
return err
8586
}
8687

8788
success = true
89+
8890
return rwTx.Commit()
8991
}

cmd/chantools/dumpbackup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (c *dumpBackupCommand) Execute(_ *cobra.Command, _ []string) error {
5050
if c.MultiFile == "" {
5151
return errors.New("backup file is required")
5252
}
53-
multiFile := chanbackup.NewMultiFile(c.MultiFile)
53+
multiFile := chanbackup.NewMultiFile(c.MultiFile, noBackupArchive)
5454
keyRing := &lnd.HDKeyRing{
5555
ExtendedKey: extendedKey,
5656
ChainParams: chainParams,

cmd/chantools/dumpchannels.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (c *dumpChannelsCommand) Execute(_ *cobra.Command, _ []string) error {
5757
if c.ChannelDB == "" {
5858
return errors.New("channel DB is required")
5959
}
60-
db, err := lnd.OpenDB(c.ChannelDB, true)
60+
db, _, err := lnd.OpenDB(c.ChannelDB, true)
6161
if err != nil {
6262
return fmt.Errorf("error opening rescue DB: %w", err)
6363
}

cmd/chantools/fakechanbackup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (c *fakeChanBackupCommand) Execute(_ *cobra.Command, _ []string) error {
126126
return fmt.Errorf("error reading root key: %w", err)
127127
}
128128

129-
multiFile := chanbackup.NewMultiFile(c.MultiFile)
129+
multiFile := chanbackup.NewMultiFile(c.MultiFile, noBackupArchive)
130130
keyRing := &lnd.HDKeyRing{
131131
ExtendedKey: extendedKey,
132132
ChainParams: chainParams,

cmd/chantools/filterbackup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (c *filterBackupCommand) Execute(_ *cobra.Command, _ []string) error {
6262
if c.MultiFile == "" {
6363
return errors.New("backup file is required")
6464
}
65-
multiFile := chanbackup.NewMultiFile(c.MultiFile)
65+
multiFile := chanbackup.NewMultiFile(c.MultiFile, noBackupArchive)
6666
keyRing := &lnd.HDKeyRing{
6767
ExtendedKey: extendedKey,
6868
ChainParams: chainParams,

cmd/chantools/fixoldbackup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (c *fixOldBackupCommand) Execute(_ *cobra.Command, _ []string) error {
5555
if c.MultiFile == "" {
5656
return errors.New("backup file is required")
5757
}
58-
multiFile := chanbackup.NewMultiFile(c.MultiFile)
58+
multiFile := chanbackup.NewMultiFile(c.MultiFile, noBackupArchive)
5959
keyRing := &lnd.HDKeyRing{
6060
ExtendedKey: extendedKey,
6161
ChainParams: chainParams,

cmd/chantools/forceclose.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (c *forceCloseCommand) Execute(_ *cobra.Command, _ []string) error {
8282
if c.ChannelDB == "" {
8383
return errors.New("rescue DB is required")
8484
}
85-
db, err := lnd.OpenDB(c.ChannelDB, true)
85+
db, _, err := lnd.OpenDB(c.ChannelDB, true)
8686
if err != nil {
8787
return fmt.Errorf("error opening rescue DB: %w", err)
8888
}

cmd/chantools/migratedb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (c *migrateDBCommand) Execute(_ *cobra.Command, _ []string) error {
4444
if c.ChannelDB == "" {
4545
return errors.New("channel DB is required")
4646
}
47-
db, err := lnd.OpenDB(c.ChannelDB, false)
47+
db, _, err := lnd.OpenDB(c.ChannelDB, false)
4848
if err != nil {
4949
return fmt.Errorf("error opening DB: %w", err)
5050
}

cmd/chantools/removechannel.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (c *removeChannelCommand) Execute(_ *cobra.Command, _ []string) error {
5656
if c.ChannelDB == "" {
5757
return errors.New("channel DB is required")
5858
}
59-
db, err := lnd.OpenDB(c.ChannelDB, false)
59+
db, _, err := lnd.OpenDB(c.ChannelDB, false)
6060
if err != nil {
6161
return fmt.Errorf("error opening channel DB: %w", err)
6262
}
@@ -88,7 +88,7 @@ func (c *removeChannelCommand) Execute(_ *cobra.Command, _ []string) error {
8888
func removeChannel(db *channeldb.ChannelStateDB,
8989
chanPoint *wire.OutPoint) error {
9090

91-
dbChan, err := db.FetchChannel(nil, *chanPoint)
91+
dbChan, err := db.FetchChannel(*chanPoint)
9292
if err != nil {
9393
return err
9494
}

cmd/chantools/rescueclosed.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (c *rescueClosedCommand) Execute(_ *cobra.Command, _ []string) error {
126126
// address and commit point?
127127
switch {
128128
case c.ChannelDB != "":
129-
db, err := lnd.OpenDB(c.ChannelDB, true)
129+
db, _, err := lnd.OpenDB(c.ChannelDB, true)
130130
if err != nil {
131131
return fmt.Errorf("error opening rescue DB: %w", err)
132132
}

cmd/chantools/rescuefunding.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (c *rescueFundingCommand) Execute(_ *cobra.Command, _ []string) error {
158158
"channel point or both local and remote pubkey")
159159

160160
case c.ChannelDB != "" && c.DBChannelPoint != "":
161-
db, err := lnd.OpenDB(c.ChannelDB, true)
161+
db, _, err := lnd.OpenDB(c.ChannelDB, true)
162162
if err != nil {
163163
return fmt.Errorf("error opening rescue DB: %w", err)
164164
}
@@ -172,7 +172,7 @@ func (c *rescueFundingCommand) Execute(_ *cobra.Command, _ []string) error {
172172

173173
// First, make sure the channel can be found in the DB.
174174
pendingChan, err := db.ChannelStateDB().FetchChannel(
175-
nil, *databaseOp,
175+
*databaseOp,
176176
)
177177
if err != nil {
178178
return fmt.Errorf("error loading pending channel %s "+

cmd/chantools/rescuetweakedkey.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ func (c *rescueTweakedKeyCommand) Execute(_ *cobra.Command, _ []string) error {
8989
}
9090

9191
func testPattern(startKey *btcec.PrivateKey, targetAddr btcutil.Address,
92-
max uint64) error {
92+
maxIndex uint64) error {
9393

9494
currentKey := copyPrivKey(startKey)
95-
for idx := uint64(0); idx <= max; idx++ {
95+
for idx := uint64(0); idx <= maxIndex; idx++ {
9696
match, err := pubKeyMatchesAddr(currentKey.PubKey(), targetAddr)
9797
if err != nil {
9898
return fmt.Errorf("error matching key to address: %w",
@@ -138,7 +138,7 @@ func testPattern(startKey *btcec.PrivateKey, targetAddr btcutil.Address,
138138
}
139139

140140
if idx != 0 && idx%5000 == 0 {
141-
fmt.Printf("Tested %d of %d mutations\n", idx, max)
141+
fmt.Printf("Tested %d of %d mutations\n", idx, maxIndex)
142142
}
143143
}
144144

@@ -154,7 +154,7 @@ func testPattern(startKey *btcec.PrivateKey, targetAddr btcutil.Address,
154154
}
155155

156156
return fmt.Errorf("%w: key for address %v not found after %d attempts",
157-
ErrAddrNotFound, targetAddr.String(), max)
157+
ErrAddrNotFound, targetAddr.String(), maxIndex)
158158
}
159159

160160
func pubKeyMatchesAddr(pubKey *btcec.PublicKey, addr btcutil.Address) (bool,

0 commit comments

Comments
 (0)