Skip to content

Commit 7988c44

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 d5ee69a commit 7988c44

File tree

6 files changed

+81
-64
lines changed

6 files changed

+81
-64
lines changed

graph/db/graph.go

Lines changed: 12 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,
@@ -754,11 +747,6 @@ func (c *ChannelGraph) IsClosedScid(scid lnwire.ShortChannelID) (bool, error) {
754747
return c.db.IsClosedScid(scid)
755748
}
756749

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

818+
// LookupAlias attempts to return the alias as advertised by the target node.
819+
func (c *VersionedReader) LookupAlias(ctx context.Context,
820+
pub *btcec.PublicKey) (string, error) {
821+
822+
return c.db.LookupAlias(ctx, c.v, pub)
823+
}
824+
825+
// SourceNode returns the source node of the graph.
826+
func (c *VersionedReader) SourceNode(ctx context.Context) (*models.Node, error) {
827+
return c.db.SourceNode(ctx, c.v)
828+
}
829+
830830
// MakeTestGraph creates a new instance of the ChannelGraph for testing
831831
// purposes. The backing Store implementation depends on the version of
832832
// 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
@@ -129,6 +129,14 @@ var versionedTests = []versionedTest{
129129
name: "node crud",
130130
test: testNodeInsertionAndDeletion,
131131
},
132+
{
133+
name: "source node",
134+
test: testSourceNode,
135+
},
136+
{
137+
name: "alias lookup",
138+
test: testAliasLookup,
139+
},
132140
}
133141

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

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

424-
graph := MakeTestGraph(t)
431+
graph := NewVersionedReader(MakeTestGraph(t), v)
425432

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

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

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

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

455-
graph := MakeTestGraph(t)
462+
graph := NewVersionedReader(MakeTestGraph(t), v)
456463

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

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

0 commit comments

Comments
 (0)