Skip to content

Commit a5f3006

Browse files
authored
Merge pull request #10339 from ellemouton/g175Prep3
[g175:2] graph/db: v2 columns and v2 node CRUD
2 parents c746aee + 59ddd43 commit a5f3006

30 files changed

+1147
-549
lines changed

autopilot/prefattach_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ type testGraph interface {
3131
}
3232

3333
type testDBGraph struct {
34-
db *graphdb.ChannelGraph
34+
db *graphdb.VersionedGraph
3535
databaseChannelGraph
3636
}
3737

3838
func newDiskChanGraph(t *testing.T) (testGraph, error) {
39-
graphDB := graphdb.MakeTestGraph(t)
39+
graphDB := graphdb.NewVersionedGraph(
40+
graphdb.MakeTestGraph(t), lnwire.GossipVersion1,
41+
)
4042
require.NoError(t, graphDB.Start())
4143
t.Cleanup(func() {
4244
require.NoError(t, graphDB.Stop())

config_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
10961096

10971097
// The graph store implementation we will use depends on whether
10981098
// native SQL is enabled or not.
1099-
var graphStore graphdb.V1Store
1099+
var graphStore graphdb.Store
11001100

11011101
// Instantiate a native SQL store if the flag is set.
11021102
if d.cfg.DB.UseNativeSQL {

docs/release-notes/release-notes-0.21.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
* Freeze the [graph SQL migration
6969
code](https://github.com/lightningnetwork/lnd/pull/10338) to prevent the
7070
need for maintenance as the sqlc code evolves.
71+
* Prepare the graph DB for handling gossip [V2
72+
nodes](https://github.com/lightningnetwork/lnd/pull/10339).
7173

7274
## Code Health
7375

graph/builder.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ type Builder struct {
111111

112112
bestHeight atomic.Uint32
113113

114-
cfg *Config
114+
cfg *Config
115+
v1Graph *graphdb.VersionedGraph
115116

116117
// newBlocks is a channel in which new blocks connected to the end of
117118
// the main chain are sent over, and blocks updated after a call to
@@ -146,7 +147,11 @@ var _ ChannelGraphSource = (*Builder)(nil)
146147
// NewBuilder constructs a new Builder.
147148
func NewBuilder(cfg *Config) (*Builder, error) {
148149
return &Builder{
149-
cfg: cfg,
150+
cfg: cfg,
151+
// For now, we'll just use V1 graph reader.
152+
v1Graph: graphdb.NewVersionedGraph(
153+
cfg.Graph, lnwire.GossipVersion1,
154+
),
150155
channelEdgeMtx: multimutex.NewMutex[uint64](),
151156
statTicker: ticker.New(defaultStatInterval),
152157
stats: new(builderStats),
@@ -874,7 +879,7 @@ func (b *Builder) assertNodeAnnFreshness(ctx context.Context, node route.Vertex,
874879
// node announcements, we will ignore such nodes. If we do know about
875880
// this node, check that this update brings info newer than what we
876881
// already have.
877-
lastUpdate, exists, err := b.cfg.Graph.HasNode(ctx, node)
882+
lastUpdate, exists, err := b.cfg.Graph.HasV1Node(ctx, node)
878883
if err != nil {
879884
return fmt.Errorf("unable to query for the "+
880885
"existence of node: %w", err)
@@ -1266,7 +1271,7 @@ func (b *Builder) GetChannelByID(chanID lnwire.ShortChannelID) (
12661271
func (b *Builder) FetchNode(ctx context.Context,
12671272
node route.Vertex) (*models.Node, error) {
12681273

1269-
return b.cfg.Graph.FetchNode(ctx, node)
1274+
return b.v1Graph.FetchNode(ctx, node)
12701275
}
12711276

12721277
// ForAllOutgoingChannels is used to iterate over all outgoing channels owned by

graph/builder_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
359359
// Create new router with same graph database.
360360
router, err := NewBuilder(&Config{
361361
SelfNode: selfNode.PubKeyBytes,
362-
Graph: ctx.graph,
362+
Graph: ctx.graph.ChannelGraph,
363363
Chain: ctx.chain,
364364
ChainView: ctx.chainView,
365365
ChannelPruneExpiry: time.Hour * 24,
@@ -1595,7 +1595,9 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
15951595
}
15961596

15971597
return &testGraphInstance{
1598-
graph: graph,
1598+
graph: graphdb.NewVersionedGraph(
1599+
graph, lnwire.GossipVersion1,
1600+
),
15991601
aliasMap: aliasMap,
16001602
privKeyMap: privKeyMap,
16011603
channelIDs: channelIDs,
@@ -1690,7 +1692,7 @@ func asymmetricTestChannel(alias1, alias2 string, capacity btcutil.Amount,
16901692

16911693
// assertChannelsPruned ensures that only the given channels are pruned from the
16921694
// graph out of the set of all channels.
1693-
func assertChannelsPruned(t *testing.T, graph *graphdb.ChannelGraph,
1695+
func assertChannelsPruned(t *testing.T, graph *graphdb.VersionedGraph,
16941696
channels []*testChannel, prunedChanIDs ...uint64) {
16951697

16961698
t.Helper()
@@ -1980,7 +1982,9 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
19801982
}
19811983

19821984
return &testGraphInstance{
1983-
graph: graph,
1985+
graph: graphdb.NewVersionedGraph(
1986+
graph, lnwire.GossipVersion1,
1987+
),
19841988
aliasMap: aliasMap,
19851989
privKeyMap: privKeyMap,
19861990
links: links,

graph/db/benchmark_test.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,19 @@ var (
7272
// and a function to open the connection.
7373
type dbConnection struct {
7474
name string
75-
open func(testing.TB) V1Store
75+
open func(testing.TB) Store
7676
}
7777

7878
// This var block defines the various database connections that we will use
7979
// for testing. Each connection is defined as a dbConnection struct that
8080
// contains a name and an open function. The open function is used to create
81-
// a new V1Store instance for the given database type.
81+
// a new Store instance for the given database type.
8282
var (
8383
// kvdbBBoltConn is a connection to a kvdb-bbolt database called
8484
// channel.db.
8585
kvdbBBoltConn = dbConnection{
8686
name: "kvdb-bbolt",
87-
open: func(b testing.TB) V1Store {
87+
open: func(b testing.TB) Store {
8888
return connectBBoltDB(b, bboltDBPath, kvdbBBoltFile)
8989
},
9090
}
@@ -93,7 +93,7 @@ var (
9393
// channel.sqlite.
9494
kvdbSqliteConn = dbConnection{
9595
name: "kvdb-sqlite",
96-
open: func(b testing.TB) V1Store {
96+
open: func(b testing.TB) Store {
9797
return connectKVDBSqlite(
9898
b, kvdbSqlitePath, kvdbSqliteFile,
9999
)
@@ -104,7 +104,7 @@ var (
104104
// called lnd.sqlite.
105105
nativeSQLSqliteConn = dbConnection{
106106
name: "native-sqlite",
107-
open: func(b testing.TB) V1Store {
107+
open: func(b testing.TB) Store {
108108
return connectNativeSQLite(
109109
b, sqldb.DefaultSQLiteConfig(),
110110
nativeSQLSqlitePath, nativeSQLSqliteFile,
@@ -116,7 +116,7 @@ var (
116116
// using a postgres connection string.
117117
kvdbPostgresConn = dbConnection{
118118
name: "kvdb-postgres",
119-
open: func(b testing.TB) V1Store {
119+
open: func(b testing.TB) Store {
120120
return connectKVDBPostgres(b, kvdbPostgresDNS)
121121
},
122122
}
@@ -125,7 +125,7 @@ var (
125125
// database using a postgres connection string.
126126
nativeSQLPostgresConn = dbConnection{
127127
name: "native-postgres",
128-
open: func(b testing.TB) V1Store {
128+
open: func(b testing.TB) Store {
129129
return connectNativePostgres(
130130
b, sqldb.DefaultPostgresConfig(),
131131
nativeSQLPostgresDNS,
@@ -134,10 +134,10 @@ var (
134134
}
135135
)
136136

137-
// connectNativePostgres creates a V1Store instance backed by a native Postgres
137+
// connectNativePostgres creates a Store instance backed by a native Postgres
138138
// database for testing purposes.
139139
func connectNativePostgres(t testing.TB, cfg *sqldb.QueryConfig,
140-
dsn string) V1Store {
140+
dsn string) Store {
141141

142142
return newSQLStore(t, cfg, sqlPostgres(t, dsn))
143143
}
@@ -157,10 +157,10 @@ func sqlPostgres(t testing.TB, dsn string) BatchedSQLQueries {
157157
return newSQLExecutor(t, store)
158158
}
159159

160-
// connectNativeSQLite creates a V1Store instance backed by a native SQLite
160+
// connectNativeSQLite creates a Store instance backed by a native SQLite
161161
// database for testing purposes.
162162
func connectNativeSQLite(t testing.TB, cfg *sqldb.QueryConfig, dbPath,
163-
file string) V1Store {
163+
file string) Store {
164164

165165
return newSQLStore(t, cfg, sqlSQLite(t, dbPath, file))
166166
}
@@ -205,9 +205,9 @@ func kvdbPostgres(t testing.TB, dsn string) kvdb.Backend {
205205
return kvStore
206206
}
207207

208-
// connectKVDBPostgres creates a V1Store instance backed by a kvdb-postgres
208+
// connectKVDBPostgres creates a Store instance backed by a kvdb-postgres
209209
// database for testing purposes.
210-
func connectKVDBPostgres(t testing.TB, dsn string) V1Store {
210+
func connectKVDBPostgres(t testing.TB, dsn string) Store {
211211
return newKVStore(t, kvdbPostgres(t, dsn))
212212
}
213213

@@ -231,14 +231,14 @@ func kvdbSqlite(t testing.TB, dbPath, fileName string) kvdb.Backend {
231231
return kvStore
232232
}
233233

234-
// connectKVDBSqlite creates a V1Store instance backed by a kvdb-sqlite
234+
// connectKVDBSqlite creates a Store instance backed by a kvdb-sqlite
235235
// database for testing purposes.
236-
func connectKVDBSqlite(t testing.TB, dbPath, fileName string) V1Store {
236+
func connectKVDBSqlite(t testing.TB, dbPath, fileName string) Store {
237237
return newKVStore(t, kvdbSqlite(t, dbPath, fileName))
238238
}
239239

240240
// connectBBoltDB creates a new BBolt database connection for testing.
241-
func connectBBoltDB(t testing.TB, dbPath, fileName string) V1Store {
241+
func connectBBoltDB(t testing.TB, dbPath, fileName string) Store {
242242
return newKVStore(t, kvdbBBolt(t, dbPath, fileName))
243243
}
244244

@@ -261,7 +261,7 @@ func kvdbBBolt(t testing.TB, dbPath, fileName string) kvdb.Backend {
261261

262262
// newKVStore creates a new KVStore instance for testing using a provided
263263
// kvdb.Backend instance.
264-
func newKVStore(t testing.TB, backend kvdb.Backend) V1Store {
264+
func newKVStore(t testing.TB, backend kvdb.Backend) Store {
265265
store, err := NewKVStore(backend, testStoreOptions...)
266266
require.NoError(t, err)
267267

@@ -286,7 +286,7 @@ func newSQLExecutor(t testing.TB, db sqldb.DB) BatchedSQLQueries {
286286
// newSQLStore creates a new SQLStore instance for testing using a provided
287287
// sqldb.DB instance.
288288
func newSQLStore(t testing.TB, cfg *sqldb.QueryConfig,
289-
db BatchedSQLQueries) V1Store {
289+
db BatchedSQLQueries) Store {
290290

291291
store, err := NewSQLStore(
292292
&SQLStoreConfig{
@@ -587,7 +587,7 @@ func BenchmarkCacheLoading(b *testing.B) {
587587
}
588588
}
589589

590-
// BenchmarkGraphReadMethods benchmarks various read calls of various V1Store
590+
// BenchmarkGraphReadMethods benchmarks various read calls of various Store
591591
// implementations.
592592
//
593593
// NOTE: this is to be run against a local graph database. It can be run
@@ -614,11 +614,11 @@ func BenchmarkGraphReadMethods(b *testing.B) {
614614

615615
tests := []struct {
616616
name string
617-
fn func(b testing.TB, store V1Store)
617+
fn func(b testing.TB, store Store)
618618
}{
619619
{
620620
name: "ForEachNode",
621-
fn: func(b testing.TB, store V1Store) {
621+
fn: func(b testing.TB, store Store) {
622622
err := store.ForEachNode(
623623
ctx,
624624
func(_ *models.Node) error {
@@ -635,7 +635,7 @@ func BenchmarkGraphReadMethods(b *testing.B) {
635635
},
636636
{
637637
name: "ForEachChannel",
638-
fn: func(b testing.TB, store V1Store) {
638+
fn: func(b testing.TB, store Store) {
639639
//nolint:ll
640640
err := store.ForEachChannel(
641641
ctx, func(_ *models.ChannelEdgeInfo,
@@ -655,7 +655,7 @@ func BenchmarkGraphReadMethods(b *testing.B) {
655655
},
656656
{
657657
name: "NodeUpdatesInHorizon",
658-
fn: func(b testing.TB, store V1Store) {
658+
fn: func(b testing.TB, store Store) {
659659
iter := store.NodeUpdatesInHorizon(
660660
time.Unix(0, 0), time.Now(),
661661
)
@@ -665,7 +665,7 @@ func BenchmarkGraphReadMethods(b *testing.B) {
665665
},
666666
{
667667
name: "ForEachNodeCacheable",
668-
fn: func(b testing.TB, store V1Store) {
668+
fn: func(b testing.TB, store Store) {
669669
err := store.ForEachNodeCacheable(
670670
ctx, func(_ route.Vertex,
671671
_ *lnwire.FeatureVector) error {
@@ -683,7 +683,7 @@ func BenchmarkGraphReadMethods(b *testing.B) {
683683
},
684684
{
685685
name: "ForEachNodeCached",
686-
fn: func(b testing.TB, store V1Store) {
686+
fn: func(b testing.TB, store Store) {
687687
//nolint:ll
688688
err := store.ForEachNodeCached(
689689
ctx, false, func(context.Context,
@@ -704,7 +704,7 @@ func BenchmarkGraphReadMethods(b *testing.B) {
704704
},
705705
{
706706
name: "ChanUpdatesInHorizon",
707-
fn: func(b testing.TB, store V1Store) {
707+
fn: func(b testing.TB, store Store) {
708708
iter := store.ChanUpdatesInHorizon(
709709
time.Unix(0, 0), time.Now(),
710710
)

0 commit comments

Comments
 (0)