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.
This commit is contained in:
7 files changed
+82
-63
No files matched your search
+14
-12
@@ -618,13 +618,6 @@ func (c *ChannelGraph) ForEachNodeCacheable(ctx context.Context,
|
||||
return c.db.ForEachNodeCacheable(ctx, cb, reset)
|
||||
}
|
||||
|
||||
// LookupAlias attempts to return the alias as advertised by the target node.
|
||||
func (c *ChannelGraph) LookupAlias(ctx context.Context,
|
||||
pub *btcec.PublicKey) (string, error) {
|
||||
|
||||
return c.db.LookupAlias(ctx, lnwire.GossipVersion1, pub)
|
||||
}
|
||||
|
||||
// NodeUpdatesInHorizon returns all known lightning nodes with updates in the
|
||||
// range.
|
||||
func (c *ChannelGraph) NodeUpdatesInHorizon(startTime, endTime time.Time,
|
||||
@@ -755,11 +748,6 @@ func (c *ChannelGraph) IsClosedScid(scid lnwire.ShortChannelID) (bool, error) {
|
||||
return c.db.IsClosedScid(scid)
|
||||
}
|
||||
|
||||
// SourceNode returns the source node of the graph.
|
||||
func (c *ChannelGraph) SourceNode(ctx context.Context) (*models.Node, error) {
|
||||
return c.db.SourceNode(ctx, lnwire.GossipVersion1)
|
||||
}
|
||||
|
||||
// SetSourceNode sets the source node within the graph database.
|
||||
func (c *ChannelGraph) SetSourceNode(ctx context.Context,
|
||||
node *models.Node) error {
|
||||
@@ -828,6 +816,20 @@ func (c *VersionedGraph) HasNode(ctx context.Context, nodePub [33]byte) (bool,
|
||||
return c.db.HasNode(ctx, c.v, nodePub)
|
||||
}
|
||||
|
||||
// LookupAlias attempts to return the alias as advertised by the target node.
|
||||
func (c *VersionedGraph) LookupAlias(ctx context.Context,
|
||||
pub *btcec.PublicKey) (string, error) {
|
||||
|
||||
return c.db.LookupAlias(ctx, c.v, pub)
|
||||
}
|
||||
|
||||
// SourceNode returns the source node of the graph.
|
||||
func (c *VersionedGraph) SourceNode(ctx context.Context) (*models.Node,
|
||||
error) {
|
||||
|
||||
return c.db.SourceNode(ctx, c.v)
|
||||
}
|
||||
|
||||
// MakeTestGraph creates a new instance of the ChannelGraph for testing
|
||||
// purposes. The backing Store implementation depends on the version of
|
||||
// NewTestDB included in the current build.
|
||||
|
||||
+17
-10
@@ -130,6 +130,14 @@ var versionedTests = []versionedTest{
|
||||
name: "node crud",
|
||||
test: testNodeInsertionAndDeletion,
|
||||
},
|
||||
{
|
||||
name: "source node",
|
||||
test: testSourceNode,
|
||||
},
|
||||
{
|
||||
name: "alias lookup",
|
||||
test: testAliasLookup,
|
||||
},
|
||||
}
|
||||
|
||||
// TestVersionedDBs runs various tests against both v1 and v2 versioned
|
||||
@@ -414,16 +422,15 @@ func TestPartialNode(t *testing.T) {
|
||||
require.ErrorIs(t, err, ErrGraphNodeNotFound)
|
||||
}
|
||||
|
||||
// TestAliasLookup tests the alias lookup functionality of the graph store.
|
||||
func TestAliasLookup(t *testing.T) {
|
||||
t.Parallel()
|
||||
// testAliasLookup tests the alias lookup functionality of the graph store.
|
||||
func testAliasLookup(t *testing.T, v lnwire.GossipVersion) {
|
||||
ctx := t.Context()
|
||||
|
||||
graph := MakeTestGraph(t)
|
||||
graph := NewVersionedGraph(MakeTestGraph(t), v)
|
||||
|
||||
// We'd like to test the alias index within the database, so first
|
||||
// create a new test node.
|
||||
testNode := createTestVertex(t, lnwire.GossipVersion1)
|
||||
testNode := createTestVertex(t, v)
|
||||
|
||||
// Add the node to the graph's database, this should also insert an
|
||||
// entry into the alias index for this node.
|
||||
@@ -438,23 +445,23 @@ func TestAliasLookup(t *testing.T) {
|
||||
require.Equal(t, testNode.Alias.UnwrapOr(""), dbAlias)
|
||||
|
||||
// Ensure that looking up a non-existent alias results in an error.
|
||||
node := createTestVertex(t, lnwire.GossipVersion1)
|
||||
node := createTestVertex(t, v)
|
||||
nodePub, err = node.PubKey()
|
||||
require.NoError(t, err, "unable to generate pubkey")
|
||||
_, err = graph.LookupAlias(ctx, nodePub)
|
||||
require.ErrorIs(t, err, ErrNodeAliasNotFound)
|
||||
}
|
||||
|
||||
// TestSourceNode tests the source node functionality of the graph store.
|
||||
func TestSourceNode(t *testing.T) {
|
||||
// testSourceNode tests the source node functionality of the graph store.
|
||||
func testSourceNode(t *testing.T, v lnwire.GossipVersion) {
|
||||
t.Parallel()
|
||||
ctx := t.Context()
|
||||
|
||||
graph := MakeTestGraph(t)
|
||||
graph := NewVersionedGraph(MakeTestGraph(t), v)
|
||||
|
||||
// We'd like to test the setting/getting of the source node, so we
|
||||
// first create a fake node to use within the test.
|
||||
testNode := createTestVertex(t, lnwire.GossipVersion1)
|
||||
testNode := createTestVertex(t, v)
|
||||
|
||||
// Attempt to fetch the source node, this should return an error as the
|
||||
// source node hasn't yet been set.
|
||||
|
||||
@@ -524,7 +524,7 @@ func (s *SQLStore) SourceNode(ctx context.Context,
|
||||
err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
||||
_, nodePub, err := s.getSourceNode(ctx, db, v)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to fetch V1 source node: %w",
|
||||
return fmt.Errorf("unable to fetch source node: %w",
|
||||
err)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user