Skip to content

Commit eec8936

Browse files
committed
graph/db+sqldb: impl DisabledChannelIDs
Which lets us run `TestDisabledChannelIDs` against our SQL DB backends.
1 parent f1da381 commit eec8936

File tree

6 files changed

+88
-1
lines changed

6 files changed

+88
-1
lines changed

docs/release-notes/release-notes-0.20.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ circuit. The indices are only available for forwarding events saved after v0.20.
8787
* [5](https://github.com/lightningnetwork/lnd/pull/9935)
8888
* [6](https://github.com/lightningnetwork/lnd/pull/9936)
8989
* [7](https://github.com/lightningnetwork/lnd/pull/9937)
90+
* [8](https://github.com/lightningnetwork/lnd/pull/9938)
9091

9192
## RPC Updates
9293

graph/db/graph_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3592,7 +3592,7 @@ func TestDisabledChannelIDs(t *testing.T) {
35923592
t.Parallel()
35933593
ctx := context.Background()
35943594

3595-
graph := MakeTestGraph(t)
3595+
graph := MakeTestGraphNew(t)
35963596

35973597
// Create first node and add it to the graph.
35983598
node1 := createTestVertex(t)
@@ -3608,6 +3608,7 @@ func TestDisabledChannelIDs(t *testing.T) {
36083608

36093609
// Adding a new channel edge to the graph.
36103610
edgeInfo, edge1, edge2 := createChannelEdge(node1, node2)
3611+
node2.LastUpdate = time.Unix(nextUpdateTime(), 0)
36113612
if err := graph.AddLightningNode(ctx, node2); err != nil {
36123613
t.Fatalf("unable to add node: %v", err)
36133614
}

graph/db/sql_store.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ type SQLQueries interface {
109109
*/
110110
UpsertEdgePolicy(ctx context.Context, arg sqlc.UpsertEdgePolicyParams) (int64, error)
111111
GetChannelPolicyByChannelAndNode(ctx context.Context, arg sqlc.GetChannelPolicyByChannelAndNodeParams) (sqlc.ChannelPolicy, error)
112+
GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error)
112113

113114
InsertChanPolicyExtraType(ctx context.Context, arg sqlc.InsertChanPolicyExtraTypeParams) error
114115
GetChannelPolicyExtraTypes(ctx context.Context, arg sqlc.GetChannelPolicyExtraTypesParams) ([]sqlc.GetChannelPolicyExtraTypesRow, error)
@@ -372,6 +373,35 @@ func (s *SQLStore) FetchNodeFeatures(nodePub route.Vertex) (
372373
return fetchNodeFeatures(ctx, s.db, nodePub)
373374
}
374375

376+
// DisabledChannelIDs returns the channel ids of disabled channels.
377+
// A channel is disabled when two of the associated ChanelEdgePolicies
378+
// have their disabled bit on.
379+
//
380+
// NOTE: part of the V1Store interface.
381+
func (s *SQLStore) DisabledChannelIDs() ([]uint64, error) {
382+
var (
383+
ctx = context.TODO()
384+
chanIDs []uint64
385+
)
386+
err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
387+
dbChanIDs, err := db.GetV1DisabledSCIDs(ctx)
388+
if err != nil {
389+
return fmt.Errorf("unable to fetch disabled "+
390+
"channels: %w", err)
391+
}
392+
393+
chanIDs = fn.Map(dbChanIDs, byteOrder.Uint64)
394+
395+
return nil
396+
}, sqldb.NoOpReset)
397+
if err != nil {
398+
return nil, fmt.Errorf("unable to fetch disabled channels: %w",
399+
err)
400+
}
401+
402+
return chanIDs, nil
403+
}
404+
375405
// LookupAlias attempts to return the alias as advertised by the target node.
376406
//
377407
// NOTE: part of the V1Store interface.

sqldb/sqlc/graph.sql.go

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sqldb/sqlc/querier.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sqldb/sqlc/queries/graph.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,19 @@ JOIN channel_policy_extra_types cpet
573573
ON cp.id = cpet.channel_policy_id
574574
WHERE cp.id = $1 OR cp.id = $2;
575575

576+
-- name: GetV1DisabledSCIDs :many
577+
SELECT c.scid
578+
FROM channels c
579+
JOIN channel_policies cp ON cp.channel_id = c.id
580+
-- NOTE: this is V1 specific since for V1, disabled is a
581+
-- simple, single boolean. The proposed V2 policy
582+
-- structure will have a more complex disabled bit vector
583+
-- and so the query for V2 may differ.
584+
WHERE cp.disabled = true
585+
AND c.version = 1
586+
GROUP BY c.scid
587+
HAVING COUNT(*) > 1;
588+
576589
-- name: DeleteChannelPolicyExtraTypes :exec
577590
DELETE FROM channel_policy_extra_types
578591
WHERE channel_policy_id = $1;

0 commit comments

Comments
 (0)