Skip to content

Commit 2ae81d5

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 fd78618 commit 2ae81d5

File tree

6 files changed

+81
-62
lines changed

6 files changed

+81
-62
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 *VersionedGraph) 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 *VersionedGraph) 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 *VersionedGraph) 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
@@ -414,16 +422,15 @@ func TestPartialNode(t *testing.T) {
414422
require.ErrorIs(t, err, ErrGraphNodeNotFound)
415423
}
416424

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

422-
graph := MakeTestGraph(t)
429+
graph := NewVersionedGraph(MakeTestGraph(t), v)
423430

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

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

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

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

453-
graph := MakeTestGraph(t)
460+
graph := NewVersionedGraph(MakeTestGraph(t), v)
454461

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

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

0 commit comments

Comments
 (0)