diff --git a/graph/db/sql_migration.go b/graph/db/sql_migration.go index 6cc6ab2ff..dd7cf62b2 100644 --- a/graph/db/sql_migration.go +++ b/graph/db/sql_migration.go @@ -445,19 +445,19 @@ func migrateSingleChannel(ctx context.Context, sqlDB SQLQueries, // Assert that the DB IDs for the channel and nodes are as expected // given the inserted channel info. err = sqldb.CompareRecords( - dbChanInfo.channelID, row.Channel.ID, "channel DB ID", + dbChanInfo.channelID, row.GraphChannel.ID, "channel DB ID", ) if err != nil { return err } err = sqldb.CompareRecords( - dbChanInfo.node1ID, row.Node.ID, "node1 DB ID", + dbChanInfo.node1ID, row.GraphNode.ID, "node1 DB ID", ) if err != nil { return err } err = sqldb.CompareRecords( - dbChanInfo.node2ID, row.Node_2.ID, "node2 DB ID", + dbChanInfo.node2ID, row.GraphNode_2.ID, "node2 DB ID", ) if err != nil { return err @@ -647,14 +647,15 @@ func getAndBuildChanAndPolicies(ctx context.Context, db SQLQueries, *models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) { node1, node2, err := buildNodeVertices( - row.Node.PubKey, row.Node_2.PubKey, + row.GraphNode.PubKey, row.GraphNode_2.PubKey, ) if err != nil { return nil, nil, nil, err } edge, err := getAndBuildEdgeInfo( - ctx, db, chain, row.Channel.ID, row.Channel, node1, node2, + ctx, db, chain, row.GraphChannel.ID, row.GraphChannel, node1, + node2, ) if err != nil { return nil, nil, nil, fmt.Errorf("unable to build channel "+ diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go index cd5031f06..d9e6c650e 100644 --- a/graph/db/sql_store.go +++ b/graph/db/sql_store.go @@ -58,17 +58,17 @@ type SQLQueries interface { Node queries. */ UpsertNode(ctx context.Context, arg sqlc.UpsertNodeParams) (int64, error) - GetNodeByPubKey(ctx context.Context, arg sqlc.GetNodeByPubKeyParams) (sqlc.Node, error) + GetNodeByPubKey(ctx context.Context, arg sqlc.GetNodeByPubKeyParams) (sqlc.GraphNode, error) GetNodeIDByPubKey(ctx context.Context, arg sqlc.GetNodeIDByPubKeyParams) (int64, error) - GetNodesByLastUpdateRange(ctx context.Context, arg sqlc.GetNodesByLastUpdateRangeParams) ([]sqlc.Node, error) - ListNodesPaginated(ctx context.Context, arg sqlc.ListNodesPaginatedParams) ([]sqlc.Node, error) + GetNodesByLastUpdateRange(ctx context.Context, arg sqlc.GetNodesByLastUpdateRangeParams) ([]sqlc.GraphNode, error) + ListNodesPaginated(ctx context.Context, arg sqlc.ListNodesPaginatedParams) ([]sqlc.GraphNode, error) ListNodeIDsAndPubKeys(ctx context.Context, arg sqlc.ListNodeIDsAndPubKeysParams) ([]sqlc.ListNodeIDsAndPubKeysRow, error) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error) DeleteUnconnectedNodes(ctx context.Context) ([][]byte, error) DeleteNodeByPubKey(ctx context.Context, arg sqlc.DeleteNodeByPubKeyParams) (sql.Result, error) DeleteNode(ctx context.Context, id int64) error - GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]sqlc.NodeExtraType, error) + GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]sqlc.GraphNodeExtraType, error) UpsertNodeExtraType(ctx context.Context, arg sqlc.UpsertNodeExtraTypeParams) error DeleteExtraNodeType(ctx context.Context, arg sqlc.DeleteExtraNodeTypeParams) error @@ -77,7 +77,7 @@ type SQLQueries interface { DeleteNodeAddresses(ctx context.Context, nodeID int64) error InsertNodeFeature(ctx context.Context, arg sqlc.InsertNodeFeatureParams) error - GetNodeFeatures(ctx context.Context, nodeID int64) ([]sqlc.NodeFeature, error) + GetNodeFeatures(ctx context.Context, nodeID int64) ([]sqlc.GraphNodeFeature, error) GetNodeFeaturesByPubKey(ctx context.Context, arg sqlc.GetNodeFeaturesByPubKeyParams) ([]int32, error) DeleteNodeFeature(ctx context.Context, arg sqlc.DeleteNodeFeatureParams) error @@ -92,7 +92,7 @@ type SQLQueries interface { */ CreateChannel(ctx context.Context, arg sqlc.CreateChannelParams) (int64, error) AddV1ChannelProof(ctx context.Context, arg sqlc.AddV1ChannelProofParams) (sql.Result, error) - GetChannelBySCID(ctx context.Context, arg sqlc.GetChannelBySCIDParams) (sqlc.Channel, error) + GetChannelBySCID(ctx context.Context, arg sqlc.GetChannelBySCIDParams) (sqlc.GraphChannel, error) GetChannelByOutpoint(ctx context.Context, outpoint string) (sqlc.GetChannelByOutpointRow, error) GetChannelsBySCIDRange(ctx context.Context, arg sqlc.GetChannelsBySCIDRangeParams) ([]sqlc.GetChannelsBySCIDRangeRow, error) GetChannelBySCIDWithPolicies(ctx context.Context, arg sqlc.GetChannelBySCIDWithPoliciesParams) (sqlc.GetChannelBySCIDWithPoliciesRow, error) @@ -104,7 +104,7 @@ type SQLQueries interface { ListChannelsPaginated(ctx context.Context, arg sqlc.ListChannelsPaginatedParams) ([]sqlc.ListChannelsPaginatedRow, error) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg sqlc.GetChannelsByPolicyLastUpdateRangeParams) ([]sqlc.GetChannelsByPolicyLastUpdateRangeRow, error) GetChannelByOutpointWithPolicies(ctx context.Context, arg sqlc.GetChannelByOutpointWithPoliciesParams) (sqlc.GetChannelByOutpointWithPoliciesRow, error) - GetPublicV1ChannelsBySCID(ctx context.Context, arg sqlc.GetPublicV1ChannelsBySCIDParams) ([]sqlc.Channel, error) + GetPublicV1ChannelsBySCID(ctx context.Context, arg sqlc.GetPublicV1ChannelsBySCIDParams) ([]sqlc.GraphChannel, error) GetSCIDByOutpoint(ctx context.Context, arg sqlc.GetSCIDByOutpointParams) ([]byte, error) DeleteChannel(ctx context.Context, id int64) error @@ -115,7 +115,7 @@ type SQLQueries interface { Channel Policy table queries. */ 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.GraphChannelPolicy, error) GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) InsertChanPolicyExtraType(ctx context.Context, arg sqlc.InsertChanPolicyExtraTypeParams) error @@ -126,7 +126,7 @@ type SQLQueries interface { Zombie index queries. */ UpsertZombieChannel(ctx context.Context, arg sqlc.UpsertZombieChannelParams) error - GetZombieChannel(ctx context.Context, arg sqlc.GetZombieChannelParams) (sqlc.ZombieChannel, error) + GetZombieChannel(ctx context.Context, arg sqlc.GetZombieChannelParams) (sqlc.GraphZombieChannel, error) CountZombieChannels(ctx context.Context, version int16) (int64, error) DeleteZombieChannel(ctx context.Context, arg sqlc.DeleteZombieChannelParams) (sql.Result, error) IsZombieChannel(ctx context.Context, arg sqlc.IsZombieChannelParams) (bool, error) @@ -134,7 +134,7 @@ type SQLQueries interface { /* Prune log table queries. */ - GetPruneTip(ctx context.Context) (sqlc.PruneLog, error) + GetPruneTip(ctx context.Context) (sqlc.GraphPruneLog, error) GetPruneHashByHeight(ctx context.Context, blockHeight int64) ([]byte, error) UpsertPruneLogEntry(ctx context.Context, arg sqlc.UpsertPruneLogEntryParams) error DeletePruneLogEntriesInRange(ctx context.Context, arg sqlc.DeletePruneLogEntriesInRangeParams) error @@ -788,7 +788,7 @@ func (s *SQLStore) ForEachNode(ctx context.Context, cb func(tx NodeRTx) error, reset func()) error { var lastID int64 = 0 - handleNode := func(db SQLQueries, dbNode sqlc.Node) error { + handleNode := func(db SQLQueries, dbNode sqlc.GraphNode) error { node, err := buildNode(ctx, db, &dbNode) if err != nil { return fmt.Errorf("unable to build node(id=%d): %w", @@ -1015,7 +1015,7 @@ func (s *SQLStore) ChanUpdatesInHorizon(startTime, // If we've already retrieved the info and policies for // this edge, then we can skip it as we don't need to do // so again. - chanIDInt := byteOrder.Uint64(row.Channel.Scid) + chanIDInt := byteOrder.Uint64(row.GraphChannel.Scid) if _, ok := edgesSeen[chanIDInt]; ok { continue } @@ -1029,15 +1029,15 @@ func (s *SQLStore) ChanUpdatesInHorizon(startTime, } node1, node2, err := buildNodes( - ctx, db, row.Node, row.Node_2, + ctx, db, row.GraphNode, row.GraphNode_2, ) if err != nil { return err } channel, err := getAndBuildEdgeInfo( - ctx, db, s.cfg.ChainHash, row.Channel.ID, - row.Channel, node1.PubKeyBytes, + ctx, db, s.cfg.ChainHash, row.GraphChannel.ID, + row.GraphChannel, node1.PubKeyBytes, node2.PubKeyBytes, ) if err != nil { @@ -1144,8 +1144,8 @@ func (s *SQLStore) ForEachNodeCached(ctx context.Context, e, err := getAndBuildEdgeInfo( ctx, db, s.cfg.ChainHash, - row.Channel.ID, row.Channel, node1, - node2, + row.GraphChannel.ID, row.GraphChannel, + node1, node2, ) if err != nil { return fmt.Errorf("unable to build "+ @@ -1250,7 +1250,9 @@ func (s *SQLStore) ForEachChannelCacheable(cb func(*models.CachedEdgeInfo, return err } - edge := buildCacheableChannelInfo(row.Channel, node1, node2) + edge := buildCacheableChannelInfo( + row.GraphChannel, node1, node2, + ) dbPol1, dbPol2, err := extractChannelPolicies(row) if err != nil { @@ -1311,7 +1313,7 @@ func (s *SQLStore) ForEachChannelCacheable(cb func(*models.CachedEdgeInfo, return err } - lastID = row.Channel.ID + lastID = row.GraphChannel.ID } } @@ -1346,8 +1348,8 @@ func (s *SQLStore) ForEachChannel(ctx context.Context, } edge, err := getAndBuildEdgeInfo( - ctx, db, s.cfg.ChainHash, row.Channel.ID, row.Channel, - node1, node2, + ctx, db, s.cfg.ChainHash, row.GraphChannel.ID, + row.GraphChannel, node1, node2, ) if err != nil { return fmt.Errorf("unable to build channel info: %w", @@ -1402,7 +1404,7 @@ func (s *SQLStore) ForEachChannel(ctx context.Context, return err } - lastID = row.Channel.ID + lastID = row.GraphChannel.ID } } @@ -1728,21 +1730,21 @@ func (s *SQLStore) DeleteChannelEdges(strictZombiePruning, markZombie bool, } node1, node2, err := buildNodeVertices( - row.Node.PubKey, row.Node_2.PubKey, + row.GraphNode.PubKey, row.GraphNode_2.PubKey, ) if err != nil { return err } info, err := getAndBuildEdgeInfo( - ctx, db, s.cfg.ChainHash, row.Channel.ID, - row.Channel, node1, node2, + ctx, db, s.cfg.ChainHash, row.GraphChannel.ID, + row.GraphChannel, node1, node2, ) if err != nil { return err } - err = db.DeleteChannel(ctx, row.Channel.ID) + err = db.DeleteChannel(ctx, row.GraphChannel.ID) if err != nil { return fmt.Errorf("unable to delete "+ "channel: %w", err) @@ -1866,15 +1868,15 @@ func (s *SQLStore) FetchChannelEdgesByID(chanID uint64) ( } node1, node2, err := buildNodeVertices( - row.Node.PubKey, row.Node_2.PubKey, + row.GraphNode.PubKey, row.GraphNode_2.PubKey, ) if err != nil { return err } edge, err = getAndBuildEdgeInfo( - ctx, db, s.cfg.ChainHash, row.Channel.ID, row.Channel, - node1, node2, + ctx, db, s.cfg.ChainHash, row.GraphChannel.ID, + row.GraphChannel, node1, node2, ) if err != nil { return fmt.Errorf("unable to build channel info: %w", @@ -1945,8 +1947,8 @@ func (s *SQLStore) FetchChannelEdgesByOutpoint(op *wire.OutPoint) ( } edge, err = getAndBuildEdgeInfo( - ctx, db, s.cfg.ChainHash, row.Channel.ID, row.Channel, - node1, node2, + ctx, db, s.cfg.ChainHash, row.GraphChannel.ID, + row.GraphChannel, node1, node2, ) if err != nil { return fmt.Errorf("unable to build channel info: %w", @@ -2187,7 +2189,7 @@ func (s *SQLStore) FetchChanInfos(chanIDs []uint64) ([]ChannelEdge, error) { } node1, node2, err := buildNodes( - ctx, db, row.Node, row.Node_2, + ctx, db, row.GraphNode, row.GraphNode_2, ) if err != nil { return fmt.Errorf("unable to fetch nodes: %w", @@ -2195,8 +2197,8 @@ func (s *SQLStore) FetchChanInfos(chanIDs []uint64) ([]ChannelEdge, error) { } edge, err := getAndBuildEdgeInfo( - ctx, db, s.cfg.ChainHash, row.Channel.ID, - row.Channel, node1.PubKeyBytes, + ctx, db, s.cfg.ChainHash, row.GraphChannel.ID, + row.GraphChannel, node1.PubKeyBytes, node2.PubKeyBytes, ) if err != nil { @@ -2385,14 +2387,14 @@ func (s *SQLStore) PruneGraph(spentOutputs []*wire.OutPoint, } info, err := getAndBuildEdgeInfo( - ctx, db, s.cfg.ChainHash, row.Channel.ID, - row.Channel, node1, node2, + ctx, db, s.cfg.ChainHash, row.GraphChannel.ID, + row.GraphChannel, node1, node2, ) if err != nil { return err } - err = db.DeleteChannel(ctx, row.Channel.ID) + err = db.DeleteChannel(ctx, row.GraphChannel.ID) if err != nil { return fmt.Errorf("unable to delete "+ "channel: %w", err) @@ -2621,14 +2623,14 @@ func (s *SQLStore) DisconnectBlockAtHeight(height uint32) ( } channel, err := getAndBuildEdgeInfo( - ctx, db, s.cfg.ChainHash, row.Channel.ID, - row.Channel, node1, node2, + ctx, db, s.cfg.ChainHash, row.GraphChannel.ID, + row.GraphChannel, node1, node2, ) if err != nil { return err } - err = db.DeleteChannel(ctx, row.Channel.ID) + err = db.DeleteChannel(ctx, row.GraphChannel.ID) if err != nil { return fmt.Errorf("unable to delete "+ "channel: %w", err) @@ -2863,7 +2865,9 @@ func forEachNodeDirectedChannel(ctx context.Context, db SQLQueries, err) } - edge := buildCacheableChannelInfo(row.Channel, node1, node2) + edge := buildCacheableChannelInfo( + row.GraphChannel, node1, node2, + ) dbPol1, dbPol2, err := extractChannelPolicies(row) if err != nil { @@ -3005,8 +3009,8 @@ func forEachNodeChannel(ctx context.Context, db SQLQueries, } edge, err := getAndBuildEdgeInfo( - ctx, db, chain, row.Channel.ID, row.Channel, node1, - node2, + ctx, db, chain, row.GraphChannel.ID, row.GraphChannel, + node1, node2, ) if err != nil { return fmt.Errorf("unable to build channel info: %w", @@ -3029,8 +3033,8 @@ func forEachNodeChannel(ctx context.Context, db SQLQueries, // Determine the outgoing and incoming policy for this // channel and node combo. - p1ToNode := row.Channel.NodeID2 - p2ToNode := row.Channel.NodeID1 + p1ToNode := row.GraphChannel.NodeID2 + p2ToNode := row.GraphChannel.NodeID1 outPolicy, inPolicy := p1, p2 if (p1 != nil && p1ToNode == id) || (p2 != nil && p2ToNode != id) { @@ -3167,7 +3171,7 @@ func getNodeByPubKey(ctx context.Context, db SQLQueries, // buildCacheableChannelInfo builds a models.CachedEdgeInfo instance from the // provided database channel row and the public keys of the two nodes // involved in the channel. -func buildCacheableChannelInfo(dbChan sqlc.Channel, node1Pub, +func buildCacheableChannelInfo(dbChan sqlc.GraphChannel, node1Pub, node2Pub route.Vertex) *models.CachedEdgeInfo { return &models.CachedEdgeInfo{ @@ -3181,7 +3185,7 @@ func buildCacheableChannelInfo(dbChan sqlc.Channel, node1Pub, // buildNode constructs a LightningNode instance from the given database node // record. The node's features, addresses and extra signed fields are also // fetched from the database and set on the node. -func buildNode(ctx context.Context, db SQLQueries, dbNode *sqlc.Node) ( +func buildNode(ctx context.Context, db SQLQueries, dbNode *sqlc.GraphNode) ( *models.LightningNode, error) { if dbNode.Version != int16(ProtocolV1) { @@ -3940,7 +3944,7 @@ func upsertChanPolicyExtraSignedFields(ctx context.Context, db SQLQueries, // provided dbChanRow and also fetches any other required information // to construct the edge info. func getAndBuildEdgeInfo(ctx context.Context, db SQLQueries, - chain chainhash.Hash, dbChanID int64, dbChan sqlc.Channel, node1, + chain chainhash.Hash, dbChanID int64, dbChan sqlc.GraphChannel, node1, node2 route.Vertex) (*models.ChannelEdgeInfo, error) { if dbChan.Version != int16(ProtocolV1) { @@ -4061,12 +4065,12 @@ func getChanFeaturesAndExtras(ctx context.Context, db SQLQueries, return fv, extras, nil } -// getAndBuildChanPolicies uses the given sqlc.ChannelPolicy and also retrieves -// all the extra info required to build the complete models.ChannelEdgePolicy -// types. It returns two policies, which may be nil if the provided -// sqlc.ChannelPolicy records are nil. +// getAndBuildChanPolicies uses the given sqlc.GraphChannelPolicy and also +// retrieves all the extra info required to build the complete +// models.ChannelEdgePolicy types. It returns two policies, which may be nil if +// the provided sqlc.GraphChannelPolicy records are nil. func getAndBuildChanPolicies(ctx context.Context, db SQLQueries, - dbPol1, dbPol2 *sqlc.ChannelPolicy, channelID uint64, node1, + dbPol1, dbPol2 *sqlc.GraphChannelPolicy, channelID uint64, node1, node2 route.Vertex) (*models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) { @@ -4132,8 +4136,8 @@ func getAndBuildChanPolicies(ctx context.Context, db SQLQueries, } // buildChanPolicy builds a models.ChannelEdgePolicy instance from the -// provided sqlc.ChannelPolicy and other required information. -func buildChanPolicy(dbPolicy sqlc.ChannelPolicy, channelID uint64, +// provided sqlc.GraphChannelPolicy and other required information. +func buildChanPolicy(dbPolicy sqlc.GraphChannelPolicy, channelID uint64, extras map[uint64][]byte, toNode route.Vertex) (*models.ChannelEdgePolicy, error) { @@ -4185,7 +4189,7 @@ func buildChanPolicy(dbPolicy sqlc.ChannelPolicy, channelID uint64, // buildNodes builds the models.LightningNode instances for the // given row which is expected to be a sqlc type that contains node information. func buildNodes(ctx context.Context, db SQLQueries, dbNode1, - dbNode2 sqlc.Node) (*models.LightningNode, *models.LightningNode, + dbNode2 sqlc.GraphNode) (*models.LightningNode, *models.LightningNode, error) { node1, err := buildNode(ctx, db, &dbNode1) @@ -4201,23 +4205,23 @@ func buildNodes(ctx context.Context, db SQLQueries, dbNode1, return node1, node2, nil } -// extractChannelPolicies extracts the sqlc.ChannelPolicy records from the give +// extractChannelPolicies extracts the sqlc.GraphChannelPolicy records from the give // row which is expected to be a sqlc type that contains channel policy // information. It returns two policies, which may be nil if the policy // information is not present in the row. // //nolint:ll,dupl,funlen -func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy, - error) { +func extractChannelPolicies(row any) (*sqlc.GraphChannelPolicy, + *sqlc.GraphChannelPolicy, error) { - var policy1, policy2 *sqlc.ChannelPolicy + var policy1, policy2 *sqlc.GraphChannelPolicy switch r := row.(type) { case sqlc.GetChannelByOutpointWithPoliciesRow: if r.Policy1ID.Valid { - policy1 = &sqlc.ChannelPolicy{ + policy1 = &sqlc.GraphChannelPolicy{ ID: r.Policy1ID.Int64, Version: r.Policy1Version.Int16, - ChannelID: r.Channel.ID, + ChannelID: r.GraphChannel.ID, NodeID: r.Policy1NodeID.Int64, Timelock: r.Policy1Timelock.Int32, FeePpm: r.Policy1FeePpm.Int64, @@ -4234,10 +4238,10 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy, } } if r.Policy2ID.Valid { - policy2 = &sqlc.ChannelPolicy{ + policy2 = &sqlc.GraphChannelPolicy{ ID: r.Policy2ID.Int64, Version: r.Policy2Version.Int16, - ChannelID: r.Channel.ID, + ChannelID: r.GraphChannel.ID, NodeID: r.Policy2NodeID.Int64, Timelock: r.Policy2Timelock.Int32, FeePpm: r.Policy2FeePpm.Int64, @@ -4258,10 +4262,10 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy, case sqlc.GetChannelBySCIDWithPoliciesRow: if r.Policy1ID.Valid { - policy1 = &sqlc.ChannelPolicy{ + policy1 = &sqlc.GraphChannelPolicy{ ID: r.Policy1ID.Int64, Version: r.Policy1Version.Int16, - ChannelID: r.Channel.ID, + ChannelID: r.GraphChannel.ID, NodeID: r.Policy1NodeID.Int64, Timelock: r.Policy1Timelock.Int32, FeePpm: r.Policy1FeePpm.Int64, @@ -4278,10 +4282,10 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy, } } if r.Policy2ID.Valid { - policy2 = &sqlc.ChannelPolicy{ + policy2 = &sqlc.GraphChannelPolicy{ ID: r.Policy2ID.Int64, Version: r.Policy2Version.Int16, - ChannelID: r.Channel.ID, + ChannelID: r.GraphChannel.ID, NodeID: r.Policy2NodeID.Int64, Timelock: r.Policy2Timelock.Int32, FeePpm: r.Policy2FeePpm.Int64, @@ -4302,10 +4306,10 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy, case sqlc.GetChannelsByPolicyLastUpdateRangeRow: if r.Policy1ID.Valid { - policy1 = &sqlc.ChannelPolicy{ + policy1 = &sqlc.GraphChannelPolicy{ ID: r.Policy1ID.Int64, Version: r.Policy1Version.Int16, - ChannelID: r.Channel.ID, + ChannelID: r.GraphChannel.ID, NodeID: r.Policy1NodeID.Int64, Timelock: r.Policy1Timelock.Int32, FeePpm: r.Policy1FeePpm.Int64, @@ -4322,10 +4326,10 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy, } } if r.Policy2ID.Valid { - policy2 = &sqlc.ChannelPolicy{ + policy2 = &sqlc.GraphChannelPolicy{ ID: r.Policy2ID.Int64, Version: r.Policy2Version.Int16, - ChannelID: r.Channel.ID, + ChannelID: r.GraphChannel.ID, NodeID: r.Policy2NodeID.Int64, Timelock: r.Policy2Timelock.Int32, FeePpm: r.Policy2FeePpm.Int64, @@ -4346,10 +4350,10 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy, case sqlc.ListChannelsByNodeIDRow: if r.Policy1ID.Valid { - policy1 = &sqlc.ChannelPolicy{ + policy1 = &sqlc.GraphChannelPolicy{ ID: r.Policy1ID.Int64, Version: r.Policy1Version.Int16, - ChannelID: r.Channel.ID, + ChannelID: r.GraphChannel.ID, NodeID: r.Policy1NodeID.Int64, Timelock: r.Policy1Timelock.Int32, FeePpm: r.Policy1FeePpm.Int64, @@ -4366,10 +4370,10 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy, } } if r.Policy2ID.Valid { - policy2 = &sqlc.ChannelPolicy{ + policy2 = &sqlc.GraphChannelPolicy{ ID: r.Policy2ID.Int64, Version: r.Policy2Version.Int16, - ChannelID: r.Channel.ID, + ChannelID: r.GraphChannel.ID, NodeID: r.Policy2NodeID.Int64, Timelock: r.Policy2Timelock.Int32, FeePpm: r.Policy2FeePpm.Int64, @@ -4390,10 +4394,10 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy, case sqlc.ListChannelsWithPoliciesPaginatedRow: if r.Policy1ID.Valid { - policy1 = &sqlc.ChannelPolicy{ + policy1 = &sqlc.GraphChannelPolicy{ ID: r.Policy1ID.Int64, Version: r.Policy1Version.Int16, - ChannelID: r.Channel.ID, + ChannelID: r.GraphChannel.ID, NodeID: r.Policy1NodeID.Int64, Timelock: r.Policy1Timelock.Int32, FeePpm: r.Policy1FeePpm.Int64, @@ -4410,10 +4414,10 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy, } } if r.Policy2ID.Valid { - policy2 = &sqlc.ChannelPolicy{ + policy2 = &sqlc.GraphChannelPolicy{ ID: r.Policy2ID.Int64, Version: r.Policy2Version.Int16, - ChannelID: r.Channel.ID, + ChannelID: r.GraphChannel.ID, NodeID: r.Policy2NodeID.Int64, Timelock: r.Policy2Timelock.Int32, FeePpm: r.Policy2FeePpm.Int64, diff --git a/sqldb/sqlc/graph.sql.go b/sqldb/sqlc/graph.sql.go index d6535e806..79c393880 100644 --- a/sqldb/sqlc/graph.sql.go +++ b/sqldb/sqlc/graph.sql.go @@ -12,11 +12,11 @@ import ( const addSourceNode = `-- name: AddSourceNode :exec /* ───────────────────────────────────────────── - source_nodes table queries + graph_source_nodes table queries ───────────────────────────────────────────── */ -INSERT INTO source_nodes (node_id) +INSERT INTO graph_source_nodes (node_id) VALUES ($1) ON CONFLICT (node_id) DO NOTHING ` @@ -27,7 +27,7 @@ func (q *Queries) AddSourceNode(ctx context.Context, nodeID int64) error { } const addV1ChannelProof = `-- name: AddV1ChannelProof :execresult -UPDATE channels +UPDATE graph_channels SET node_1_signature = $2, node_2_signature = $3, bitcoin_1_signature = $4, @@ -56,7 +56,7 @@ func (q *Queries) AddV1ChannelProof(ctx context.Context, arg AddV1ChannelProofPa const countZombieChannels = `-- name: CountZombieChannels :one SELECT COUNT(*) -FROM zombie_channels +FROM graph_zombie_channels WHERE version = $1 ` @@ -69,11 +69,11 @@ func (q *Queries) CountZombieChannels(ctx context.Context, version int16) (int64 const createChannel = `-- name: CreateChannel :one /* ───────────────────────────────────────────── - channels table queries + graph_channels table queries ───────────────────────────────────────────── */ -INSERT INTO channels ( +INSERT INTO graph_channels ( version, scid, node_id_1, node_id_2, outpoint, capacity, bitcoin_key_1, bitcoin_key_2, node_1_signature, node_2_signature, bitcoin_1_signature, @@ -121,11 +121,11 @@ func (q *Queries) CreateChannel(ctx context.Context, arg CreateChannelParams) (i const createChannelExtraType = `-- name: CreateChannelExtraType :exec /* ───────────────────────────────────────────── - channel_extra_types table queries + graph_channel_extra_types table queries ───────────────────────────────────────────── */ -INSERT INTO channel_extra_types ( +INSERT INTO graph_channel_extra_types ( channel_id, type, value ) VALUES ($1, $2, $3) @@ -143,7 +143,7 @@ func (q *Queries) CreateChannelExtraType(ctx context.Context, arg CreateChannelE } const deleteChannel = `-- name: DeleteChannel :exec -DELETE FROM channels WHERE id = $1 +DELETE FROM graph_channels WHERE id = $1 ` func (q *Queries) DeleteChannel(ctx context.Context, id int64) error { @@ -152,7 +152,7 @@ func (q *Queries) DeleteChannel(ctx context.Context, id int64) error { } const deleteChannelPolicyExtraTypes = `-- name: DeleteChannelPolicyExtraTypes :exec -DELETE FROM channel_policy_extra_types +DELETE FROM graph_channel_policy_extra_types WHERE channel_policy_id = $1 ` @@ -162,7 +162,7 @@ func (q *Queries) DeleteChannelPolicyExtraTypes(ctx context.Context, channelPoli } const deleteExtraNodeType = `-- name: DeleteExtraNodeType :exec -DELETE FROM node_extra_types +DELETE FROM graph_node_extra_types WHERE node_id = $1 AND type = $2 ` @@ -178,7 +178,7 @@ func (q *Queries) DeleteExtraNodeType(ctx context.Context, arg DeleteExtraNodeTy } const deleteNode = `-- name: DeleteNode :exec -DELETE FROM nodes +DELETE FROM graph_nodes WHERE id = $1 ` @@ -188,7 +188,7 @@ func (q *Queries) DeleteNode(ctx context.Context, id int64) error { } const deleteNodeAddresses = `-- name: DeleteNodeAddresses :exec -DELETE FROM node_addresses +DELETE FROM graph_node_addresses WHERE node_id = $1 ` @@ -198,7 +198,7 @@ func (q *Queries) DeleteNodeAddresses(ctx context.Context, nodeID int64) error { } const deleteNodeByPubKey = `-- name: DeleteNodeByPubKey :execresult -DELETE FROM nodes +DELETE FROM graph_nodes WHERE pub_key = $1 AND version = $2 ` @@ -213,7 +213,7 @@ func (q *Queries) DeleteNodeByPubKey(ctx context.Context, arg DeleteNodeByPubKey } const deleteNodeFeature = `-- name: DeleteNodeFeature :exec -DELETE FROM node_features +DELETE FROM graph_node_features WHERE node_id = $1 AND feature_bit = $2 ` @@ -229,7 +229,7 @@ func (q *Queries) DeleteNodeFeature(ctx context.Context, arg DeleteNodeFeaturePa } const deletePruneLogEntriesInRange = `-- name: DeletePruneLogEntriesInRange :exec -DELETE FROM prune_log +DELETE FROM graph_prune_log WHERE block_height >= $1 AND block_height <= $2 ` @@ -245,19 +245,19 @@ func (q *Queries) DeletePruneLogEntriesInRange(ctx context.Context, arg DeletePr } const deleteUnconnectedNodes = `-- name: DeleteUnconnectedNodes :many -DELETE FROM nodes +DELETE FROM graph_nodes WHERE -- Ignore any of our source nodes. NOT EXISTS ( SELECT 1 - FROM source_nodes sn - WHERE sn.node_id = nodes.id + FROM graph_source_nodes sn + WHERE sn.node_id = graph_nodes.id ) -- Select all nodes that do not have any channels. AND NOT EXISTS ( SELECT 1 - FROM channels c - WHERE c.node_id_1 = nodes.id OR c.node_id_2 = nodes.id + FROM graph_channels c + WHERE c.node_id_1 = graph_nodes.id OR c.node_id_2 = graph_nodes.id ) RETURNING pub_key ` @@ -285,7 +285,7 @@ func (q *Queries) DeleteUnconnectedNodes(ctx context.Context) ([][]byte, error) } const deleteZombieChannel = `-- name: DeleteZombieChannel :execresult -DELETE FROM zombie_channels +DELETE FROM graph_zombie_channels WHERE scid = $1 AND version = $2 ` @@ -304,9 +304,9 @@ SELECT c.id, c.version, c.scid, c.node_id_1, c.node_id_2, c.outpoint, c.capacity, c.bitcoin_key_1, c.bitcoin_key_2, c.node_1_signature, c.node_2_signature, c.bitcoin_1_signature, c.bitcoin_2_signature, n1.pub_key AS node1_pub_key, n2.pub_key AS node2_pub_key -FROM channels c - JOIN nodes n1 ON c.node_id_1 = n1.id - JOIN nodes n2 ON c.node_id_2 = n2.id +FROM graph_channels c + JOIN graph_nodes n1 ON c.node_id_1 = n1.id + JOIN graph_nodes n2 ON c.node_id_2 = n2.id WHERE c.scid = $1 AND c.version = $2 ` @@ -362,35 +362,35 @@ SELECT c.id, c.version, c.scid, c.node_id_1, c.node_id_2, c.outpoint, c.capacity, c.bitcoin_key_1, c.bitcoin_key_2, c.node_1_signature, c.node_2_signature, c.bitcoin_1_signature, c.bitcoin_2_signature, n1.pub_key AS node1_pubkey, n2.pub_key AS node2_pubkey -FROM channels c - JOIN nodes n1 ON c.node_id_1 = n1.id - JOIN nodes n2 ON c.node_id_2 = n2.id +FROM graph_channels c + JOIN graph_nodes n1 ON c.node_id_1 = n1.id + JOIN graph_nodes n2 ON c.node_id_2 = n2.id WHERE c.outpoint = $1 ` type GetChannelByOutpointRow struct { - Channel Channel - Node1Pubkey []byte - Node2Pubkey []byte + GraphChannel GraphChannel + Node1Pubkey []byte + Node2Pubkey []byte } func (q *Queries) GetChannelByOutpoint(ctx context.Context, outpoint string) (GetChannelByOutpointRow, error) { row := q.db.QueryRowContext(ctx, getChannelByOutpoint, outpoint) var i GetChannelByOutpointRow err := row.Scan( - &i.Channel.ID, - &i.Channel.Version, - &i.Channel.Scid, - &i.Channel.NodeID1, - &i.Channel.NodeID2, - &i.Channel.Outpoint, - &i.Channel.Capacity, - &i.Channel.BitcoinKey1, - &i.Channel.BitcoinKey2, - &i.Channel.Node1Signature, - &i.Channel.Node2Signature, - &i.Channel.Bitcoin1Signature, - &i.Channel.Bitcoin2Signature, + &i.GraphChannel.ID, + &i.GraphChannel.Version, + &i.GraphChannel.Scid, + &i.GraphChannel.NodeID1, + &i.GraphChannel.NodeID2, + &i.GraphChannel.Outpoint, + &i.GraphChannel.Capacity, + &i.GraphChannel.BitcoinKey1, + &i.GraphChannel.BitcoinKey2, + &i.GraphChannel.Node1Signature, + &i.GraphChannel.Node2Signature, + &i.GraphChannel.Bitcoin1Signature, + &i.GraphChannel.Bitcoin2Signature, &i.Node1Pubkey, &i.Node2Pubkey, ) @@ -437,12 +437,12 @@ SELECT cp2.message_flags AS policy_2_message_flags, cp2.channel_flags AS policy_2_channel_flags, cp2.signature AS policy_2_signature -FROM channels c - JOIN nodes n1 ON c.node_id_1 = n1.id - JOIN nodes n2 ON c.node_id_2 = n2.id - LEFT JOIN channel_policies cp1 +FROM graph_channels c + JOIN graph_nodes n1 ON c.node_id_1 = n1.id + JOIN graph_nodes n2 ON c.node_id_2 = n2.id + LEFT JOIN graph_channel_policies cp1 ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version - LEFT JOIN channel_policies cp2 + LEFT JOIN graph_channel_policies cp2 ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version WHERE c.outpoint = $1 AND c.version = $2 ` @@ -453,7 +453,7 @@ type GetChannelByOutpointWithPoliciesParams struct { } type GetChannelByOutpointWithPoliciesRow struct { - Channel Channel + GraphChannel GraphChannel Node1Pubkey []byte Node2Pubkey []byte Policy1ID sql.NullInt64 @@ -492,19 +492,19 @@ func (q *Queries) GetChannelByOutpointWithPolicies(ctx context.Context, arg GetC row := q.db.QueryRowContext(ctx, getChannelByOutpointWithPolicies, arg.Outpoint, arg.Version) var i GetChannelByOutpointWithPoliciesRow err := row.Scan( - &i.Channel.ID, - &i.Channel.Version, - &i.Channel.Scid, - &i.Channel.NodeID1, - &i.Channel.NodeID2, - &i.Channel.Outpoint, - &i.Channel.Capacity, - &i.Channel.BitcoinKey1, - &i.Channel.BitcoinKey2, - &i.Channel.Node1Signature, - &i.Channel.Node2Signature, - &i.Channel.Bitcoin1Signature, - &i.Channel.Bitcoin2Signature, + &i.GraphChannel.ID, + &i.GraphChannel.Version, + &i.GraphChannel.Scid, + &i.GraphChannel.NodeID1, + &i.GraphChannel.NodeID2, + &i.GraphChannel.Outpoint, + &i.GraphChannel.Capacity, + &i.GraphChannel.BitcoinKey1, + &i.GraphChannel.BitcoinKey2, + &i.GraphChannel.Node1Signature, + &i.GraphChannel.Node2Signature, + &i.GraphChannel.Bitcoin1Signature, + &i.GraphChannel.Bitcoin2Signature, &i.Node1Pubkey, &i.Node2Pubkey, &i.Policy1ID, @@ -542,7 +542,7 @@ func (q *Queries) GetChannelByOutpointWithPolicies(ctx context.Context, arg GetC } const getChannelBySCID = `-- name: GetChannelBySCID :one -SELECT id, version, scid, node_id_1, node_id_2, outpoint, capacity, bitcoin_key_1, bitcoin_key_2, node_1_signature, node_2_signature, bitcoin_1_signature, bitcoin_2_signature FROM channels +SELECT id, version, scid, node_id_1, node_id_2, outpoint, capacity, bitcoin_key_1, bitcoin_key_2, node_1_signature, node_2_signature, bitcoin_1_signature, bitcoin_2_signature FROM graph_channels WHERE scid = $1 AND version = $2 ` @@ -551,9 +551,9 @@ type GetChannelBySCIDParams struct { Version int16 } -func (q *Queries) GetChannelBySCID(ctx context.Context, arg GetChannelBySCIDParams) (Channel, error) { +func (q *Queries) GetChannelBySCID(ctx context.Context, arg GetChannelBySCIDParams) (GraphChannel, error) { row := q.db.QueryRowContext(ctx, getChannelBySCID, arg.Scid, arg.Version) - var i Channel + var i GraphChannel err := row.Scan( &i.ID, &i.Version, @@ -612,12 +612,12 @@ SELECT cp2.channel_flags AS policy_2_channel_flags, cp2.signature AS policy2_signature -FROM channels c - JOIN nodes n1 ON c.node_id_1 = n1.id - JOIN nodes n2 ON c.node_id_2 = n2.id - LEFT JOIN channel_policies cp1 +FROM graph_channels c + JOIN graph_nodes n1 ON c.node_id_1 = n1.id + JOIN graph_nodes n2 ON c.node_id_2 = n2.id + LEFT JOIN graph_channel_policies cp1 ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version - LEFT JOIN channel_policies cp2 + LEFT JOIN graph_channel_policies cp2 ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version WHERE c.scid = $1 AND c.version = $2 @@ -629,9 +629,9 @@ type GetChannelBySCIDWithPoliciesParams struct { } type GetChannelBySCIDWithPoliciesRow struct { - Channel Channel - Node Node - Node_2 Node + GraphChannel GraphChannel + GraphNode GraphNode + GraphNode_2 GraphNode Policy1ID sql.NullInt64 Policy1NodeID sql.NullInt64 Policy1Version sql.NullInt16 @@ -668,33 +668,33 @@ func (q *Queries) GetChannelBySCIDWithPolicies(ctx context.Context, arg GetChann row := q.db.QueryRowContext(ctx, getChannelBySCIDWithPolicies, arg.Scid, arg.Version) var i GetChannelBySCIDWithPoliciesRow err := row.Scan( - &i.Channel.ID, - &i.Channel.Version, - &i.Channel.Scid, - &i.Channel.NodeID1, - &i.Channel.NodeID2, - &i.Channel.Outpoint, - &i.Channel.Capacity, - &i.Channel.BitcoinKey1, - &i.Channel.BitcoinKey2, - &i.Channel.Node1Signature, - &i.Channel.Node2Signature, - &i.Channel.Bitcoin1Signature, - &i.Channel.Bitcoin2Signature, - &i.Node.ID, - &i.Node.Version, - &i.Node.PubKey, - &i.Node.Alias, - &i.Node.LastUpdate, - &i.Node.Color, - &i.Node.Signature, - &i.Node_2.ID, - &i.Node_2.Version, - &i.Node_2.PubKey, - &i.Node_2.Alias, - &i.Node_2.LastUpdate, - &i.Node_2.Color, - &i.Node_2.Signature, + &i.GraphChannel.ID, + &i.GraphChannel.Version, + &i.GraphChannel.Scid, + &i.GraphChannel.NodeID1, + &i.GraphChannel.NodeID2, + &i.GraphChannel.Outpoint, + &i.GraphChannel.Capacity, + &i.GraphChannel.BitcoinKey1, + &i.GraphChannel.BitcoinKey2, + &i.GraphChannel.Node1Signature, + &i.GraphChannel.Node2Signature, + &i.GraphChannel.Bitcoin1Signature, + &i.GraphChannel.Bitcoin2Signature, + &i.GraphNode.ID, + &i.GraphNode.Version, + &i.GraphNode.PubKey, + &i.GraphNode.Alias, + &i.GraphNode.LastUpdate, + &i.GraphNode.Color, + &i.GraphNode.Signature, + &i.GraphNode_2.ID, + &i.GraphNode_2.Version, + &i.GraphNode_2.PubKey, + &i.GraphNode_2.Alias, + &i.GraphNode_2.LastUpdate, + &i.GraphNode_2.Color, + &i.GraphNode_2.Signature, &i.Policy1ID, &i.Policy1NodeID, &i.Policy1Version, @@ -736,7 +736,7 @@ SELECT cf.feature_bit AS feature_bit, NULL AS extra_key, NULL AS value -FROM channel_features cf +FROM graph_channel_features cf WHERE cf.channel_id = $1 UNION ALL @@ -747,7 +747,7 @@ SELECT 0 AS feature_bit, cet.type AS extra_key, cet.value AS value -FROM channel_extra_types cet +FROM graph_channel_extra_types cet WHERE cet.channel_id = $1 ` @@ -790,7 +790,7 @@ func (q *Queries) GetChannelFeaturesAndExtras(ctx context.Context, channelID int const getChannelPolicyByChannelAndNode = `-- name: GetChannelPolicyByChannelAndNode :one SELECT id, version, channel_id, node_id, timelock, fee_ppm, base_fee_msat, min_htlc_msat, max_htlc_msat, last_update, disabled, inbound_base_fee_msat, inbound_fee_rate_milli_msat, message_flags, channel_flags, signature -FROM channel_policies +FROM graph_channel_policies WHERE channel_id = $1 AND node_id = $2 AND version = $3 @@ -802,9 +802,9 @@ type GetChannelPolicyByChannelAndNodeParams struct { Version int16 } -func (q *Queries) GetChannelPolicyByChannelAndNode(ctx context.Context, arg GetChannelPolicyByChannelAndNodeParams) (ChannelPolicy, error) { +func (q *Queries) GetChannelPolicyByChannelAndNode(ctx context.Context, arg GetChannelPolicyByChannelAndNodeParams) (GraphChannelPolicy, error) { row := q.db.QueryRowContext(ctx, getChannelPolicyByChannelAndNode, arg.ChannelID, arg.NodeID, arg.Version) - var i ChannelPolicy + var i GraphChannelPolicy err := row.Scan( &i.ID, &i.Version, @@ -833,8 +833,8 @@ SELECT cp.node_id, cpet.type, cpet.value -FROM channel_policies cp -JOIN channel_policy_extra_types cpet +FROM graph_channel_policies cp +JOIN graph_channel_policy_extra_types cpet ON cp.id = cpet.channel_policy_id WHERE cp.id = $1 OR cp.id = $2 ` @@ -921,12 +921,12 @@ SELECT cp2.channel_flags AS policy2_channel_flags, cp2.signature AS policy2_signature -FROM channels c - JOIN nodes n1 ON c.node_id_1 = n1.id - JOIN nodes n2 ON c.node_id_2 = n2.id - LEFT JOIN channel_policies cp1 +FROM graph_channels c + JOIN graph_nodes n1 ON c.node_id_1 = n1.id + JOIN graph_nodes n2 ON c.node_id_2 = n2.id + LEFT JOIN graph_channel_policies cp1 ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version - LEFT JOIN channel_policies cp2 + LEFT JOIN graph_channel_policies cp2 ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version WHERE c.version = $1 AND ( @@ -949,9 +949,9 @@ type GetChannelsByPolicyLastUpdateRangeParams struct { } type GetChannelsByPolicyLastUpdateRangeRow struct { - Channel Channel - Node Node - Node_2 Node + GraphChannel GraphChannel + GraphNode GraphNode + GraphNode_2 GraphNode Policy1ID sql.NullInt64 Policy1NodeID sql.NullInt64 Policy1Version sql.NullInt16 @@ -994,33 +994,33 @@ func (q *Queries) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg Ge for rows.Next() { var i GetChannelsByPolicyLastUpdateRangeRow if err := rows.Scan( - &i.Channel.ID, - &i.Channel.Version, - &i.Channel.Scid, - &i.Channel.NodeID1, - &i.Channel.NodeID2, - &i.Channel.Outpoint, - &i.Channel.Capacity, - &i.Channel.BitcoinKey1, - &i.Channel.BitcoinKey2, - &i.Channel.Node1Signature, - &i.Channel.Node2Signature, - &i.Channel.Bitcoin1Signature, - &i.Channel.Bitcoin2Signature, - &i.Node.ID, - &i.Node.Version, - &i.Node.PubKey, - &i.Node.Alias, - &i.Node.LastUpdate, - &i.Node.Color, - &i.Node.Signature, - &i.Node_2.ID, - &i.Node_2.Version, - &i.Node_2.PubKey, - &i.Node_2.Alias, - &i.Node_2.LastUpdate, - &i.Node_2.Color, - &i.Node_2.Signature, + &i.GraphChannel.ID, + &i.GraphChannel.Version, + &i.GraphChannel.Scid, + &i.GraphChannel.NodeID1, + &i.GraphChannel.NodeID2, + &i.GraphChannel.Outpoint, + &i.GraphChannel.Capacity, + &i.GraphChannel.BitcoinKey1, + &i.GraphChannel.BitcoinKey2, + &i.GraphChannel.Node1Signature, + &i.GraphChannel.Node2Signature, + &i.GraphChannel.Bitcoin1Signature, + &i.GraphChannel.Bitcoin2Signature, + &i.GraphNode.ID, + &i.GraphNode.Version, + &i.GraphNode.PubKey, + &i.GraphNode.Alias, + &i.GraphNode.LastUpdate, + &i.GraphNode.Color, + &i.GraphNode.Signature, + &i.GraphNode_2.ID, + &i.GraphNode_2.Version, + &i.GraphNode_2.PubKey, + &i.GraphNode_2.Alias, + &i.GraphNode_2.LastUpdate, + &i.GraphNode_2.Color, + &i.GraphNode_2.Signature, &i.Policy1ID, &i.Policy1NodeID, &i.Policy1Version, @@ -1069,9 +1069,9 @@ const getChannelsBySCIDRange = `-- name: GetChannelsBySCIDRange :many SELECT c.id, c.version, c.scid, c.node_id_1, c.node_id_2, c.outpoint, c.capacity, c.bitcoin_key_1, c.bitcoin_key_2, c.node_1_signature, c.node_2_signature, c.bitcoin_1_signature, c.bitcoin_2_signature, n1.pub_key AS node1_pub_key, n2.pub_key AS node2_pub_key -FROM channels c - JOIN nodes n1 ON c.node_id_1 = n1.id - JOIN nodes n2 ON c.node_id_2 = n2.id +FROM graph_channels c + JOIN graph_nodes n1 ON c.node_id_1 = n1.id + JOIN graph_nodes n2 ON c.node_id_2 = n2.id WHERE scid >= $1 AND scid < $2 ` @@ -1082,9 +1082,9 @@ type GetChannelsBySCIDRangeParams struct { } type GetChannelsBySCIDRangeRow struct { - Channel Channel - Node1PubKey []byte - Node2PubKey []byte + GraphChannel GraphChannel + Node1PubKey []byte + Node2PubKey []byte } func (q *Queries) GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error) { @@ -1097,19 +1097,19 @@ func (q *Queries) GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsByS for rows.Next() { var i GetChannelsBySCIDRangeRow if err := rows.Scan( - &i.Channel.ID, - &i.Channel.Version, - &i.Channel.Scid, - &i.Channel.NodeID1, - &i.Channel.NodeID2, - &i.Channel.Outpoint, - &i.Channel.Capacity, - &i.Channel.BitcoinKey1, - &i.Channel.BitcoinKey2, - &i.Channel.Node1Signature, - &i.Channel.Node2Signature, - &i.Channel.Bitcoin1Signature, - &i.Channel.Bitcoin2Signature, + &i.GraphChannel.ID, + &i.GraphChannel.Version, + &i.GraphChannel.Scid, + &i.GraphChannel.NodeID1, + &i.GraphChannel.NodeID2, + &i.GraphChannel.Outpoint, + &i.GraphChannel.Capacity, + &i.GraphChannel.BitcoinKey1, + &i.GraphChannel.BitcoinKey2, + &i.GraphChannel.Node1Signature, + &i.GraphChannel.Node2Signature, + &i.GraphChannel.Bitcoin1Signature, + &i.GraphChannel.Bitcoin2Signature, &i.Node1PubKey, &i.Node2PubKey, ); err != nil { @@ -1128,19 +1128,19 @@ func (q *Queries) GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsByS const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many SELECT node_id, type, value -FROM node_extra_types +FROM graph_node_extra_types WHERE node_id = $1 ` -func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]NodeExtraType, error) { +func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]GraphNodeExtraType, error) { rows, err := q.db.QueryContext(ctx, getExtraNodeTypes, nodeID) if err != nil { return nil, err } defer rows.Close() - var items []NodeExtraType + var items []GraphNodeExtraType for rows.Next() { - var i NodeExtraType + var i GraphNodeExtraType if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil { return nil, err } @@ -1157,8 +1157,8 @@ func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]NodeEx const getNodeAddressesByPubKey = `-- name: GetNodeAddressesByPubKey :many SELECT a.type, a.address -FROM nodes n -LEFT JOIN node_addresses a ON a.node_id = n.id +FROM graph_nodes n +LEFT JOIN graph_node_addresses a ON a.node_id = n.id WHERE n.pub_key = $1 AND n.version = $2 ORDER BY a.type ASC, a.position ASC ` @@ -1198,7 +1198,7 @@ func (q *Queries) GetNodeAddressesByPubKey(ctx context.Context, arg GetNodeAddre const getNodeByPubKey = `-- name: GetNodeByPubKey :one SELECT id, version, pub_key, alias, last_update, color, signature -FROM nodes +FROM graph_nodes WHERE pub_key = $1 AND version = $2 ` @@ -1208,9 +1208,9 @@ type GetNodeByPubKeyParams struct { Version int16 } -func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (Node, error) { +func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (GraphNode, error) { row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version) - var i Node + var i GraphNode err := row.Scan( &i.ID, &i.Version, @@ -1225,19 +1225,19 @@ func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams const getNodeFeatures = `-- name: GetNodeFeatures :many SELECT node_id, feature_bit -FROM node_features +FROM graph_node_features WHERE node_id = $1 ` -func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]NodeFeature, error) { +func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]GraphNodeFeature, error) { rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID) if err != nil { return nil, err } defer rows.Close() - var items []NodeFeature + var items []GraphNodeFeature for rows.Next() { - var i NodeFeature + var i GraphNodeFeature if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil { return nil, err } @@ -1254,8 +1254,8 @@ func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]NodeFeat const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many SELECT f.feature_bit -FROM nodes n - JOIN node_features f ON f.node_id = n.id +FROM graph_nodes n + JOIN graph_node_features f ON f.node_id = n.id WHERE n.pub_key = $1 AND n.version = $2 ` @@ -1290,7 +1290,7 @@ func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeatur const getNodeIDByPubKey = `-- name: GetNodeIDByPubKey :one SELECT id -FROM nodes +FROM graph_nodes WHERE pub_key = $1 AND version = $2 ` @@ -1309,7 +1309,7 @@ func (q *Queries) GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyPa const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many SELECT id, version, pub_key, alias, last_update, color, signature -FROM nodes +FROM graph_nodes WHERE last_update >= $1 AND last_update < $2 ` @@ -1319,15 +1319,15 @@ type GetNodesByLastUpdateRangeParams struct { EndTime sql.NullInt64 } -func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]Node, error) { +func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]GraphNode, error) { rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange, arg.StartTime, arg.EndTime) if err != nil { return nil, err } defer rows.Close() - var items []Node + var items []GraphNode for rows.Next() { - var i Node + var i GraphNode if err := rows.Scan( &i.ID, &i.Version, @@ -1352,7 +1352,7 @@ func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByL const getPruneHashByHeight = `-- name: GetPruneHashByHeight :one SELECT block_hash -FROM prune_log +FROM graph_prune_log WHERE block_height = $1 ` @@ -1365,21 +1365,21 @@ func (q *Queries) GetPruneHashByHeight(ctx context.Context, blockHeight int64) ( const getPruneTip = `-- name: GetPruneTip :one SELECT block_height, block_hash -FROM prune_log +FROM graph_prune_log ORDER BY block_height DESC LIMIT 1 ` -func (q *Queries) GetPruneTip(ctx context.Context) (PruneLog, error) { +func (q *Queries) GetPruneTip(ctx context.Context) (GraphPruneLog, error) { row := q.db.QueryRowContext(ctx, getPruneTip) - var i PruneLog + var i GraphPruneLog err := row.Scan(&i.BlockHeight, &i.BlockHash) return i, err } const getPublicV1ChannelsBySCID = `-- name: GetPublicV1ChannelsBySCID :many SELECT id, version, scid, node_id_1, node_id_2, outpoint, capacity, bitcoin_key_1, bitcoin_key_2, node_1_signature, node_2_signature, bitcoin_1_signature, bitcoin_2_signature -FROM channels +FROM graph_channels WHERE node_1_signature IS NOT NULL AND scid >= $1 AND scid < $2 @@ -1390,15 +1390,15 @@ type GetPublicV1ChannelsBySCIDParams struct { EndScid []byte } -func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]Channel, error) { +func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]GraphChannel, error) { rows, err := q.db.QueryContext(ctx, getPublicV1ChannelsBySCID, arg.StartScid, arg.EndScid) if err != nil { return nil, err } defer rows.Close() - var items []Channel + var items []GraphChannel for rows.Next() { - var i Channel + var i GraphChannel if err := rows.Scan( &i.ID, &i.Version, @@ -1428,7 +1428,7 @@ func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1 } const getSCIDByOutpoint = `-- name: GetSCIDByOutpoint :one -SELECT scid from channels +SELECT scid from graph_channels WHERE outpoint = $1 AND version = $2 ` @@ -1446,8 +1446,8 @@ func (q *Queries) GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointPa const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many SELECT sn.node_id, n.pub_key -FROM source_nodes sn - JOIN nodes n ON sn.node_id = n.id +FROM graph_source_nodes sn + JOIN graph_nodes n ON sn.node_id = n.id WHERE n.version = $1 ` @@ -1481,8 +1481,8 @@ func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([ const getV1DisabledSCIDs = `-- name: GetV1DisabledSCIDs :many SELECT c.scid -FROM channels c - JOIN channel_policies cp ON cp.channel_id = c.id +FROM graph_channels c + JOIN graph_channel_policies cp ON cp.channel_id = c.id WHERE cp.disabled = true AND c.version = 1 GROUP BY c.scid @@ -1518,7 +1518,7 @@ func (q *Queries) GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) { const getZombieChannel = `-- name: GetZombieChannel :one SELECT scid, version, node_key_1, node_key_2 -FROM zombie_channels +FROM graph_zombie_channels WHERE scid = $1 AND version = $2 ` @@ -1528,9 +1528,9 @@ type GetZombieChannelParams struct { Version int16 } -func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (ZombieChannel, error) { +func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (GraphZombieChannel, error) { row := q.db.QueryRowContext(ctx, getZombieChannel, arg.Scid, arg.Version) - var i ZombieChannel + var i GraphZombieChannel err := row.Scan( &i.Scid, &i.Version, @@ -1542,7 +1542,7 @@ func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelPara const highestSCID = `-- name: HighestSCID :one SELECT scid -FROM channels +FROM graph_channels WHERE version = $1 ORDER BY scid DESC LIMIT 1 @@ -1557,11 +1557,11 @@ func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error const insertChanPolicyExtraType = `-- name: InsertChanPolicyExtraType :exec /* ───────────────────────────────────────────── - channel_policy_extra_types table queries + graph_channel_policy_extra_types table queries ───────────────────────────────────────────── */ -INSERT INTO channel_policy_extra_types ( +INSERT INTO graph_channel_policy_extra_types ( channel_policy_id, type, value ) VALUES ($1, $2, $3) @@ -1580,11 +1580,11 @@ func (q *Queries) InsertChanPolicyExtraType(ctx context.Context, arg InsertChanP const insertChannelFeature = `-- name: InsertChannelFeature :exec /* ───────────────────────────────────────────── - channel_features table queries + graph_channel_features table queries ───────────────────────────────────────────── */ -INSERT INTO channel_features ( +INSERT INTO graph_channel_features ( channel_id, feature_bit ) VALUES ( $1, $2 @@ -1603,11 +1603,11 @@ func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFea const insertClosedChannel = `-- name: InsertClosedChannel :exec /* ───────────────────────────────────────────── - closed_scid table queries + graph_closed_scid table queries ────────────────────────────────────────────- */ -INSERT INTO closed_scids (scid) +INSERT INTO graph_closed_scids (scid) VALUES ($1) ON CONFLICT (scid) DO NOTHING ` @@ -1619,11 +1619,11 @@ func (q *Queries) InsertClosedChannel(ctx context.Context, scid []byte) error { const insertNodeAddress = `-- name: InsertNodeAddress :exec /* ───────────────────────────────────────────── - node_addresses table queries - ───────────────────────────────────────────── + graph_node_addresses table queries + ───────────────────────────────────��───────── */ -INSERT INTO node_addresses ( +INSERT INTO graph_node_addresses ( node_id, type, address, @@ -1652,11 +1652,11 @@ func (q *Queries) InsertNodeAddress(ctx context.Context, arg InsertNodeAddressPa const insertNodeFeature = `-- name: InsertNodeFeature :exec /* ───────────────────────────────────────────── - node_features table queries + graph_node_features table queries ───────────────────────────────────────────── */ -INSERT INTO node_features ( +INSERT INTO graph_node_features ( node_id, feature_bit ) VALUES ( $1, $2 @@ -1676,7 +1676,7 @@ func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeaturePa const isClosedChannel = `-- name: IsClosedChannel :one SELECT EXISTS ( SELECT 1 - FROM closed_scids + FROM graph_closed_scids WHERE scid = $1 ) ` @@ -1691,8 +1691,8 @@ func (q *Queries) IsClosedChannel(ctx context.Context, scid []byte) (bool, error const isPublicV1Node = `-- name: IsPublicV1Node :one SELECT EXISTS ( SELECT 1 - FROM channels c - JOIN nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2 + FROM graph_channels c + JOIN graph_nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2 -- NOTE: we hard-code the version here since the clauses -- here that determine if a node is public is specific -- to the V1 gossip protocol. In V1, a node is public @@ -1717,7 +1717,7 @@ func (q *Queries) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, erro const isZombieChannel = `-- name: IsZombieChannel :one SELECT EXISTS ( SELECT 1 - FROM zombie_channels + FROM graph_zombie_channels WHERE scid = $1 AND version = $2 ) AS is_zombie @@ -1777,12 +1777,12 @@ SELECT c.id, c.version, c.scid, c.node_id_1, c.node_id_2, c.outpoint, c.capacity cp2.channel_flags AS policy2_channel_flags, cp2.signature AS policy2_signature -FROM channels c - JOIN nodes n1 ON c.node_id_1 = n1.id - JOIN nodes n2 ON c.node_id_2 = n2.id - LEFT JOIN channel_policies cp1 +FROM graph_channels c + JOIN graph_nodes n1 ON c.node_id_1 = n1.id + JOIN graph_nodes n2 ON c.node_id_2 = n2.id + LEFT JOIN graph_channel_policies cp1 ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version - LEFT JOIN channel_policies cp2 + LEFT JOIN graph_channel_policies cp2 ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version WHERE c.version = $1 AND (c.node_id_1 = $2 OR c.node_id_2 = $2) @@ -1794,7 +1794,7 @@ type ListChannelsByNodeIDParams struct { } type ListChannelsByNodeIDRow struct { - Channel Channel + GraphChannel GraphChannel Node1Pubkey []byte Node2Pubkey []byte Policy1ID sql.NullInt64 @@ -1839,19 +1839,19 @@ func (q *Queries) ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNo for rows.Next() { var i ListChannelsByNodeIDRow if err := rows.Scan( - &i.Channel.ID, - &i.Channel.Version, - &i.Channel.Scid, - &i.Channel.NodeID1, - &i.Channel.NodeID2, - &i.Channel.Outpoint, - &i.Channel.Capacity, - &i.Channel.BitcoinKey1, - &i.Channel.BitcoinKey2, - &i.Channel.Node1Signature, - &i.Channel.Node2Signature, - &i.Channel.Bitcoin1Signature, - &i.Channel.Bitcoin2Signature, + &i.GraphChannel.ID, + &i.GraphChannel.Version, + &i.GraphChannel.Scid, + &i.GraphChannel.NodeID1, + &i.GraphChannel.NodeID2, + &i.GraphChannel.Outpoint, + &i.GraphChannel.Capacity, + &i.GraphChannel.BitcoinKey1, + &i.GraphChannel.BitcoinKey2, + &i.GraphChannel.Node1Signature, + &i.GraphChannel.Node2Signature, + &i.GraphChannel.Bitcoin1Signature, + &i.GraphChannel.Bitcoin2Signature, &i.Node1Pubkey, &i.Node2Pubkey, &i.Policy1ID, @@ -1900,7 +1900,7 @@ func (q *Queries) ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNo const listChannelsPaginated = `-- name: ListChannelsPaginated :many SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint -FROM channels c +FROM graph_channels c WHERE c.version = $1 AND c.id > $2 ORDER BY c.id LIMIT $3 @@ -1989,12 +1989,12 @@ SELECT cp2.channel_flags AS policy2_channel_flags, cp2.signature AS policy_2_signature -FROM channels c -JOIN nodes n1 ON c.node_id_1 = n1.id -JOIN nodes n2 ON c.node_id_2 = n2.id -LEFT JOIN channel_policies cp1 +FROM graph_channels c +JOIN graph_nodes n1 ON c.node_id_1 = n1.id +JOIN graph_nodes n2 ON c.node_id_2 = n2.id +LEFT JOIN graph_channel_policies cp1 ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version -LEFT JOIN channel_policies cp2 +LEFT JOIN graph_channel_policies cp2 ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version WHERE c.version = $1 AND c.id > $2 ORDER BY c.id @@ -2008,7 +2008,7 @@ type ListChannelsWithPoliciesPaginatedParams struct { } type ListChannelsWithPoliciesPaginatedRow struct { - Channel Channel + GraphChannel GraphChannel Node1Pubkey []byte Node2Pubkey []byte Policy1ID sql.NullInt64 @@ -2053,19 +2053,19 @@ func (q *Queries) ListChannelsWithPoliciesPaginated(ctx context.Context, arg Lis for rows.Next() { var i ListChannelsWithPoliciesPaginatedRow if err := rows.Scan( - &i.Channel.ID, - &i.Channel.Version, - &i.Channel.Scid, - &i.Channel.NodeID1, - &i.Channel.NodeID2, - &i.Channel.Outpoint, - &i.Channel.Capacity, - &i.Channel.BitcoinKey1, - &i.Channel.BitcoinKey2, - &i.Channel.Node1Signature, - &i.Channel.Node2Signature, - &i.Channel.Bitcoin1Signature, - &i.Channel.Bitcoin2Signature, + &i.GraphChannel.ID, + &i.GraphChannel.Version, + &i.GraphChannel.Scid, + &i.GraphChannel.NodeID1, + &i.GraphChannel.NodeID2, + &i.GraphChannel.Outpoint, + &i.GraphChannel.Capacity, + &i.GraphChannel.BitcoinKey1, + &i.GraphChannel.BitcoinKey2, + &i.GraphChannel.Node1Signature, + &i.GraphChannel.Node2Signature, + &i.GraphChannel.Bitcoin1Signature, + &i.GraphChannel.Bitcoin2Signature, &i.Node1Pubkey, &i.Node2Pubkey, &i.Policy1ID, @@ -2114,7 +2114,7 @@ func (q *Queries) ListChannelsWithPoliciesPaginated(ctx context.Context, arg Lis const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many SELECT id, pub_key -FROM nodes +FROM graph_nodes WHERE version = $1 AND id > $2 ORDER BY id LIMIT $3 @@ -2156,7 +2156,7 @@ func (q *Queries) ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndP const listNodesPaginated = `-- name: ListNodesPaginated :many SELECT id, version, pub_key, alias, last_update, color, signature -FROM nodes +FROM graph_nodes WHERE version = $1 AND id > $2 ORDER BY id LIMIT $3 @@ -2168,15 +2168,15 @@ type ListNodesPaginatedParams struct { Limit int32 } -func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]Node, error) { +func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]GraphNode, error) { rows, err := q.db.QueryContext(ctx, listNodesPaginated, arg.Version, arg.ID, arg.Limit) if err != nil { return nil, err } defer rows.Close() - var items []Node + var items []GraphNode for rows.Next() { - var i Node + var i GraphNode if err := rows.Scan( &i.ID, &i.Version, @@ -2201,11 +2201,11 @@ func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginated const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one /* ───────────────────────────────────────────── - channel_policies table queries + graph_channel_policies table queries ───────────────────────────────────────────── */ -INSERT INTO channel_policies ( +INSERT INTO graph_channel_policies ( version, channel_id, node_id, timelock, fee_ppm, base_fee_msat, min_htlc_msat, last_update, disabled, max_htlc_msat, inbound_base_fee_msat, @@ -2230,7 +2230,7 @@ ON CONFLICT (channel_id, node_id, version) message_flags = EXCLUDED.message_flags, channel_flags = EXCLUDED.channel_flags, signature = EXCLUDED.signature -WHERE EXCLUDED.last_update > channel_policies.last_update +WHERE EXCLUDED.last_update > graph_channel_policies.last_update RETURNING id ` @@ -2277,11 +2277,11 @@ func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyPara const upsertNode = `-- name: UpsertNode :one /* ───────────────────────────────────────────── - nodes table queries - ───────────────────────────────────────────── + graph_nodes table queries + ───────────────────────────��───────────────── */ -INSERT INTO nodes ( +INSERT INTO graph_nodes ( version, pub_key, alias, last_update, color, signature ) VALUES ( $1, $2, $3, $4, $5, $6 @@ -2294,8 +2294,8 @@ ON CONFLICT (pub_key, version) last_update = EXCLUDED.last_update, color = EXCLUDED.color, signature = EXCLUDED.signature -WHERE nodes.last_update IS NULL - OR EXCLUDED.last_update > nodes.last_update +WHERE graph_nodes.last_update IS NULL + OR EXCLUDED.last_update > graph_nodes.last_update RETURNING id ` @@ -2324,11 +2324,11 @@ func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec /* ───────────────────────────────────────────── - node_extra_types table queries + graph_node_extra_types table queries ───────────────────────────────────────────── */ -INSERT INTO node_extra_types ( +INSERT INTO graph_node_extra_types ( node_id, type, value ) VALUES ($1, $2, $3) @@ -2350,12 +2350,12 @@ func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTy } const upsertPruneLogEntry = `-- name: UpsertPruneLogEntry :exec -/* ───────────────────────────────────────────── - prune_log table queries +/* ───────────────────────────���───────────────── + graph_prune_log table queries ───────────────────────────────────────────── */ -INSERT INTO prune_log ( +INSERT INTO graph_prune_log ( block_height, block_hash ) VALUES ( $1, $2 @@ -2376,18 +2376,18 @@ func (q *Queries) UpsertPruneLogEntry(ctx context.Context, arg UpsertPruneLogEnt const upsertZombieChannel = `-- name: UpsertZombieChannel :exec /* ───────────────────────────────────────────── - zombie_channels table queries + graph_zombie_channels table queries ───────────────────────────────────────────── */ -INSERT INTO zombie_channels (scid, version, node_key_1, node_key_2) +INSERT INTO graph_zombie_channels (scid, version, node_key_1, node_key_2) VALUES ($1, $2, $3, $4) ON CONFLICT (scid, version) DO UPDATE SET -- If a conflict exists for the SCID and version pair, then we -- update the node keys. - node_key_1 = COALESCE(EXCLUDED.node_key_1, zombie_channels.node_key_1), - node_key_2 = COALESCE(EXCLUDED.node_key_2, zombie_channels.node_key_2) + node_key_1 = COALESCE(EXCLUDED.node_key_1, graph_zombie_channels.node_key_1), + node_key_2 = COALESCE(EXCLUDED.node_key_2, graph_zombie_channels.node_key_2) ` type UpsertZombieChannelParams struct { diff --git a/sqldb/sqlc/migrations/000007_graph.down.sql b/sqldb/sqlc/migrations/000007_graph.down.sql index db90d8976..da92ccf22 100644 --- a/sqldb/sqlc/migrations/000007_graph.down.sql +++ b/sqldb/sqlc/migrations/000007_graph.down.sql @@ -1,32 +1,34 @@ -- Drop indexes. -DROP INDEX IF EXISTS nodes_unique; -DROP INDEX IF EXISTS node_extra_types_unique; -DROP INDEX IF EXISTS node_features_unique; -DROP INDEX IF EXISTS node_addresses_unique; -DROP INDEX IF EXISTS node_last_update_idx; -DROP INDEX IF EXISTS source_nodes_unique; -DROP INDEX IF EXISTS channels_node_id_1_idx; -DROP INDEX IF EXISTS channels_node_id_2_idx; -DROP INDEX IF EXISTS channels_unique; -DROP INDEX IF EXISTS channels_version_outpoint_idx; -DROP INDEX IF EXISTS channel_features_unique; -DROP INDEX IF EXISTS channel_extra_types_unique; -DROP INDEX IF EXISTS channel_policies_unique; -DROP INDEX IF EXISTS channel_policy_extra_types_unique; -DROP INDEX IF EXISTS channel_policy_last_update_idx; +DROP INDEX IF EXISTS graph_nodes_unique; +DROP INDEX IF EXISTS graph_node_extra_types_unique; +DROP INDEX IF EXISTS graph_node_features_unique; +DROP INDEX IF EXISTS graph_node_addresses_unique; +DROP INDEX IF EXISTS graph_node_last_update_idx; +DROP INDEX IF EXISTS graph_source_nodes_unique; +DROP INDEX IF EXISTS graph_channels_node_id_1_idx; +DROP INDEX IF EXISTS graph_channels_node_id_2_idx; +DROP INDEX IF EXISTS graph_channels_unique; +DROP INDEX IF EXISTS graph_channels_version_outpoint_idx; +DROP INDEX IF EXISTS graph_channel_features_unique; +DROP INDEX IF EXISTS graph_channel_extra_types_unique; +DROP INDEX IF EXISTS graph_channel_policies_unique; +DROP INDEX IF EXISTS graph_channel_policy_extra_types_unique; +DROP INDEX IF EXISTS graph_channel_policy_last_update_idx; +DROP INDEX IF EXISTS graph_zombie_channels_channel_id_version_idx; -- Drop tables in order of reverse dependencies. -DROP TABLE IF EXISTS channel_policy_extra_types; -DROP TABLE IF EXISTS channel_policies; -DROP TABLE IF EXISTS channel_features; -DROP TABLE IF EXISTS channel_extra_types; -DROP TABLE IF EXISTS channels; -DROP TABLE IF EXISTS source_nodes; -DROP TABLE IF EXISTS node_addresses; -DROP TABLE IF EXISTS node_features; -DROP TABLE IF EXISTS node_extra_types; -DROP TABLE IF EXISTS nodes; -DROP TABLE IF EXISTS channel_policy_extra_types; -DROP TABLE IF EXISTS zombie_channels; -DROP TABLE IF EXISTS prune_log; -DROP TABLE IF EXISTS closed_scids; +DROP TABLE IF EXISTS graph_channel_policy_extra_types; +DROP TABLE IF EXISTS graph_channel_policies; +DROP TABLE IF EXISTS graph_channel_features; +DROP TABLE IF EXISTS graph_channel_extra_types; +DROP TABLE IF EXISTS graph_channels; +DROP TABLE IF EXISTS graph_source_nodes; +DROP TABLE IF EXISTS graph_node_addresses; +DROP TABLE IF EXISTS graph_node_features; +DROP TABLE IF EXISTS graph_node_extra_types; +DROP TABLE IF EXISTS graph_nodes; +DROP TABLE IF EXISTS graph_channel_policy_extra_types; +DROP TABLE IF EXISTS graph_zombie_channels; +DROP TABLE IF EXISTS graph_prune_log; +DROP TABLE IF EXISTS graph_closed_scids; + diff --git a/sqldb/sqlc/migrations/000007_graph.up.sql b/sqldb/sqlc/migrations/000007_graph.up.sql index 2217aee9e..c1c69058c 100644 --- a/sqldb/sqlc/migrations/000007_graph.up.sql +++ b/sqldb/sqlc/migrations/000007_graph.up.sql @@ -4,7 +4,7 @@ */ -- nodes stores all the nodes that we are aware of in the LN graph. -CREATE TABLE IF NOT EXISTS nodes ( +CREATE TABLE IF NOT EXISTS graph_nodes ( -- The db ID of the node. This will only be used DB level -- relations. id INTEGER PRIMARY KEY, @@ -34,16 +34,16 @@ CREATE TABLE IF NOT EXISTS nodes ( -- A node (identified by a public key) can only have one active node -- announcement per protocol. -CREATE UNIQUE INDEX IF NOT EXISTS nodes_unique ON nodes ( +CREATE UNIQUE INDEX IF NOT EXISTS graph_nodes_unique ON graph_nodes ( pub_key, version ); -CREATE INDEX IF NOT EXISTS node_last_update_idx ON nodes(last_update); +CREATE INDEX IF NOT EXISTS graph_node_last_update_idx ON graph_nodes(last_update); -- node_extra_types stores any extra TLV fields covered by a node announcement that -- we do not have an explicit column for in the nodes table. -CREATE TABLE IF NOT EXISTS node_extra_types ( +CREATE TABLE IF NOT EXISTS graph_node_extra_types ( -- The node id this TLV field belongs to. - node_id BIGINT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE, + node_id BIGINT NOT NULL REFERENCES graph_nodes(id) ON DELETE CASCADE, -- The Type field. type BIGINT NOT NULL, @@ -51,26 +51,26 @@ CREATE TABLE IF NOT EXISTS node_extra_types ( -- The value field. value BLOB ); -CREATE UNIQUE INDEX IF NOT EXISTS node_extra_types_unique ON node_extra_types ( +CREATE UNIQUE INDEX IF NOT EXISTS graph_node_extra_types_unique ON graph_node_extra_types ( type, node_id ); -- node_features contains the feature bits of a node. -CREATE TABLE IF NOT EXISTS node_features ( +CREATE TABLE IF NOT EXISTS graph_node_features ( -- The node id this feature belongs to. - node_id BIGINT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE, + node_id BIGINT NOT NULL REFERENCES graph_nodes(id) ON DELETE CASCADE, -- The feature bit value. feature_bit INTEGER NOT NULL ); -CREATE UNIQUE INDEX IF NOT EXISTS node_features_unique ON node_features ( +CREATE UNIQUE INDEX IF NOT EXISTS graph_node_features_unique ON graph_node_features ( node_id, feature_bit ); -- node_addresses contains the advertised addresses of nodes. -CREATE TABLE IF NOT EXISTS node_addresses ( +CREATE TABLE IF NOT EXISTS graph_node_addresses ( -- The node id this feature belongs to. - node_id BIGINT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE, + node_id BIGINT NOT NULL REFERENCES graph_nodes(id) ON DELETE CASCADE, -- An enum that represents the type of address. This will -- dictate how the address column should be parsed. @@ -86,14 +86,14 @@ CREATE TABLE IF NOT EXISTS node_addresses ( -- The advertised address of the node. address TEXT NOT NULL ); -CREATE UNIQUE INDEX IF NOT EXISTS node_addresses_unique ON node_addresses ( +CREATE UNIQUE INDEX IF NOT EXISTS graph_node_addresses_unique ON graph_node_addresses ( node_id, type, position ); -CREATE TABLE IF NOT EXISTS source_nodes ( - node_id BIGINT NOT NULL REFERENCES nodes (id) ON DELETE CASCADE +CREATE TABLE IF NOT EXISTS graph_source_nodes ( + node_id BIGINT NOT NULL REFERENCES graph_nodes (id) ON DELETE CASCADE ); -CREATE UNIQUE INDEX IF NOT EXISTS source_nodes_unique ON source_nodes ( +CREATE UNIQUE INDEX IF NOT EXISTS graph_source_nodes_unique ON graph_source_nodes ( node_id ); @@ -103,7 +103,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS source_nodes_unique ON source_nodes ( */ -- channels stores all teh channels that we are aware of in the graph. -CREATE TABLE IF NOT EXISTS channels ( +CREATE TABLE IF NOT EXISTS graph_channels ( -- The db ID of the channel. id INTEGER PRIMARY KEY, @@ -113,13 +113,13 @@ CREATE TABLE IF NOT EXISTS channels ( -- The channel id (short channel id) of the channel. scid BLOB NOT NULL, - -- A reference to a node in the nodes table for the node_1 node in + -- A reference to a node in the graph_nodes table for the node_1 node in -- the channel announcement. - node_id_1 BIGINT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE, + node_id_1 BIGINT NOT NULL REFERENCES graph_nodes(id) ON DELETE CASCADE, - -- A reference to a node in the nodes table for the node_2 node in + -- A reference to a node in the graph_nodes table for the node_2 node in -- the channel announcement. - node_id_2 BIGINT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE, + node_id_2 BIGINT NOT NULL REFERENCES graph_nodes(id) ON DELETE CASCADE, -- The outpoint of the funding transaction. We chose to store this -- in a string format for the sake of readability and user queries on @@ -171,34 +171,34 @@ CREATE TABLE IF NOT EXISTS channels ( ); -- We'll want to lookup all the channels owned by a node, so we create -- indexes on the node_id_1 and node_id_2 columns. -CREATE INDEX IF NOT EXISTS channels_node_id_1_idx ON channels(node_id_1); -CREATE INDEX IF NOT EXISTS channels_node_id_2_idx ON channels(node_id_2); +CREATE INDEX IF NOT EXISTS graph_channels_node_id_1_idx ON graph_channels(node_id_1); +CREATE INDEX IF NOT EXISTS graph_channels_node_id_2_idx ON graph_channels(node_id_2); -- A channel (identified by a short channel id) can only have one active -- channel announcement per protocol version. We also order the index by -- scid in descending order so that we have an idea of the latest channel -- announcement we know of. -CREATE UNIQUE INDEX IF NOT EXISTS channels_unique ON channels(version, scid DESC); -CREATE INDEX IF NOT EXISTS channels_version_outpoint_idx ON channels(version, outpoint); +CREATE UNIQUE INDEX IF NOT EXISTS graph_channels_unique ON graph_channels(version, scid DESC); +CREATE INDEX IF NOT EXISTS graph_channels_version_outpoint_idx ON graph_channels(version, outpoint); -- channel_features contains the feature bits of a channel. -CREATE TABLE IF NOT EXISTS channel_features ( +CREATE TABLE IF NOT EXISTS graph_channel_features ( -- The channel id this feature belongs to. - channel_id BIGINT NOT NULL REFERENCES channels(id) ON DELETE CASCADE, + channel_id BIGINT NOT NULL REFERENCES graph_channels(id) ON DELETE CASCADE, -- The feature bit value. feature_bit INTEGER NOT NULL ); -CREATE UNIQUE INDEX IF NOT EXISTS channel_features_unique ON channel_features ( +CREATE UNIQUE INDEX IF NOT EXISTS graph_channel_features_unique ON graph_channel_features ( channel_id, feature_bit ); -- channel_extra_types stores any extra TLV fields covered by a channels -- announcement that we do not have an explicit column for in the channels -- table. -CREATE TABLE IF NOT EXISTS channel_extra_types ( +CREATE TABLE IF NOT EXISTS graph_channel_extra_types ( -- The channel id this TLV field belongs to. - channel_id BIGINT NOT NULL REFERENCES channels(id) ON DELETE CASCADE, + channel_id BIGINT NOT NULL REFERENCES graph_channels(id) ON DELETE CASCADE, -- The Type field. type BIGINT NOT NULL, @@ -206,7 +206,7 @@ CREATE TABLE IF NOT EXISTS channel_extra_types ( -- The value field. value BLOB ); -CREATE UNIQUE INDEX IF NOT EXISTS channel_extra_types_unique ON channel_extra_types ( +CREATE UNIQUE INDEX IF NOT EXISTS graph_channel_extra_types_unique ON graph_channel_extra_types ( type, channel_id ); @@ -215,7 +215,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS channel_extra_types_unique ON channel_extra_ty ───────────────────────────────────────────── */ -CREATE TABLE IF NOT EXISTS channel_policies ( +CREATE TABLE IF NOT EXISTS graph_channel_policies ( -- The db ID of the channel policy. id INTEGER PRIMARY KEY, @@ -223,10 +223,10 @@ CREATE TABLE IF NOT EXISTS channel_policies ( version SMALLINT NOT NULL, -- The DB ID of the channel that this policy is referencing. - channel_id BIGINT NOT NULL REFERENCES channels(id) ON DELETE CASCADE, + channel_id BIGINT NOT NULL REFERENCES graph_channels(id) ON DELETE CASCADE, -- The DB ID of the node that created the policy update. - node_id BIGINT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE, + node_id BIGINT NOT NULL REFERENCES graph_nodes(id) ON DELETE CASCADE, -- The number of blocks that the node will subtract from the expiry -- of an incoming HTLC. @@ -290,17 +290,17 @@ CREATE TABLE IF NOT EXISTS channel_policies ( ); -- A node can only have a single live policy update for a channel on a -- given protocol at any given time. -CREATE UNIQUE INDEX IF NOT EXISTS channel_policies_unique ON channel_policies ( +CREATE UNIQUE INDEX IF NOT EXISTS graph_channel_policies_unique ON graph_channel_policies ( channel_id, node_id, version ); -CREATE INDEX IF NOT EXISTS channel_policy_last_update_idx ON channel_policies(last_update); +CREATE INDEX IF NOT EXISTS graph_channel_policy_last_update_idx ON graph_channel_policies(last_update); -- channel_policy_extra_types stores any extra TLV fields covered by a channel -- update that we do not have an explicit column for in the channel_policies -- table. -CREATE TABLE IF NOT EXISTS channel_policy_extra_types ( +CREATE TABLE IF NOT EXISTS graph_channel_policy_extra_types ( -- The channel_policy id this TLV field belongs to. - channel_policy_id BIGINT NOT NULL REFERENCES channel_policies(id) ON DELETE CASCADE, + channel_policy_id BIGINT NOT NULL REFERENCES graph_channel_policies(id) ON DELETE CASCADE, -- The Type field. type BIGINT NOT NULL, @@ -308,7 +308,7 @@ CREATE TABLE IF NOT EXISTS channel_policy_extra_types ( -- The value field. value BLOB ); -CREATE UNIQUE INDEX IF NOT EXISTS channel_policy_extra_types_unique ON channel_policy_extra_types ( +CREATE UNIQUE INDEX IF NOT EXISTS graph_channel_policy_extra_types_unique ON graph_channel_policy_extra_types ( type, channel_policy_id ); @@ -317,7 +317,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS channel_policy_extra_types_unique ON channel_p ───────────────────────────────────────────── */ -CREATE TABLE IF NOT EXISTS zombie_channels ( +CREATE TABLE IF NOT EXISTS graph_zombie_channels ( -- The channel id (short channel id) of the channel. -- NOTE: we don't use a foreign key here to the `channels` -- table since we may delete the channel record once it @@ -337,10 +337,10 @@ CREATE TABLE IF NOT EXISTS zombie_channels ( -- will be able to resurrect the channel. node_key_2 BLOB ); -CREATE UNIQUE INDEX IF NOT EXISTS zombie_channels_channel_id_version_idx - ON zombie_channels(scid, version); +CREATE UNIQUE INDEX IF NOT EXISTS graph_zombie_channels_channel_id_version_idx + ON graph_zombie_channels(scid, version); -CREATE TABLE IF NOT EXISTS prune_log ( +CREATE TABLE IF NOT EXISTS graph_prune_log ( -- The block height that the prune was performed at. -- NOTE: we don't use INTEGER PRIMARY KEY here since that would -- get transformed into an auto-incrementing type by our SQL type @@ -352,7 +352,7 @@ CREATE TABLE IF NOT EXISTS prune_log ( block_hash BLOB NOT NULL ); -CREATE TABLE IF NOT EXISTS closed_scids ( +CREATE TABLE IF NOT EXISTS graph_closed_scids ( -- The short channel id of the channel. scid BLOB PRIMARY KEY ); \ No newline at end of file diff --git a/sqldb/sqlc/models.go b/sqldb/sqlc/models.go index ca43bed1f..24df0d680 100644 --- a/sqldb/sqlc/models.go +++ b/sqldb/sqlc/models.go @@ -28,7 +28,7 @@ type AmpSubInvoiceHtlc struct { Preimage []byte } -type Channel struct { +type GraphChannel struct { ID int64 Version int16 Scid []byte @@ -44,18 +44,18 @@ type Channel struct { Bitcoin2Signature []byte } -type ChannelExtraType struct { +type GraphChannelExtraType struct { ChannelID int64 Type int64 Value []byte } -type ChannelFeature struct { +type GraphChannelFeature struct { ChannelID int64 FeatureBit int32 } -type ChannelPolicy struct { +type GraphChannelPolicy struct { ID int64 Version int16 ChannelID int64 @@ -74,16 +74,60 @@ type ChannelPolicy struct { Signature []byte } -type ChannelPolicyExtraType struct { +type GraphChannelPolicyExtraType struct { ChannelPolicyID int64 Type int64 Value []byte } -type ClosedScid struct { +type GraphClosedScid struct { Scid []byte } +type GraphNode struct { + ID int64 + Version int16 + PubKey []byte + Alias sql.NullString + LastUpdate sql.NullInt64 + Color sql.NullString + Signature []byte +} + +type GraphNodeAddress struct { + NodeID int64 + Type int16 + Position int32 + Address string +} + +type GraphNodeExtraType struct { + NodeID int64 + Type int64 + Value []byte +} + +type GraphNodeFeature struct { + NodeID int64 + FeatureBit int32 +} + +type GraphPruneLog struct { + BlockHeight int64 + BlockHash []byte +} + +type GraphSourceNode struct { + NodeID int64 +} + +type GraphZombieChannel struct { + Scid []byte + Version int16 + NodeKey1 []byte + NodeKey2 []byte +} + type Invoice struct { ID int64 Hash []byte @@ -158,47 +202,3 @@ type MigrationTracker struct { Version int32 MigrationTime time.Time } - -type Node struct { - ID int64 - Version int16 - PubKey []byte - Alias sql.NullString - LastUpdate sql.NullInt64 - Color sql.NullString - Signature []byte -} - -type NodeAddress struct { - NodeID int64 - Type int16 - Position int32 - Address string -} - -type NodeExtraType struct { - NodeID int64 - Type int64 - Value []byte -} - -type NodeFeature struct { - NodeID int64 - FeatureBit int32 -} - -type PruneLog struct { - BlockHeight int64 - BlockHash []byte -} - -type SourceNode struct { - NodeID int64 -} - -type ZombieChannel struct { - Scid []byte - Version int16 - NodeKey1 []byte - NodeKey2 []byte -} diff --git a/sqldb/sqlc/querier.go b/sqldb/sqlc/querier.go index 71fc4d281..ba84db5ac 100644 --- a/sqldb/sqlc/querier.go +++ b/sqldb/sqlc/querier.go @@ -37,15 +37,15 @@ type Querier interface { GetChannelAndNodesBySCID(ctx context.Context, arg GetChannelAndNodesBySCIDParams) (GetChannelAndNodesBySCIDRow, error) GetChannelByOutpoint(ctx context.Context, outpoint string) (GetChannelByOutpointRow, error) GetChannelByOutpointWithPolicies(ctx context.Context, arg GetChannelByOutpointWithPoliciesParams) (GetChannelByOutpointWithPoliciesRow, error) - GetChannelBySCID(ctx context.Context, arg GetChannelBySCIDParams) (Channel, error) + GetChannelBySCID(ctx context.Context, arg GetChannelBySCIDParams) (GraphChannel, error) GetChannelBySCIDWithPolicies(ctx context.Context, arg GetChannelBySCIDWithPoliciesParams) (GetChannelBySCIDWithPoliciesRow, error) GetChannelFeaturesAndExtras(ctx context.Context, channelID int64) ([]GetChannelFeaturesAndExtrasRow, error) - GetChannelPolicyByChannelAndNode(ctx context.Context, arg GetChannelPolicyByChannelAndNodeParams) (ChannelPolicy, error) + GetChannelPolicyByChannelAndNode(ctx context.Context, arg GetChannelPolicyByChannelAndNodeParams) (GraphChannelPolicy, error) GetChannelPolicyExtraTypes(ctx context.Context, arg GetChannelPolicyExtraTypesParams) ([]GetChannelPolicyExtraTypesRow, error) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg GetChannelsByPolicyLastUpdateRangeParams) ([]GetChannelsByPolicyLastUpdateRangeRow, error) GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error) GetDatabaseVersion(ctx context.Context) (int32, error) - GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]NodeExtraType, error) + GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]GraphNodeExtraType, error) // This method may return more than one invoice if filter using multiple fields // from different invoices. It is the caller's responsibility to ensure that // we bubble up an error in those cases. @@ -58,14 +58,14 @@ type Querier interface { GetKVInvoicePaymentHashByAddIndex(ctx context.Context, addIndex int64) ([]byte, error) GetMigration(ctx context.Context, version int32) (time.Time, error) GetNodeAddressesByPubKey(ctx context.Context, arg GetNodeAddressesByPubKeyParams) ([]GetNodeAddressesByPubKeyRow, error) - GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (Node, error) - GetNodeFeatures(ctx context.Context, nodeID int64) ([]NodeFeature, error) + GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (GraphNode, error) + GetNodeFeatures(ctx context.Context, nodeID int64) ([]GraphNodeFeature, error) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyParams) (int64, error) - GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]Node, error) + GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]GraphNode, error) GetPruneHashByHeight(ctx context.Context, blockHeight int64) ([]byte, error) - GetPruneTip(ctx context.Context) (PruneLog, error) - GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]Channel, error) + GetPruneTip(ctx context.Context) (GraphPruneLog, error) + GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]GraphChannel, error) GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) // NOTE: this is V1 specific since for V1, disabled is a @@ -73,7 +73,7 @@ type Querier interface { // 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) (GraphZombieChannel, error) HighestSCID(ctx context.Context, version int16) ([]byte, error) InsertAMPSubInvoice(ctx context.Context, arg InsertAMPSubInvoiceParams) error InsertAMPSubInvoiceHTLC(ctx context.Context, arg InsertAMPSubInvoiceHTLCParams) error @@ -95,7 +95,7 @@ type Querier interface { ListChannelsPaginated(ctx context.Context, arg ListChannelsPaginatedParams) ([]ListChannelsPaginatedRow, error) ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error) ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error) - ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]Node, error) + ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]GraphNode, error) NextInvoiceSettleIndex(ctx context.Context) (int64, error) OnAMPSubInvoiceCanceled(ctx context.Context, arg OnAMPSubInvoiceCanceledParams) error OnAMPSubInvoiceCreated(ctx context.Context, arg OnAMPSubInvoiceCreatedParams) error diff --git a/sqldb/sqlc/queries/graph.sql b/sqldb/sqlc/queries/graph.sql index ec43410c9..5088b37ee 100644 --- a/sqldb/sqlc/queries/graph.sql +++ b/sqldb/sqlc/queries/graph.sql @@ -1,10 +1,10 @@ /* ───────────────────────────────────────────── - nodes table queries - ───────────────────────────────────────────── + graph_nodes table queries + ───────────────────────────��───────────────── */ -- name: UpsertNode :one -INSERT INTO nodes ( +INSERT INTO graph_nodes ( version, pub_key, alias, last_update, color, signature ) VALUES ( $1, $2, $3, $4, $5, $6 @@ -17,32 +17,32 @@ ON CONFLICT (pub_key, version) last_update = EXCLUDED.last_update, color = EXCLUDED.color, signature = EXCLUDED.signature -WHERE nodes.last_update IS NULL - OR EXCLUDED.last_update > nodes.last_update +WHERE graph_nodes.last_update IS NULL + OR EXCLUDED.last_update > graph_nodes.last_update RETURNING id; -- name: GetNodeByPubKey :one SELECT * -FROM nodes +FROM graph_nodes WHERE pub_key = $1 AND version = $2; -- name: GetNodeIDByPubKey :one SELECT id -FROM nodes +FROM graph_nodes WHERE pub_key = $1 AND version = $2; -- name: ListNodesPaginated :many SELECT * -FROM nodes +FROM graph_nodes WHERE version = $1 AND id > $2 ORDER BY id LIMIT $3; -- name: ListNodeIDsAndPubKeys :many SELECT id, pub_key -FROM nodes +FROM graph_nodes WHERE version = $1 AND id > $2 ORDER BY id LIMIT $3; @@ -50,8 +50,8 @@ LIMIT $3; -- name: IsPublicV1Node :one SELECT EXISTS ( SELECT 1 - FROM channels c - JOIN nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2 + FROM graph_channels c + JOIN graph_nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2 -- NOTE: we hard-code the version here since the clauses -- here that determine if a node is public is specific -- to the V1 gossip protocol. In V1, a node is public @@ -66,37 +66,37 @@ SELECT EXISTS ( ); -- name: DeleteUnconnectedNodes :many -DELETE FROM nodes +DELETE FROM graph_nodes WHERE -- Ignore any of our source nodes. NOT EXISTS ( SELECT 1 - FROM source_nodes sn - WHERE sn.node_id = nodes.id + FROM graph_source_nodes sn + WHERE sn.node_id = graph_nodes.id ) -- Select all nodes that do not have any channels. AND NOT EXISTS ( SELECT 1 - FROM channels c - WHERE c.node_id_1 = nodes.id OR c.node_id_2 = nodes.id + FROM graph_channels c + WHERE c.node_id_1 = graph_nodes.id OR c.node_id_2 = graph_nodes.id ) RETURNING pub_key; -- name: DeleteNodeByPubKey :execresult -DELETE FROM nodes +DELETE FROM graph_nodes WHERE pub_key = $1 AND version = $2; -- name: DeleteNode :exec -DELETE FROM nodes +DELETE FROM graph_nodes WHERE id = $1; /* ───────────────────────────────────────────── - node_features table queries + graph_node_features table queries ───────────────────────────────────────────── */ -- name: InsertNodeFeature :exec -INSERT INTO node_features ( +INSERT INTO graph_node_features ( node_id, feature_bit ) VALUES ( $1, $2 @@ -104,28 +104,28 @@ INSERT INTO node_features ( -- name: GetNodeFeatures :many SELECT * -FROM node_features +FROM graph_node_features WHERE node_id = $1; -- name: GetNodeFeaturesByPubKey :many SELECT f.feature_bit -FROM nodes n - JOIN node_features f ON f.node_id = n.id +FROM graph_nodes n + JOIN graph_node_features f ON f.node_id = n.id WHERE n.pub_key = $1 AND n.version = $2; -- name: DeleteNodeFeature :exec -DELETE FROM node_features +DELETE FROM graph_node_features WHERE node_id = $1 AND feature_bit = $2; /* ───────────────────────────────────────────── - node_addresses table queries - ───────────────────────────────────────────── + graph_node_addresses table queries + ───────────────────────────────────��───────── */ -- name: InsertNodeAddress :exec -INSERT INTO node_addresses ( +INSERT INTO graph_node_addresses ( node_id, type, address, @@ -136,28 +136,28 @@ INSERT INTO node_addresses ( -- name: GetNodeAddressesByPubKey :many SELECT a.type, a.address -FROM nodes n -LEFT JOIN node_addresses a ON a.node_id = n.id +FROM graph_nodes n +LEFT JOIN graph_node_addresses a ON a.node_id = n.id WHERE n.pub_key = $1 AND n.version = $2 ORDER BY a.type ASC, a.position ASC; -- name: GetNodesByLastUpdateRange :many SELECT * -FROM nodes +FROM graph_nodes WHERE last_update >= @start_time AND last_update < @end_time; -- name: DeleteNodeAddresses :exec -DELETE FROM node_addresses +DELETE FROM graph_node_addresses WHERE node_id = $1; /* ───────────────────────────────────────────── - node_extra_types table queries + graph_node_extra_types table queries ───────────────────────────────────────────── */ -- name: UpsertNodeExtraType :exec -INSERT INTO node_extra_types ( +INSERT INTO graph_node_extra_types ( node_id, type, value ) VALUES ($1, $2, $3) @@ -168,37 +168,37 @@ ON CONFLICT (type, node_id) -- name: GetExtraNodeTypes :many SELECT * -FROM node_extra_types +FROM graph_node_extra_types WHERE node_id = $1; -- name: DeleteExtraNodeType :exec -DELETE FROM node_extra_types +DELETE FROM graph_node_extra_types WHERE node_id = $1 AND type = $2; /* ───────────────────────────────────────────── - source_nodes table queries + graph_source_nodes table queries ───────────────────────────────────────────── */ -- name: AddSourceNode :exec -INSERT INTO source_nodes (node_id) +INSERT INTO graph_source_nodes (node_id) VALUES ($1) ON CONFLICT (node_id) DO NOTHING; -- name: GetSourceNodesByVersion :many SELECT sn.node_id, n.pub_key -FROM source_nodes sn - JOIN nodes n ON sn.node_id = n.id +FROM graph_source_nodes sn + JOIN graph_nodes n ON sn.node_id = n.id WHERE n.version = $1; /* ───────────────────────────────────────────── - channels table queries + graph_channels table queries ───────────────────────────────────────────── */ -- name: CreateChannel :one -INSERT INTO channels ( +INSERT INTO graph_channels ( version, scid, node_id_1, node_id_2, outpoint, capacity, bitcoin_key_1, bitcoin_key_2, node_1_signature, node_2_signature, bitcoin_1_signature, @@ -209,7 +209,7 @@ INSERT INTO channels ( RETURNING id; -- name: AddV1ChannelProof :execresult -UPDATE channels +UPDATE graph_channels SET node_1_signature = $2, node_2_signature = $3, bitcoin_1_signature = $4, @@ -221,14 +221,14 @@ WHERE scid = $1 SELECT sqlc.embed(c), n1.pub_key AS node1_pub_key, n2.pub_key AS node2_pub_key -FROM channels c - JOIN nodes n1 ON c.node_id_1 = n1.id - JOIN nodes n2 ON c.node_id_2 = n2.id +FROM graph_channels c + JOIN graph_nodes n1 ON c.node_id_1 = n1.id + JOIN graph_nodes n2 ON c.node_id_2 = n2.id WHERE scid >= @start_scid AND scid < @end_scid; -- name: GetChannelBySCID :one -SELECT * FROM channels +SELECT * FROM graph_channels WHERE scid = $1 AND version = $2; -- name: GetChannelByOutpoint :one @@ -236,9 +236,9 @@ SELECT sqlc.embed(c), n1.pub_key AS node1_pubkey, n2.pub_key AS node2_pubkey -FROM channels c - JOIN nodes n1 ON c.node_id_1 = n1.id - JOIN nodes n2 ON c.node_id_2 = n2.id +FROM graph_channels c + JOIN graph_nodes n1 ON c.node_id_1 = n1.id + JOIN graph_nodes n2 ON c.node_id_2 = n2.id WHERE c.outpoint = $1; -- name: GetChannelAndNodesBySCID :one @@ -246,9 +246,9 @@ SELECT c.*, n1.pub_key AS node1_pub_key, n2.pub_key AS node2_pub_key -FROM channels c - JOIN nodes n1 ON c.node_id_1 = n1.id - JOIN nodes n2 ON c.node_id_2 = n2.id +FROM graph_channels c + JOIN graph_nodes n1 ON c.node_id_1 = n1.id + JOIN graph_nodes n2 ON c.node_id_2 = n2.id WHERE c.scid = $1 AND c.version = $2; @@ -259,7 +259,7 @@ SELECT cf.feature_bit AS feature_bit, NULL AS extra_key, NULL AS value -FROM channel_features cf +FROM graph_channel_features cf WHERE cf.channel_id = $1 UNION ALL @@ -270,11 +270,11 @@ SELECT 0 AS feature_bit, cet.type AS extra_key, cet.value AS value -FROM channel_extra_types cet +FROM graph_channel_extra_types cet WHERE cet.channel_id = $1; -- name: GetSCIDByOutpoint :one -SELECT scid from channels +SELECT scid from graph_channels WHERE outpoint = $1 AND version = $2; -- name: GetChannelsByPolicyLastUpdateRange :many @@ -317,12 +317,12 @@ SELECT cp2.channel_flags AS policy2_channel_flags, cp2.signature AS policy2_signature -FROM channels c - JOIN nodes n1 ON c.node_id_1 = n1.id - JOIN nodes n2 ON c.node_id_2 = n2.id - LEFT JOIN channel_policies cp1 +FROM graph_channels c + JOIN graph_nodes n1 ON c.node_id_1 = n1.id + JOIN graph_nodes n2 ON c.node_id_2 = n2.id + LEFT JOIN graph_channel_policies cp1 ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version - LEFT JOIN channel_policies cp2 + LEFT JOIN graph_channel_policies cp2 ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version WHERE c.version = @version AND ( @@ -377,18 +377,18 @@ SELECT cp2.message_flags AS policy_2_message_flags, cp2.channel_flags AS policy_2_channel_flags, cp2.signature AS policy_2_signature -FROM channels c - JOIN nodes n1 ON c.node_id_1 = n1.id - JOIN nodes n2 ON c.node_id_2 = n2.id - LEFT JOIN channel_policies cp1 +FROM graph_channels c + JOIN graph_nodes n1 ON c.node_id_1 = n1.id + JOIN graph_nodes n2 ON c.node_id_2 = n2.id + LEFT JOIN graph_channel_policies cp1 ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version - LEFT JOIN channel_policies cp2 + LEFT JOIN graph_channel_policies cp2 ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version WHERE c.outpoint = $1 AND c.version = $2; -- name: HighestSCID :one SELECT scid -FROM channels +FROM graph_channels WHERE version = $1 ORDER BY scid DESC LIMIT 1; @@ -435,26 +435,26 @@ SELECT sqlc.embed(c), cp2.channel_flags AS policy2_channel_flags, cp2.signature AS policy2_signature -FROM channels c - JOIN nodes n1 ON c.node_id_1 = n1.id - JOIN nodes n2 ON c.node_id_2 = n2.id - LEFT JOIN channel_policies cp1 +FROM graph_channels c + JOIN graph_nodes n1 ON c.node_id_1 = n1.id + JOIN graph_nodes n2 ON c.node_id_2 = n2.id + LEFT JOIN graph_channel_policies cp1 ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version - LEFT JOIN channel_policies cp2 + LEFT JOIN graph_channel_policies cp2 ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version WHERE c.version = $1 AND (c.node_id_1 = $2 OR c.node_id_2 = $2); -- name: GetPublicV1ChannelsBySCID :many SELECT * -FROM channels +FROM graph_channels WHERE node_1_signature IS NOT NULL AND scid >= @start_scid AND scid < @end_scid; -- name: ListChannelsPaginated :many SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint -FROM channels c +FROM graph_channels c WHERE c.version = $1 AND c.id > $2 ORDER BY c.id LIMIT $3; @@ -501,50 +501,50 @@ SELECT cp2.channel_flags AS policy2_channel_flags, cp2.signature AS policy_2_signature -FROM channels c -JOIN nodes n1 ON c.node_id_1 = n1.id -JOIN nodes n2 ON c.node_id_2 = n2.id -LEFT JOIN channel_policies cp1 +FROM graph_channels c +JOIN graph_nodes n1 ON c.node_id_1 = n1.id +JOIN graph_nodes n2 ON c.node_id_2 = n2.id +LEFT JOIN graph_channel_policies cp1 ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version -LEFT JOIN channel_policies cp2 +LEFT JOIN graph_channel_policies cp2 ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version WHERE c.version = $1 AND c.id > $2 ORDER BY c.id LIMIT $3; -- name: DeleteChannel :exec -DELETE FROM channels WHERE id = $1; +DELETE FROM graph_channels WHERE id = $1; /* ───────────────────────────────────────────── - channel_features table queries + graph_channel_features table queries ───────────────────────────────────────────── */ -- name: InsertChannelFeature :exec -INSERT INTO channel_features ( +INSERT INTO graph_channel_features ( channel_id, feature_bit ) VALUES ( $1, $2 ); /* ───────────────────────────────────────────── - channel_extra_types table queries + graph_channel_extra_types table queries ───────────────────────────────────────────── */ -- name: CreateChannelExtraType :exec -INSERT INTO channel_extra_types ( +INSERT INTO graph_channel_extra_types ( channel_id, type, value ) VALUES ($1, $2, $3); /* ───────────────────────────────────────────── - channel_policies table queries + graph_channel_policies table queries ───────────────────────────────────────────── */ -- name: UpsertEdgePolicy :one -INSERT INTO channel_policies ( +INSERT INTO graph_channel_policies ( version, channel_id, node_id, timelock, fee_ppm, base_fee_msat, min_htlc_msat, last_update, disabled, max_htlc_msat, inbound_base_fee_msat, @@ -569,12 +569,12 @@ ON CONFLICT (channel_id, node_id, version) message_flags = EXCLUDED.message_flags, channel_flags = EXCLUDED.channel_flags, signature = EXCLUDED.signature -WHERE EXCLUDED.last_update > channel_policies.last_update +WHERE EXCLUDED.last_update > graph_channel_policies.last_update RETURNING id; -- name: GetChannelPolicyByChannelAndNode :one SELECT * -FROM channel_policies +FROM graph_channel_policies WHERE channel_id = $1 AND node_id = $2 AND version = $3; @@ -619,23 +619,23 @@ SELECT cp2.channel_flags AS policy_2_channel_flags, cp2.signature AS policy2_signature -FROM channels c - JOIN nodes n1 ON c.node_id_1 = n1.id - JOIN nodes n2 ON c.node_id_2 = n2.id - LEFT JOIN channel_policies cp1 +FROM graph_channels c + JOIN graph_nodes n1 ON c.node_id_1 = n1.id + JOIN graph_nodes n2 ON c.node_id_2 = n2.id + LEFT JOIN graph_channel_policies cp1 ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version - LEFT JOIN channel_policies cp2 + LEFT JOIN graph_channel_policies cp2 ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version WHERE c.scid = @scid AND c.version = @version; /* ───────────────────────────────────────────── - channel_policy_extra_types table queries + graph_channel_policy_extra_types table queries ───────────────────────────────────────────── */ -- name: InsertChanPolicyExtraType :exec -INSERT INTO channel_policy_extra_types ( +INSERT INTO graph_channel_policy_extra_types ( channel_policy_id, type, value ) VALUES ($1, $2, $3); @@ -647,15 +647,15 @@ SELECT cp.node_id, cpet.type, cpet.value -FROM channel_policies cp -JOIN channel_policy_extra_types cpet +FROM graph_channel_policies cp +JOIN graph_channel_policy_extra_types cpet ON cp.id = cpet.channel_policy_id 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 +FROM graph_channels c + JOIN graph_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 @@ -666,55 +666,55 @@ GROUP BY c.scid HAVING COUNT(*) > 1; -- name: DeleteChannelPolicyExtraTypes :exec -DELETE FROM channel_policy_extra_types +DELETE FROM graph_channel_policy_extra_types WHERE channel_policy_id = $1; /* ───────────────────────────────────────────── - zombie_channels table queries + graph_zombie_channels table queries ───────────────────────────────────────────── */ -- name: UpsertZombieChannel :exec -INSERT INTO zombie_channels (scid, version, node_key_1, node_key_2) +INSERT INTO graph_zombie_channels (scid, version, node_key_1, node_key_2) VALUES ($1, $2, $3, $4) ON CONFLICT (scid, version) DO UPDATE SET -- If a conflict exists for the SCID and version pair, then we -- update the node keys. - node_key_1 = COALESCE(EXCLUDED.node_key_1, zombie_channels.node_key_1), - node_key_2 = COALESCE(EXCLUDED.node_key_2, zombie_channels.node_key_2); + node_key_1 = COALESCE(EXCLUDED.node_key_1, graph_zombie_channels.node_key_1), + node_key_2 = COALESCE(EXCLUDED.node_key_2, graph_zombie_channels.node_key_2); -- name: DeleteZombieChannel :execresult -DELETE FROM zombie_channels +DELETE FROM graph_zombie_channels WHERE scid = $1 AND version = $2; -- name: CountZombieChannels :one SELECT COUNT(*) -FROM zombie_channels +FROM graph_zombie_channels WHERE version = $1; -- name: GetZombieChannel :one SELECT * -FROM zombie_channels +FROM graph_zombie_channels WHERE scid = $1 AND version = $2; -- name: IsZombieChannel :one SELECT EXISTS ( SELECT 1 - FROM zombie_channels + FROM graph_zombie_channels WHERE scid = $1 AND version = $2 ) AS is_zombie; -/* ───────────────────────────────────────────── - prune_log table queries +/* ───────────────────────────���───────────────── + graph_prune_log table queries ───────────────────────────────────────────── */ -- name: UpsertPruneLogEntry :exec -INSERT INTO prune_log ( +INSERT INTO graph_prune_log ( block_height, block_hash ) VALUES ( $1, $2 @@ -724,33 +724,33 @@ ON CONFLICT(block_height) DO UPDATE SET -- name: GetPruneTip :one SELECT block_height, block_hash -FROM prune_log +FROM graph_prune_log ORDER BY block_height DESC LIMIT 1; -- name: GetPruneHashByHeight :one SELECT block_hash -FROM prune_log +FROM graph_prune_log WHERE block_height = $1; -- name: DeletePruneLogEntriesInRange :exec -DELETE FROM prune_log +DELETE FROM graph_prune_log WHERE block_height >= @start_height AND block_height <= @end_height; /* ───────────────────────────────────────────── - closed_scid table queries + graph_closed_scid table queries ────────────────────────────────────────────- */ -- name: InsertClosedChannel :exec -INSERT INTO closed_scids (scid) +INSERT INTO graph_closed_scids (scid) VALUES ($1) ON CONFLICT (scid) DO NOTHING; -- name: IsClosedChannel :one SELECT EXISTS ( SELECT 1 - FROM closed_scids + FROM graph_closed_scids WHERE scid = $1 );