Skip to content

Commit 6f9ccab

Browse files
committed
graph/db: convert other node CRUD methods
Convert a few more CRUD methods to handle v2 nodes. Then update some more tests to be run against both v1 and v2 nodes.
1 parent bd978bb commit 6f9ccab

File tree

6 files changed

+83
-64
lines changed

6 files changed

+83
-64
lines changed

graph/db/graph.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -618,13 +618,6 @@ func (c *ChannelGraph) ForEachNodeCacheable(ctx context.Context,
618618
return c.db.ForEachNodeCacheable(ctx, cb, reset)
619619
}
620620

621-
// LookupAlias attempts to return the alias as advertised by the target node.
622-
func (c *ChannelGraph) LookupAlias(ctx context.Context,
623-
pub *btcec.PublicKey) (string, error) {
624-
625-
return c.db.LookupAlias(ctx, lnwire.GossipVersion1, pub)
626-
}
627-
628621
// NodeUpdatesInHorizon returns all known lightning nodes with updates in the
629622
// range.
630623
func (c *ChannelGraph) NodeUpdatesInHorizon(startTime, endTime time.Time,
@@ -755,11 +748,6 @@ func (c *ChannelGraph) IsClosedScid(scid lnwire.ShortChannelID) (bool, error) {
755748
return c.db.IsClosedScid(scid)
756749
}
757750

758-
// SourceNode returns the source node of the graph.
759-
func (c *ChannelGraph) SourceNode(ctx context.Context) (*models.Node, error) {
760-
return c.db.SourceNode(ctx, lnwire.GossipVersion1)
761-
}
762-
763751
// SetSourceNode sets the source node within the graph database.
764752
func (c *ChannelGraph) SetSourceNode(ctx context.Context,
765753
node *models.Node) error {
@@ -828,6 +816,20 @@ func (c *VersionedReader) HasNode(ctx context.Context, nodePub [33]byte) (bool,
828816
return c.db.HasNode(ctx, c.v, nodePub)
829817
}
830818

819+
// LookupAlias attempts to return the alias as advertised by the target node.
820+
func (c *VersionedReader) LookupAlias(ctx context.Context,
821+
pub *btcec.PublicKey) (string, error) {
822+
823+
return c.db.LookupAlias(ctx, c.v, pub)
824+
}
825+
826+
// SourceNode returns the source node of the graph.
827+
func (c *VersionedReader) SourceNode(ctx context.Context) (*models.Node,
828+
error) {
829+
830+
return c.db.SourceNode(ctx, c.v)
831+
}
832+
831833
// MakeTestGraph creates a new instance of the ChannelGraph for testing
832834
// purposes. The backing Store implementation depends on the version of
833835
// NewTestDB included in the current build.

graph/db/graph_test.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ var versionedTests = []versionedTest{
130130
name: "node crud",
131131
test: testNodeInsertionAndDeletion,
132132
},
133+
{
134+
name: "source node",
135+
test: testSourceNode,
136+
},
137+
{
138+
name: "alias lookup",
139+
test: testAliasLookup,
140+
},
133141
}
134142

135143
// TestVersionedDBs runs various tests against both v1 and v2 versioned
@@ -415,16 +423,15 @@ func TestPartialNode(t *testing.T) {
415423
require.ErrorIs(t, err, ErrGraphNodeNotFound)
416424
}
417425

418-
// TestAliasLookup tests the alias lookup functionality of the graph store.
419-
func TestAliasLookup(t *testing.T) {
420-
t.Parallel()
426+
// testAliasLookup tests the alias lookup functionality of the graph store.
427+
func testAliasLookup(t *testing.T, v lnwire.GossipVersion) {
421428
ctx := t.Context()
422429

423-
graph := MakeTestGraph(t)
430+
graph := NewVersionedReader(MakeTestGraph(t), v)
424431

425432
// We'd like to test the alias index within the database, so first
426433
// create a new test node.
427-
testNode := createTestVertex(t, lnwire.GossipVersion1)
434+
testNode := createTestVertex(t, v)
428435

429436
// Add the node to the graph's database, this should also insert an
430437
// entry into the alias index for this node.
@@ -439,23 +446,23 @@ func TestAliasLookup(t *testing.T) {
439446
require.Equal(t, testNode.Alias.UnwrapOr(""), dbAlias)
440447

441448
// Ensure that looking up a non-existent alias results in an error.
442-
node := createTestVertex(t, lnwire.GossipVersion1)
449+
node := createTestVertex(t, v)
443450
nodePub, err = node.PubKey()
444451
require.NoError(t, err, "unable to generate pubkey")
445452
_, err = graph.LookupAlias(ctx, nodePub)
446453
require.ErrorIs(t, err, ErrNodeAliasNotFound)
447454
}
448455

449-
// TestSourceNode tests the source node functionality of the graph store.
450-
func TestSourceNode(t *testing.T) {
456+
// testSourceNode tests the source node functionality of the graph store.
457+
func testSourceNode(t *testing.T, v lnwire.GossipVersion) {
451458
t.Parallel()
452459
ctx := t.Context()
453460

454-
graph := MakeTestGraph(t)
461+
graph := NewVersionedReader(MakeTestGraph(t), v)
455462

456463
// We'd like to test the setting/getting of the source node, so we
457464
// first create a fake node to use within the test.
458-
testNode := createTestVertex(t, lnwire.GossipVersion1)
465+
testNode := createTestVertex(t, v)
459466

460467
// Attempt to fetch the source node, this should return an error as the
461468
// source node hasn't yet been set.

0 commit comments

Comments
 (0)