graph/db+sqldb: impl DisabledChannelIDs
Which lets us run `TestDisabledChannelIDs` against our SQL DB backends.
This commit is contained in:
6 files changed
+88
-1
No files matched your search
@@ -87,6 +87,7 @@ circuit. The indices are only available for forwarding events saved after v0.20.
|
|||||||
* [5](https://github.com/lightningnetwork/lnd/pull/9935)
|
* [5](https://github.com/lightningnetwork/lnd/pull/9935)
|
||||||
* [6](https://github.com/lightningnetwork/lnd/pull/9936)
|
* [6](https://github.com/lightningnetwork/lnd/pull/9936)
|
||||||
* [7](https://github.com/lightningnetwork/lnd/pull/9937)
|
* [7](https://github.com/lightningnetwork/lnd/pull/9937)
|
||||||
|
* [8](https://github.com/lightningnetwork/lnd/pull/9938)
|
||||||
|
|
||||||
## RPC Updates
|
## RPC Updates
|
||||||
|
|
||||||
|
|||||||
@@ -3592,7 +3592,7 @@ func TestDisabledChannelIDs(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
graph := MakeTestGraph(t)
|
graph := MakeTestGraphNew(t)
|
||||||
|
|
||||||
// Create first node and add it to the graph.
|
// Create first node and add it to the graph.
|
||||||
node1 := createTestVertex(t)
|
node1 := createTestVertex(t)
|
||||||
@@ -3608,6 +3608,7 @@ func TestDisabledChannelIDs(t *testing.T) {
|
|||||||
|
|
||||||
// Adding a new channel edge to the graph.
|
// Adding a new channel edge to the graph.
|
||||||
edgeInfo, edge1, edge2 := createChannelEdge(node1, node2)
|
edgeInfo, edge1, edge2 := createChannelEdge(node1, node2)
|
||||||
|
node2.LastUpdate = time.Unix(nextUpdateTime(), 0)
|
||||||
if err := graph.AddLightningNode(ctx, node2); err != nil {
|
if err := graph.AddLightningNode(ctx, node2); err != nil {
|
||||||
t.Fatalf("unable to add node: %v", err)
|
t.Fatalf("unable to add node: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ type SQLQueries interface {
|
|||||||
*/
|
*/
|
||||||
UpsertEdgePolicy(ctx context.Context, arg sqlc.UpsertEdgePolicyParams) (int64, error)
|
UpsertEdgePolicy(ctx context.Context, arg sqlc.UpsertEdgePolicyParams) (int64, error)
|
||||||
GetChannelPolicyByChannelAndNode(ctx context.Context, arg sqlc.GetChannelPolicyByChannelAndNodeParams) (sqlc.ChannelPolicy, error)
|
GetChannelPolicyByChannelAndNode(ctx context.Context, arg sqlc.GetChannelPolicyByChannelAndNodeParams) (sqlc.ChannelPolicy, error)
|
||||||
|
GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error)
|
||||||
|
|
||||||
InsertChanPolicyExtraType(ctx context.Context, arg sqlc.InsertChanPolicyExtraTypeParams) error
|
InsertChanPolicyExtraType(ctx context.Context, arg sqlc.InsertChanPolicyExtraTypeParams) error
|
||||||
GetChannelPolicyExtraTypes(ctx context.Context, arg sqlc.GetChannelPolicyExtraTypesParams) ([]sqlc.GetChannelPolicyExtraTypesRow, error)
|
GetChannelPolicyExtraTypes(ctx context.Context, arg sqlc.GetChannelPolicyExtraTypesParams) ([]sqlc.GetChannelPolicyExtraTypesRow, error)
|
||||||
@@ -372,6 +373,35 @@ func (s *SQLStore) FetchNodeFeatures(nodePub route.Vertex) (
|
|||||||
return fetchNodeFeatures(ctx, s.db, nodePub)
|
return fetchNodeFeatures(ctx, s.db, nodePub)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DisabledChannelIDs returns the channel ids of disabled channels.
|
||||||
|
// A channel is disabled when two of the associated ChanelEdgePolicies
|
||||||
|
// have their disabled bit on.
|
||||||
|
//
|
||||||
|
// NOTE: part of the V1Store interface.
|
||||||
|
func (s *SQLStore) DisabledChannelIDs() ([]uint64, error) {
|
||||||
|
var (
|
||||||
|
ctx = context.TODO()
|
||||||
|
chanIDs []uint64
|
||||||
|
)
|
||||||
|
err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
||||||
|
dbChanIDs, err := db.GetV1DisabledSCIDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to fetch disabled "+
|
||||||
|
"channels: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
chanIDs = fn.Map(dbChanIDs, byteOrder.Uint64)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}, sqldb.NoOpReset)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to fetch disabled channels: %w",
|
||||||
|
err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return chanIDs, nil
|
||||||
|
}
|
||||||
|
|
||||||
// LookupAlias attempts to return the alias as advertised by the target node.
|
// LookupAlias attempts to return the alias as advertised by the target node.
|
||||||
//
|
//
|
||||||
// NOTE: part of the V1Store interface.
|
// NOTE: part of the V1Store interface.
|
||||||
|
|||||||
@@ -1219,6 +1219,43 @@ func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getV1DisabledSCIDs = `-- name: GetV1DisabledSCIDs :many
|
||||||
|
SELECT c.scid
|
||||||
|
FROM channels c
|
||||||
|
JOIN channel_policies cp ON cp.channel_id = c.id
|
||||||
|
WHERE cp.disabled = true
|
||||||
|
AND c.version = 1
|
||||||
|
GROUP BY c.scid
|
||||||
|
HAVING COUNT(*) > 1
|
||||||
|
`
|
||||||
|
|
||||||
|
// NOTE: this is V1 specific since for V1, disabled is a
|
||||||
|
// simple, single boolean. The proposed V2 policy
|
||||||
|
// structure will have a more complex disabled bit vector
|
||||||
|
// and so the query for V2 may differ.
|
||||||
|
func (q *Queries) GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, getV1DisabledSCIDs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items [][]byte
|
||||||
|
for rows.Next() {
|
||||||
|
var scid []byte
|
||||||
|
if err := rows.Scan(&scid); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, scid)
|
||||||
|
}
|
||||||
|
if err := rows.Close(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
const getZombieChannel = `-- name: GetZombieChannel :one
|
const getZombieChannel = `-- name: GetZombieChannel :one
|
||||||
SELECT scid, version, node_key_1, node_key_2
|
SELECT scid, version, node_key_1, node_key_2
|
||||||
FROM zombie_channels
|
FROM zombie_channels
|
||||||
|
|||||||
@@ -60,6 +60,11 @@ type Querier interface {
|
|||||||
GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]Channel, error)
|
GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]Channel, error)
|
||||||
GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error)
|
GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error)
|
||||||
GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error)
|
GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error)
|
||||||
|
// NOTE: this is V1 specific since for V1, disabled is a
|
||||||
|
// simple, single boolean. The proposed V2 policy
|
||||||
|
// structure will have a more complex disabled bit vector
|
||||||
|
// and so the query for V2 may differ.
|
||||||
|
GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error)
|
||||||
GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (ZombieChannel, error)
|
GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (ZombieChannel, error)
|
||||||
HighestSCID(ctx context.Context, version int16) ([]byte, error)
|
HighestSCID(ctx context.Context, version int16) ([]byte, error)
|
||||||
InsertAMPSubInvoice(ctx context.Context, arg InsertAMPSubInvoiceParams) error
|
InsertAMPSubInvoice(ctx context.Context, arg InsertAMPSubInvoiceParams) error
|
||||||
|
|||||||
@@ -573,6 +573,19 @@ JOIN channel_policy_extra_types cpet
|
|||||||
ON cp.id = cpet.channel_policy_id
|
ON cp.id = cpet.channel_policy_id
|
||||||
WHERE cp.id = $1 OR cp.id = $2;
|
WHERE cp.id = $1 OR cp.id = $2;
|
||||||
|
|
||||||
|
-- name: GetV1DisabledSCIDs :many
|
||||||
|
SELECT c.scid
|
||||||
|
FROM channels c
|
||||||
|
JOIN channel_policies cp ON cp.channel_id = c.id
|
||||||
|
-- NOTE: this is V1 specific since for V1, disabled is a
|
||||||
|
-- simple, single boolean. The proposed V2 policy
|
||||||
|
-- structure will have a more complex disabled bit vector
|
||||||
|
-- and so the query for V2 may differ.
|
||||||
|
WHERE cp.disabled = true
|
||||||
|
AND c.version = 1
|
||||||
|
GROUP BY c.scid
|
||||||
|
HAVING COUNT(*) > 1;
|
||||||
|
|
||||||
-- name: DeleteChannelPolicyExtraTypes :exec
|
-- name: DeleteChannelPolicyExtraTypes :exec
|
||||||
DELETE FROM channel_policy_extra_types
|
DELETE FROM channel_policy_extra_types
|
||||||
WHERE channel_policy_id = $1;
|
WHERE channel_policy_id = $1;
|
||||||
|
|||||||
Reference in new issue
Block a user