Skip to content

Commit 46ce8ab

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 807a0ea commit 46ce8ab

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
@@ -417,16 +425,15 @@ func TestPartialNode(t *testing.T) {
417425
require.ErrorIs(t, err, ErrGraphNodeNotFound)
418426
}
419427

420-
// TestAliasLookup tests the alias lookup functionality of the graph store.
421-
func TestAliasLookup(t *testing.T) {
422-
t.Parallel()
428+
// testAliasLookup tests the alias lookup functionality of the graph store.
429+
func testAliasLookup(t *testing.T, v lnwire.GossipVersion) {
423430
ctx := t.Context()
424431

425-
graph := MakeTestGraph(t)
432+
graph := NewVersionedReader(MakeTestGraph(t), v)
426433

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

431438
// Add the node to the graph's database, this should also insert an
432439
// entry into the alias index for this node.
@@ -441,23 +448,23 @@ func TestAliasLookup(t *testing.T) {
441448
require.Equal(t, testNode.Alias.UnwrapOr(""), dbAlias)
442449

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

451-
// TestSourceNode tests the source node functionality of the graph store.
452-
func TestSourceNode(t *testing.T) {
458+
// testSourceNode tests the source node functionality of the graph store.
459+
func testSourceNode(t *testing.T, v lnwire.GossipVersion) {
453460
t.Parallel()
454461
ctx := t.Context()
455462

456-
graph := MakeTestGraph(t)
463+
graph := NewVersionedReader(MakeTestGraph(t), v)
457464

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

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

0 commit comments

Comments
 (0)