sqldb+graph/db: prefix graph SQL objects with "graph_"

This makes it more clear what each table is for especially when viewed
with other invoice/payments tables.
This commit is contained in:
Elle Mouton committed 2025-07-15 18:40:16 +02:00
1 parent df6c02e3af
commit 74b70a5108
8 files changed
+615 -608

No files matched your search

+6 -5
View File
@@ -445,19 +445,19 @@ func migrateSingleChannel(ctx context.Context, sqlDB SQLQueries,
// Assert that the DB IDs for the channel and nodes are as expected // Assert that the DB IDs for the channel and nodes are as expected
// given the inserted channel info. // given the inserted channel info.
err = sqldb.CompareRecords( err = sqldb.CompareRecords(
dbChanInfo.channelID, row.Channel.ID, "channel DB ID", dbChanInfo.channelID, row.GraphChannel.ID, "channel DB ID",
) )
if err != nil { if err != nil {
return err return err
} }
err = sqldb.CompareRecords( err = sqldb.CompareRecords(
dbChanInfo.node1ID, row.Node.ID, "node1 DB ID", dbChanInfo.node1ID, row.GraphNode.ID, "node1 DB ID",
) )
if err != nil { if err != nil {
return err return err
} }
err = sqldb.CompareRecords( err = sqldb.CompareRecords(
dbChanInfo.node2ID, row.Node_2.ID, "node2 DB ID", dbChanInfo.node2ID, row.GraphNode_2.ID, "node2 DB ID",
) )
if err != nil { if err != nil {
return err return err
@@ -647,14 +647,15 @@ func getAndBuildChanAndPolicies(ctx context.Context, db SQLQueries,
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) { *models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) {
node1, node2, err := buildNodeVertices( node1, node2, err := buildNodeVertices(
row.Node.PubKey, row.Node_2.PubKey, row.GraphNode.PubKey, row.GraphNode_2.PubKey,
) )
if err != nil { if err != nil {
return nil, nil, nil, err return nil, nil, nil, err
} }
edge, err := getAndBuildEdgeInfo( 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 { if err != nil {
return nil, nil, nil, fmt.Errorf("unable to build channel "+ return nil, nil, nil, fmt.Errorf("unable to build channel "+
+84 -80
View File
@@ -58,17 +58,17 @@ type SQLQueries interface {
Node queries. Node queries.
*/ */
UpsertNode(ctx context.Context, arg sqlc.UpsertNodeParams) (int64, error) 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) GetNodeIDByPubKey(ctx context.Context, arg sqlc.GetNodeIDByPubKeyParams) (int64, error)
GetNodesByLastUpdateRange(ctx context.Context, arg sqlc.GetNodesByLastUpdateRangeParams) ([]sqlc.Node, error) GetNodesByLastUpdateRange(ctx context.Context, arg sqlc.GetNodesByLastUpdateRangeParams) ([]sqlc.GraphNode, error)
ListNodesPaginated(ctx context.Context, arg sqlc.ListNodesPaginatedParams) ([]sqlc.Node, error) ListNodesPaginated(ctx context.Context, arg sqlc.ListNodesPaginatedParams) ([]sqlc.GraphNode, error)
ListNodeIDsAndPubKeys(ctx context.Context, arg sqlc.ListNodeIDsAndPubKeysParams) ([]sqlc.ListNodeIDsAndPubKeysRow, error) ListNodeIDsAndPubKeys(ctx context.Context, arg sqlc.ListNodeIDsAndPubKeysParams) ([]sqlc.ListNodeIDsAndPubKeysRow, error)
IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error)
DeleteUnconnectedNodes(ctx context.Context) ([][]byte, error) DeleteUnconnectedNodes(ctx context.Context) ([][]byte, error)
DeleteNodeByPubKey(ctx context.Context, arg sqlc.DeleteNodeByPubKeyParams) (sql.Result, error) DeleteNodeByPubKey(ctx context.Context, arg sqlc.DeleteNodeByPubKeyParams) (sql.Result, error)
DeleteNode(ctx context.Context, id int64) 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 UpsertNodeExtraType(ctx context.Context, arg sqlc.UpsertNodeExtraTypeParams) error
DeleteExtraNodeType(ctx context.Context, arg sqlc.DeleteExtraNodeTypeParams) error DeleteExtraNodeType(ctx context.Context, arg sqlc.DeleteExtraNodeTypeParams) error
@@ -77,7 +77,7 @@ type SQLQueries interface {
DeleteNodeAddresses(ctx context.Context, nodeID int64) error DeleteNodeAddresses(ctx context.Context, nodeID int64) error
InsertNodeFeature(ctx context.Context, arg sqlc.InsertNodeFeatureParams) 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) GetNodeFeaturesByPubKey(ctx context.Context, arg sqlc.GetNodeFeaturesByPubKeyParams) ([]int32, error)
DeleteNodeFeature(ctx context.Context, arg sqlc.DeleteNodeFeatureParams) 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) CreateChannel(ctx context.Context, arg sqlc.CreateChannelParams) (int64, error)
AddV1ChannelProof(ctx context.Context, arg sqlc.AddV1ChannelProofParams) (sql.Result, 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) GetChannelByOutpoint(ctx context.Context, outpoint string) (sqlc.GetChannelByOutpointRow, error)
GetChannelsBySCIDRange(ctx context.Context, arg sqlc.GetChannelsBySCIDRangeParams) ([]sqlc.GetChannelsBySCIDRangeRow, error) GetChannelsBySCIDRange(ctx context.Context, arg sqlc.GetChannelsBySCIDRangeParams) ([]sqlc.GetChannelsBySCIDRangeRow, error)
GetChannelBySCIDWithPolicies(ctx context.Context, arg sqlc.GetChannelBySCIDWithPoliciesParams) (sqlc.GetChannelBySCIDWithPoliciesRow, 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) ListChannelsPaginated(ctx context.Context, arg sqlc.ListChannelsPaginatedParams) ([]sqlc.ListChannelsPaginatedRow, error)
GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg sqlc.GetChannelsByPolicyLastUpdateRangeParams) ([]sqlc.GetChannelsByPolicyLastUpdateRangeRow, error) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg sqlc.GetChannelsByPolicyLastUpdateRangeParams) ([]sqlc.GetChannelsByPolicyLastUpdateRangeRow, error)
GetChannelByOutpointWithPolicies(ctx context.Context, arg sqlc.GetChannelByOutpointWithPoliciesParams) (sqlc.GetChannelByOutpointWithPoliciesRow, 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) GetSCIDByOutpoint(ctx context.Context, arg sqlc.GetSCIDByOutpointParams) ([]byte, error)
DeleteChannel(ctx context.Context, id int64) error DeleteChannel(ctx context.Context, id int64) error
@@ -115,7 +115,7 @@ type SQLQueries interface {
Channel Policy table queries. Channel Policy table queries.
*/ */
UpsertEdgePolicy(ctx context.Context, arg sqlc.UpsertEdgePolicyParams) (int64, error) UpsertEdgePolicy(ctx context.Context, arg sqlc.UpsertEdgePolicyParams) (int64, error)
GetChannelPolicyByChannelAndNode(ctx context.Context, arg sqlc.GetChannelPolicyByChannelAndNodeParams) (sqlc.ChannelPolicy, error) GetChannelPolicyByChannelAndNode(ctx context.Context, arg sqlc.GetChannelPolicyByChannelAndNodeParams) (sqlc.GraphChannelPolicy, error)
GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error)
InsertChanPolicyExtraType(ctx context.Context, arg sqlc.InsertChanPolicyExtraTypeParams) error InsertChanPolicyExtraType(ctx context.Context, arg sqlc.InsertChanPolicyExtraTypeParams) error
@@ -126,7 +126,7 @@ type SQLQueries interface {
Zombie index queries. Zombie index queries.
*/ */
UpsertZombieChannel(ctx context.Context, arg sqlc.UpsertZombieChannelParams) error 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) CountZombieChannels(ctx context.Context, version int16) (int64, error)
DeleteZombieChannel(ctx context.Context, arg sqlc.DeleteZombieChannelParams) (sql.Result, error) DeleteZombieChannel(ctx context.Context, arg sqlc.DeleteZombieChannelParams) (sql.Result, error)
IsZombieChannel(ctx context.Context, arg sqlc.IsZombieChannelParams) (bool, error) IsZombieChannel(ctx context.Context, arg sqlc.IsZombieChannelParams) (bool, error)
@@ -134,7 +134,7 @@ type SQLQueries interface {
/* /*
Prune log table queries. 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) GetPruneHashByHeight(ctx context.Context, blockHeight int64) ([]byte, error)
UpsertPruneLogEntry(ctx context.Context, arg sqlc.UpsertPruneLogEntryParams) error UpsertPruneLogEntry(ctx context.Context, arg sqlc.UpsertPruneLogEntryParams) error
DeletePruneLogEntriesInRange(ctx context.Context, arg sqlc.DeletePruneLogEntriesInRangeParams) 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 { cb func(tx NodeRTx) error, reset func()) error {
var lastID int64 = 0 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) node, err := buildNode(ctx, db, &dbNode)
if err != nil { if err != nil {
return fmt.Errorf("unable to build node(id=%d): %w", 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 // If we've already retrieved the info and policies for
// this edge, then we can skip it as we don't need to do // this edge, then we can skip it as we don't need to do
// so again. // so again.
chanIDInt := byteOrder.Uint64(row.Channel.Scid) chanIDInt := byteOrder.Uint64(row.GraphChannel.Scid)
if _, ok := edgesSeen[chanIDInt]; ok { if _, ok := edgesSeen[chanIDInt]; ok {
continue continue
} }
@@ -1029,15 +1029,15 @@ func (s *SQLStore) ChanUpdatesInHorizon(startTime,
} }
node1, node2, err := buildNodes( node1, node2, err := buildNodes(
ctx, db, row.Node, row.Node_2, ctx, db, row.GraphNode, row.GraphNode_2,
) )
if err != nil { if err != nil {
return err return err
} }
channel, err := getAndBuildEdgeInfo( channel, err := getAndBuildEdgeInfo(
ctx, db, s.cfg.ChainHash, row.Channel.ID, ctx, db, s.cfg.ChainHash, row.GraphChannel.ID,
row.Channel, node1.PubKeyBytes, row.GraphChannel, node1.PubKeyBytes,
node2.PubKeyBytes, node2.PubKeyBytes,
) )
if err != nil { if err != nil {
@@ -1144,8 +1144,8 @@ func (s *SQLStore) ForEachNodeCached(ctx context.Context,
e, err := getAndBuildEdgeInfo( e, err := getAndBuildEdgeInfo(
ctx, db, s.cfg.ChainHash, ctx, db, s.cfg.ChainHash,
row.Channel.ID, row.Channel, node1, row.GraphChannel.ID, row.GraphChannel,
node2, node1, node2,
) )
if err != nil { if err != nil {
return fmt.Errorf("unable to build "+ return fmt.Errorf("unable to build "+
@@ -1250,7 +1250,9 @@ func (s *SQLStore) ForEachChannelCacheable(cb func(*models.CachedEdgeInfo,
return err return err
} }
edge := buildCacheableChannelInfo(row.Channel, node1, node2) edge := buildCacheableChannelInfo(
row.GraphChannel, node1, node2,
)
dbPol1, dbPol2, err := extractChannelPolicies(row) dbPol1, dbPol2, err := extractChannelPolicies(row)
if err != nil { if err != nil {
@@ -1311,7 +1313,7 @@ func (s *SQLStore) ForEachChannelCacheable(cb func(*models.CachedEdgeInfo,
return err return err
} }
lastID = row.Channel.ID lastID = row.GraphChannel.ID
} }
} }
@@ -1346,8 +1348,8 @@ func (s *SQLStore) ForEachChannel(ctx context.Context,
} }
edge, err := getAndBuildEdgeInfo( edge, err := getAndBuildEdgeInfo(
ctx, db, s.cfg.ChainHash, row.Channel.ID, row.Channel, ctx, db, s.cfg.ChainHash, row.GraphChannel.ID,
node1, node2, row.GraphChannel, node1, node2,
) )
if err != nil { if err != nil {
return fmt.Errorf("unable to build channel info: %w", return fmt.Errorf("unable to build channel info: %w",
@@ -1402,7 +1404,7 @@ func (s *SQLStore) ForEachChannel(ctx context.Context,
return err 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( node1, node2, err := buildNodeVertices(
row.Node.PubKey, row.Node_2.PubKey, row.GraphNode.PubKey, row.GraphNode_2.PubKey,
) )
if err != nil { if err != nil {
return err return err
} }
info, err := getAndBuildEdgeInfo( info, err := getAndBuildEdgeInfo(
ctx, db, s.cfg.ChainHash, row.Channel.ID, ctx, db, s.cfg.ChainHash, row.GraphChannel.ID,
row.Channel, node1, node2, row.GraphChannel, node1, node2,
) )
if err != nil { if err != nil {
return err return err
} }
err = db.DeleteChannel(ctx, row.Channel.ID) err = db.DeleteChannel(ctx, row.GraphChannel.ID)
if err != nil { if err != nil {
return fmt.Errorf("unable to delete "+ return fmt.Errorf("unable to delete "+
"channel: %w", err) "channel: %w", err)
@@ -1866,15 +1868,15 @@ func (s *SQLStore) FetchChannelEdgesByID(chanID uint64) (
} }
node1, node2, err := buildNodeVertices( node1, node2, err := buildNodeVertices(
row.Node.PubKey, row.Node_2.PubKey, row.GraphNode.PubKey, row.GraphNode_2.PubKey,
) )
if err != nil { if err != nil {
return err return err
} }
edge, err = getAndBuildEdgeInfo( edge, err = getAndBuildEdgeInfo(
ctx, db, s.cfg.ChainHash, row.Channel.ID, row.Channel, ctx, db, s.cfg.ChainHash, row.GraphChannel.ID,
node1, node2, row.GraphChannel, node1, node2,
) )
if err != nil { if err != nil {
return fmt.Errorf("unable to build channel info: %w", return fmt.Errorf("unable to build channel info: %w",
@@ -1945,8 +1947,8 @@ func (s *SQLStore) FetchChannelEdgesByOutpoint(op *wire.OutPoint) (
} }
edge, err = getAndBuildEdgeInfo( edge, err = getAndBuildEdgeInfo(
ctx, db, s.cfg.ChainHash, row.Channel.ID, row.Channel, ctx, db, s.cfg.ChainHash, row.GraphChannel.ID,
node1, node2, row.GraphChannel, node1, node2,
) )
if err != nil { if err != nil {
return fmt.Errorf("unable to build channel info: %w", 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( node1, node2, err := buildNodes(
ctx, db, row.Node, row.Node_2, ctx, db, row.GraphNode, row.GraphNode_2,
) )
if err != nil { if err != nil {
return fmt.Errorf("unable to fetch nodes: %w", return fmt.Errorf("unable to fetch nodes: %w",
@@ -2195,8 +2197,8 @@ func (s *SQLStore) FetchChanInfos(chanIDs []uint64) ([]ChannelEdge, error) {
} }
edge, err := getAndBuildEdgeInfo( edge, err := getAndBuildEdgeInfo(
ctx, db, s.cfg.ChainHash, row.Channel.ID, ctx, db, s.cfg.ChainHash, row.GraphChannel.ID,
row.Channel, node1.PubKeyBytes, row.GraphChannel, node1.PubKeyBytes,
node2.PubKeyBytes, node2.PubKeyBytes,
) )
if err != nil { if err != nil {
@@ -2385,14 +2387,14 @@ func (s *SQLStore) PruneGraph(spentOutputs []*wire.OutPoint,
} }
info, err := getAndBuildEdgeInfo( info, err := getAndBuildEdgeInfo(
ctx, db, s.cfg.ChainHash, row.Channel.ID, ctx, db, s.cfg.ChainHash, row.GraphChannel.ID,
row.Channel, node1, node2, row.GraphChannel, node1, node2,
) )
if err != nil { if err != nil {
return err return err
} }
err = db.DeleteChannel(ctx, row.Channel.ID) err = db.DeleteChannel(ctx, row.GraphChannel.ID)
if err != nil { if err != nil {
return fmt.Errorf("unable to delete "+ return fmt.Errorf("unable to delete "+
"channel: %w", err) "channel: %w", err)
@@ -2621,14 +2623,14 @@ func (s *SQLStore) DisconnectBlockAtHeight(height uint32) (
} }
channel, err := getAndBuildEdgeInfo( channel, err := getAndBuildEdgeInfo(
ctx, db, s.cfg.ChainHash, row.Channel.ID, ctx, db, s.cfg.ChainHash, row.GraphChannel.ID,
row.Channel, node1, node2, row.GraphChannel, node1, node2,
) )
if err != nil { if err != nil {
return err return err
} }
err = db.DeleteChannel(ctx, row.Channel.ID) err = db.DeleteChannel(ctx, row.GraphChannel.ID)
if err != nil { if err != nil {
return fmt.Errorf("unable to delete "+ return fmt.Errorf("unable to delete "+
"channel: %w", err) "channel: %w", err)
@@ -2863,7 +2865,9 @@ func forEachNodeDirectedChannel(ctx context.Context, db SQLQueries,
err) err)
} }
edge := buildCacheableChannelInfo(row.Channel, node1, node2) edge := buildCacheableChannelInfo(
row.GraphChannel, node1, node2,
)
dbPol1, dbPol2, err := extractChannelPolicies(row) dbPol1, dbPol2, err := extractChannelPolicies(row)
if err != nil { if err != nil {
@@ -3005,8 +3009,8 @@ func forEachNodeChannel(ctx context.Context, db SQLQueries,
} }
edge, err := getAndBuildEdgeInfo( edge, err := getAndBuildEdgeInfo(
ctx, db, chain, row.Channel.ID, row.Channel, node1, ctx, db, chain, row.GraphChannel.ID, row.GraphChannel,
node2, node1, node2,
) )
if err != nil { if err != nil {
return fmt.Errorf("unable to build channel info: %w", 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 // Determine the outgoing and incoming policy for this
// channel and node combo. // channel and node combo.
p1ToNode := row.Channel.NodeID2 p1ToNode := row.GraphChannel.NodeID2
p2ToNode := row.Channel.NodeID1 p2ToNode := row.GraphChannel.NodeID1
outPolicy, inPolicy := p1, p2 outPolicy, inPolicy := p1, p2
if (p1 != nil && p1ToNode == id) || if (p1 != nil && p1ToNode == id) ||
(p2 != nil && p2ToNode != id) { (p2 != nil && p2ToNode != id) {
@@ -3167,7 +3171,7 @@ func getNodeByPubKey(ctx context.Context, db SQLQueries,
// buildCacheableChannelInfo builds a models.CachedEdgeInfo instance from the // buildCacheableChannelInfo builds a models.CachedEdgeInfo instance from the
// provided database channel row and the public keys of the two nodes // provided database channel row and the public keys of the two nodes
// involved in the channel. // involved in the channel.
func buildCacheableChannelInfo(dbChan sqlc.Channel, node1Pub, func buildCacheableChannelInfo(dbChan sqlc.GraphChannel, node1Pub,
node2Pub route.Vertex) *models.CachedEdgeInfo { node2Pub route.Vertex) *models.CachedEdgeInfo {
return &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 // buildNode constructs a LightningNode instance from the given database node
// record. The node's features, addresses and extra signed fields are also // record. The node's features, addresses and extra signed fields are also
// fetched from the database and set on the node. // 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) { *models.LightningNode, error) {
if dbNode.Version != int16(ProtocolV1) { 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 // provided dbChanRow and also fetches any other required information
// to construct the edge info. // to construct the edge info.
func getAndBuildEdgeInfo(ctx context.Context, db SQLQueries, 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) { node2 route.Vertex) (*models.ChannelEdgeInfo, error) {
if dbChan.Version != int16(ProtocolV1) { if dbChan.Version != int16(ProtocolV1) {
@@ -4061,12 +4065,12 @@ func getChanFeaturesAndExtras(ctx context.Context, db SQLQueries,
return fv, extras, nil return fv, extras, nil
} }
// getAndBuildChanPolicies uses the given sqlc.ChannelPolicy and also retrieves // getAndBuildChanPolicies uses the given sqlc.GraphChannelPolicy and also
// all the extra info required to build the complete models.ChannelEdgePolicy // retrieves all the extra info required to build the complete
// types. It returns two policies, which may be nil if the provided // models.ChannelEdgePolicy types. It returns two policies, which may be nil if
// sqlc.ChannelPolicy records are nil. // the provided sqlc.GraphChannelPolicy records are nil.
func getAndBuildChanPolicies(ctx context.Context, db SQLQueries, 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, node2 route.Vertex) (*models.ChannelEdgePolicy,
*models.ChannelEdgePolicy, error) { *models.ChannelEdgePolicy, error) {
@@ -4132,8 +4136,8 @@ func getAndBuildChanPolicies(ctx context.Context, db SQLQueries,
} }
// buildChanPolicy builds a models.ChannelEdgePolicy instance from the // buildChanPolicy builds a models.ChannelEdgePolicy instance from the
// provided sqlc.ChannelPolicy and other required information. // provided sqlc.GraphChannelPolicy and other required information.
func buildChanPolicy(dbPolicy sqlc.ChannelPolicy, channelID uint64, func buildChanPolicy(dbPolicy sqlc.GraphChannelPolicy, channelID uint64,
extras map[uint64][]byte, extras map[uint64][]byte,
toNode route.Vertex) (*models.ChannelEdgePolicy, error) { 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 // buildNodes builds the models.LightningNode instances for the
// given row which is expected to be a sqlc type that contains node information. // given row which is expected to be a sqlc type that contains node information.
func buildNodes(ctx context.Context, db SQLQueries, dbNode1, func buildNodes(ctx context.Context, db SQLQueries, dbNode1,
dbNode2 sqlc.Node) (*models.LightningNode, *models.LightningNode, dbNode2 sqlc.GraphNode) (*models.LightningNode, *models.LightningNode,
error) { error) {
node1, err := buildNode(ctx, db, &dbNode1) node1, err := buildNode(ctx, db, &dbNode1)
@@ -4201,23 +4205,23 @@ func buildNodes(ctx context.Context, db SQLQueries, dbNode1,
return node1, node2, nil 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 // 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. It returns two policies, which may be nil if the policy
// information is not present in the row. // information is not present in the row.
// //
//nolint:ll,dupl,funlen //nolint:ll,dupl,funlen
func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy, func extractChannelPolicies(row any) (*sqlc.GraphChannelPolicy,
error) { *sqlc.GraphChannelPolicy, error) {
var policy1, policy2 *sqlc.ChannelPolicy var policy1, policy2 *sqlc.GraphChannelPolicy
switch r := row.(type) { switch r := row.(type) {
case sqlc.GetChannelByOutpointWithPoliciesRow: case sqlc.GetChannelByOutpointWithPoliciesRow:
if r.Policy1ID.Valid { if r.Policy1ID.Valid {
policy1 = &sqlc.ChannelPolicy{ policy1 = &sqlc.GraphChannelPolicy{
ID: r.Policy1ID.Int64, ID: r.Policy1ID.Int64,
Version: r.Policy1Version.Int16, Version: r.Policy1Version.Int16,
ChannelID: r.Channel.ID, ChannelID: r.GraphChannel.ID,
NodeID: r.Policy1NodeID.Int64, NodeID: r.Policy1NodeID.Int64,
Timelock: r.Policy1Timelock.Int32, Timelock: r.Policy1Timelock.Int32,
FeePpm: r.Policy1FeePpm.Int64, FeePpm: r.Policy1FeePpm.Int64,
@@ -4234,10 +4238,10 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy,
} }
} }
if r.Policy2ID.Valid { if r.Policy2ID.Valid {
policy2 = &sqlc.ChannelPolicy{ policy2 = &sqlc.GraphChannelPolicy{
ID: r.Policy2ID.Int64, ID: r.Policy2ID.Int64,
Version: r.Policy2Version.Int16, Version: r.Policy2Version.Int16,
ChannelID: r.Channel.ID, ChannelID: r.GraphChannel.ID,
NodeID: r.Policy2NodeID.Int64, NodeID: r.Policy2NodeID.Int64,
Timelock: r.Policy2Timelock.Int32, Timelock: r.Policy2Timelock.Int32,
FeePpm: r.Policy2FeePpm.Int64, FeePpm: r.Policy2FeePpm.Int64,
@@ -4258,10 +4262,10 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy,
case sqlc.GetChannelBySCIDWithPoliciesRow: case sqlc.GetChannelBySCIDWithPoliciesRow:
if r.Policy1ID.Valid { if r.Policy1ID.Valid {
policy1 = &sqlc.ChannelPolicy{ policy1 = &sqlc.GraphChannelPolicy{
ID: r.Policy1ID.Int64, ID: r.Policy1ID.Int64,
Version: r.Policy1Version.Int16, Version: r.Policy1Version.Int16,
ChannelID: r.Channel.ID, ChannelID: r.GraphChannel.ID,
NodeID: r.Policy1NodeID.Int64, NodeID: r.Policy1NodeID.Int64,
Timelock: r.Policy1Timelock.Int32, Timelock: r.Policy1Timelock.Int32,
FeePpm: r.Policy1FeePpm.Int64, FeePpm: r.Policy1FeePpm.Int64,
@@ -4278,10 +4282,10 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy,
} }
} }
if r.Policy2ID.Valid { if r.Policy2ID.Valid {
policy2 = &sqlc.ChannelPolicy{ policy2 = &sqlc.GraphChannelPolicy{
ID: r.Policy2ID.Int64, ID: r.Policy2ID.Int64,
Version: r.Policy2Version.Int16, Version: r.Policy2Version.Int16,
ChannelID: r.Channel.ID, ChannelID: r.GraphChannel.ID,
NodeID: r.Policy2NodeID.Int64, NodeID: r.Policy2NodeID.Int64,
Timelock: r.Policy2Timelock.Int32, Timelock: r.Policy2Timelock.Int32,
FeePpm: r.Policy2FeePpm.Int64, FeePpm: r.Policy2FeePpm.Int64,
@@ -4302,10 +4306,10 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy,
case sqlc.GetChannelsByPolicyLastUpdateRangeRow: case sqlc.GetChannelsByPolicyLastUpdateRangeRow:
if r.Policy1ID.Valid { if r.Policy1ID.Valid {
policy1 = &sqlc.ChannelPolicy{ policy1 = &sqlc.GraphChannelPolicy{
ID: r.Policy1ID.Int64, ID: r.Policy1ID.Int64,
Version: r.Policy1Version.Int16, Version: r.Policy1Version.Int16,
ChannelID: r.Channel.ID, ChannelID: r.GraphChannel.ID,
NodeID: r.Policy1NodeID.Int64, NodeID: r.Policy1NodeID.Int64,
Timelock: r.Policy1Timelock.Int32, Timelock: r.Policy1Timelock.Int32,
FeePpm: r.Policy1FeePpm.Int64, FeePpm: r.Policy1FeePpm.Int64,
@@ -4322,10 +4326,10 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy,
} }
} }
if r.Policy2ID.Valid { if r.Policy2ID.Valid {
policy2 = &sqlc.ChannelPolicy{ policy2 = &sqlc.GraphChannelPolicy{
ID: r.Policy2ID.Int64, ID: r.Policy2ID.Int64,
Version: r.Policy2Version.Int16, Version: r.Policy2Version.Int16,
ChannelID: r.Channel.ID, ChannelID: r.GraphChannel.ID,
NodeID: r.Policy2NodeID.Int64, NodeID: r.Policy2NodeID.Int64,
Timelock: r.Policy2Timelock.Int32, Timelock: r.Policy2Timelock.Int32,
FeePpm: r.Policy2FeePpm.Int64, FeePpm: r.Policy2FeePpm.Int64,
@@ -4346,10 +4350,10 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy,
case sqlc.ListChannelsByNodeIDRow: case sqlc.ListChannelsByNodeIDRow:
if r.Policy1ID.Valid { if r.Policy1ID.Valid {
policy1 = &sqlc.ChannelPolicy{ policy1 = &sqlc.GraphChannelPolicy{
ID: r.Policy1ID.Int64, ID: r.Policy1ID.Int64,
Version: r.Policy1Version.Int16, Version: r.Policy1Version.Int16,
ChannelID: r.Channel.ID, ChannelID: r.GraphChannel.ID,
NodeID: r.Policy1NodeID.Int64, NodeID: r.Policy1NodeID.Int64,
Timelock: r.Policy1Timelock.Int32, Timelock: r.Policy1Timelock.Int32,
FeePpm: r.Policy1FeePpm.Int64, FeePpm: r.Policy1FeePpm.Int64,
@@ -4366,10 +4370,10 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy,
} }
} }
if r.Policy2ID.Valid { if r.Policy2ID.Valid {
policy2 = &sqlc.ChannelPolicy{ policy2 = &sqlc.GraphChannelPolicy{
ID: r.Policy2ID.Int64, ID: r.Policy2ID.Int64,
Version: r.Policy2Version.Int16, Version: r.Policy2Version.Int16,
ChannelID: r.Channel.ID, ChannelID: r.GraphChannel.ID,
NodeID: r.Policy2NodeID.Int64, NodeID: r.Policy2NodeID.Int64,
Timelock: r.Policy2Timelock.Int32, Timelock: r.Policy2Timelock.Int32,
FeePpm: r.Policy2FeePpm.Int64, FeePpm: r.Policy2FeePpm.Int64,
@@ -4390,10 +4394,10 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy,
case sqlc.ListChannelsWithPoliciesPaginatedRow: case sqlc.ListChannelsWithPoliciesPaginatedRow:
if r.Policy1ID.Valid { if r.Policy1ID.Valid {
policy1 = &sqlc.ChannelPolicy{ policy1 = &sqlc.GraphChannelPolicy{
ID: r.Policy1ID.Int64, ID: r.Policy1ID.Int64,
Version: r.Policy1Version.Int16, Version: r.Policy1Version.Int16,
ChannelID: r.Channel.ID, ChannelID: r.GraphChannel.ID,
NodeID: r.Policy1NodeID.Int64, NodeID: r.Policy1NodeID.Int64,
Timelock: r.Policy1Timelock.Int32, Timelock: r.Policy1Timelock.Int32,
FeePpm: r.Policy1FeePpm.Int64, FeePpm: r.Policy1FeePpm.Int64,
@@ -4410,10 +4414,10 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy,
} }
} }
if r.Policy2ID.Valid { if r.Policy2ID.Valid {
policy2 = &sqlc.ChannelPolicy{ policy2 = &sqlc.GraphChannelPolicy{
ID: r.Policy2ID.Int64, ID: r.Policy2ID.Int64,
Version: r.Policy2Version.Int16, Version: r.Policy2Version.Int16,
ChannelID: r.Channel.ID, ChannelID: r.GraphChannel.ID,
NodeID: r.Policy2NodeID.Int64, NodeID: r.Policy2NodeID.Int64,
Timelock: r.Policy2Timelock.Int32, Timelock: r.Policy2Timelock.Int32,
FeePpm: r.Policy2FeePpm.Int64, FeePpm: r.Policy2FeePpm.Int64,
+275 -275
View File
File diff suppressed because it is too large. Load diff
+31 -29
View File
@@ -1,32 +1,34 @@
-- Drop indexes. -- Drop indexes.
DROP INDEX IF EXISTS nodes_unique; DROP INDEX IF EXISTS graph_nodes_unique;
DROP INDEX IF EXISTS node_extra_types_unique; DROP INDEX IF EXISTS graph_node_extra_types_unique;
DROP INDEX IF EXISTS node_features_unique; DROP INDEX IF EXISTS graph_node_features_unique;
DROP INDEX IF EXISTS node_addresses_unique; DROP INDEX IF EXISTS graph_node_addresses_unique;
DROP INDEX IF EXISTS node_last_update_idx; DROP INDEX IF EXISTS graph_node_last_update_idx;
DROP INDEX IF EXISTS source_nodes_unique; DROP INDEX IF EXISTS graph_source_nodes_unique;
DROP INDEX IF EXISTS channels_node_id_1_idx; DROP INDEX IF EXISTS graph_channels_node_id_1_idx;
DROP INDEX IF EXISTS channels_node_id_2_idx; DROP INDEX IF EXISTS graph_channels_node_id_2_idx;
DROP INDEX IF EXISTS channels_unique; DROP INDEX IF EXISTS graph_channels_unique;
DROP INDEX IF EXISTS channels_version_outpoint_idx; DROP INDEX IF EXISTS graph_channels_version_outpoint_idx;
DROP INDEX IF EXISTS channel_features_unique; DROP INDEX IF EXISTS graph_channel_features_unique;
DROP INDEX IF EXISTS channel_extra_types_unique; DROP INDEX IF EXISTS graph_channel_extra_types_unique;
DROP INDEX IF EXISTS channel_policies_unique; DROP INDEX IF EXISTS graph_channel_policies_unique;
DROP INDEX IF EXISTS channel_policy_extra_types_unique; DROP INDEX IF EXISTS graph_channel_policy_extra_types_unique;
DROP INDEX IF EXISTS channel_policy_last_update_idx; 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 tables in order of reverse dependencies.
DROP TABLE IF EXISTS channel_policy_extra_types; DROP TABLE IF EXISTS graph_channel_policy_extra_types;
DROP TABLE IF EXISTS channel_policies; DROP TABLE IF EXISTS graph_channel_policies;
DROP TABLE IF EXISTS channel_features; DROP TABLE IF EXISTS graph_channel_features;
DROP TABLE IF EXISTS channel_extra_types; DROP TABLE IF EXISTS graph_channel_extra_types;
DROP TABLE IF EXISTS channels; DROP TABLE IF EXISTS graph_channels;
DROP TABLE IF EXISTS source_nodes; DROP TABLE IF EXISTS graph_source_nodes;
DROP TABLE IF EXISTS node_addresses; DROP TABLE IF EXISTS graph_node_addresses;
DROP TABLE IF EXISTS node_features; DROP TABLE IF EXISTS graph_node_features;
DROP TABLE IF EXISTS node_extra_types; DROP TABLE IF EXISTS graph_node_extra_types;
DROP TABLE IF EXISTS nodes; DROP TABLE IF EXISTS graph_nodes;
DROP TABLE IF EXISTS channel_policy_extra_types; DROP TABLE IF EXISTS graph_channel_policy_extra_types;
DROP TABLE IF EXISTS zombie_channels; DROP TABLE IF EXISTS graph_zombie_channels;
DROP TABLE IF EXISTS prune_log; DROP TABLE IF EXISTS graph_prune_log;
DROP TABLE IF EXISTS closed_scids; DROP TABLE IF EXISTS graph_closed_scids;
+43 -43
View File
@@ -4,7 +4,7 @@
*/ */
-- nodes stores all the nodes that we are aware of in the LN graph. -- 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 -- The db ID of the node. This will only be used DB level
-- relations. -- relations.
id INTEGER PRIMARY KEY, 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 -- A node (identified by a public key) can only have one active node
-- announcement per protocol. -- 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 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 -- 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. -- 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. -- 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. -- The Type field.
type BIGINT NOT NULL, type BIGINT NOT NULL,
@@ -51,26 +51,26 @@ CREATE TABLE IF NOT EXISTS node_extra_types (
-- The value field. -- The value field.
value BLOB 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 type, node_id
); );
-- node_features contains the feature bits of a node. -- 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. -- 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. -- The feature bit value.
feature_bit INTEGER NOT NULL 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_id, feature_bit
); );
-- node_addresses contains the advertised addresses of nodes. -- 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. -- 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 -- An enum that represents the type of address. This will
-- dictate how the address column should be parsed. -- 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. -- The advertised address of the node.
address TEXT NOT NULL 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 node_id, type, position
); );
CREATE TABLE IF NOT EXISTS source_nodes ( CREATE TABLE IF NOT EXISTS graph_source_nodes (
node_id BIGINT NOT NULL REFERENCES nodes (id) ON DELETE CASCADE 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 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. -- 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. -- The db ID of the channel.
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
@@ -113,13 +113,13 @@ CREATE TABLE IF NOT EXISTS channels (
-- The channel id (short channel id) of the channel. -- The channel id (short channel id) of the channel.
scid BLOB NOT NULL, 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. -- 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. -- 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 -- The outpoint of the funding transaction. We chose to store this
-- in a string format for the sake of readability and user queries on -- 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 -- 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. -- 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 graph_channels_node_id_1_idx ON graph_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_2_idx ON graph_channels(node_id_2);
-- A channel (identified by a short channel id) can only have one active -- A channel (identified by a short channel id) can only have one active
-- channel announcement per protocol version. We also order the index by -- 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 -- scid in descending order so that we have an idea of the latest channel
-- announcement we know of. -- announcement we know of.
CREATE UNIQUE INDEX IF NOT EXISTS channels_unique ON channels(version, scid DESC); CREATE UNIQUE INDEX IF NOT EXISTS graph_channels_unique ON graph_channels(version, scid DESC);
CREATE INDEX IF NOT EXISTS channels_version_outpoint_idx ON channels(version, outpoint); CREATE INDEX IF NOT EXISTS graph_channels_version_outpoint_idx ON graph_channels(version, outpoint);
-- channel_features contains the feature bits of a channel. -- 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. -- 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. -- The feature bit value.
feature_bit INTEGER NOT NULL 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_id, feature_bit
); );
-- channel_extra_types stores any extra TLV fields covered by a channels -- 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 -- announcement that we do not have an explicit column for in the channels
-- table. -- 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. -- 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. -- The Type field.
type BIGINT NOT NULL, type BIGINT NOT NULL,
@@ -206,7 +206,7 @@ CREATE TABLE IF NOT EXISTS channel_extra_types (
-- The value field. -- The value field.
value BLOB 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 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. -- The db ID of the channel policy.
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
@@ -223,10 +223,10 @@ CREATE TABLE IF NOT EXISTS channel_policies (
version SMALLINT NOT NULL, version SMALLINT NOT NULL,
-- The DB ID of the channel that this policy is referencing. -- 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. -- 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 -- The number of blocks that the node will subtract from the expiry
-- of an incoming HTLC. -- 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 -- A node can only have a single live policy update for a channel on a
-- given protocol at any given time. -- 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 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 -- 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 -- update that we do not have an explicit column for in the channel_policies
-- table. -- 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. -- 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. -- The Type field.
type BIGINT NOT NULL, type BIGINT NOT NULL,
@@ -308,7 +308,7 @@ CREATE TABLE IF NOT EXISTS channel_policy_extra_types (
-- The value field. -- The value field.
value BLOB 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 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. -- The channel id (short channel id) of the channel.
-- NOTE: we don't use a foreign key here to the `channels` -- NOTE: we don't use a foreign key here to the `channels`
-- table since we may delete the channel record once it -- 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. -- will be able to resurrect the channel.
node_key_2 BLOB node_key_2 BLOB
); );
CREATE UNIQUE INDEX IF NOT EXISTS zombie_channels_channel_id_version_idx CREATE UNIQUE INDEX IF NOT EXISTS graph_zombie_channels_channel_id_version_idx
ON zombie_channels(scid, version); 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. -- The block height that the prune was performed at.
-- NOTE: we don't use INTEGER PRIMARY KEY here since that would -- NOTE: we don't use INTEGER PRIMARY KEY here since that would
-- get transformed into an auto-incrementing type by our SQL type -- 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 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. -- The short channel id of the channel.
scid BLOB PRIMARY KEY scid BLOB PRIMARY KEY
); );
+50 -50
View File
@@ -28,7 +28,7 @@ type AmpSubInvoiceHtlc struct {
Preimage []byte Preimage []byte
} }
type Channel struct { type GraphChannel struct {
ID int64 ID int64
Version int16 Version int16
Scid []byte Scid []byte
@@ -44,18 +44,18 @@ type Channel struct {
Bitcoin2Signature []byte Bitcoin2Signature []byte
} }
type ChannelExtraType struct { type GraphChannelExtraType struct {
ChannelID int64 ChannelID int64
Type int64 Type int64
Value []byte Value []byte
} }
type ChannelFeature struct { type GraphChannelFeature struct {
ChannelID int64 ChannelID int64
FeatureBit int32 FeatureBit int32
} }
type ChannelPolicy struct { type GraphChannelPolicy struct {
ID int64 ID int64
Version int16 Version int16
ChannelID int64 ChannelID int64
@@ -74,16 +74,60 @@ type ChannelPolicy struct {
Signature []byte Signature []byte
} }
type ChannelPolicyExtraType struct { type GraphChannelPolicyExtraType struct {
ChannelPolicyID int64 ChannelPolicyID int64
Type int64 Type int64
Value []byte Value []byte
} }
type ClosedScid struct { type GraphClosedScid struct {
Scid []byte 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 { type Invoice struct {
ID int64 ID int64
Hash []byte Hash []byte
@@ -158,47 +202,3 @@ type MigrationTracker struct {
Version int32 Version int32
MigrationTime time.Time 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
}
+10 -10
View File
@@ -37,15 +37,15 @@ type Querier interface {
GetChannelAndNodesBySCID(ctx context.Context, arg GetChannelAndNodesBySCIDParams) (GetChannelAndNodesBySCIDRow, error) GetChannelAndNodesBySCID(ctx context.Context, arg GetChannelAndNodesBySCIDParams) (GetChannelAndNodesBySCIDRow, error)
GetChannelByOutpoint(ctx context.Context, outpoint string) (GetChannelByOutpointRow, error) GetChannelByOutpoint(ctx context.Context, outpoint string) (GetChannelByOutpointRow, error)
GetChannelByOutpointWithPolicies(ctx context.Context, arg GetChannelByOutpointWithPoliciesParams) (GetChannelByOutpointWithPoliciesRow, 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) GetChannelBySCIDWithPolicies(ctx context.Context, arg GetChannelBySCIDWithPoliciesParams) (GetChannelBySCIDWithPoliciesRow, error)
GetChannelFeaturesAndExtras(ctx context.Context, channelID int64) ([]GetChannelFeaturesAndExtrasRow, 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) GetChannelPolicyExtraTypes(ctx context.Context, arg GetChannelPolicyExtraTypesParams) ([]GetChannelPolicyExtraTypesRow, error)
GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg GetChannelsByPolicyLastUpdateRangeParams) ([]GetChannelsByPolicyLastUpdateRangeRow, error) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg GetChannelsByPolicyLastUpdateRangeParams) ([]GetChannelsByPolicyLastUpdateRangeRow, error)
GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error) GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error)
GetDatabaseVersion(ctx context.Context) (int32, 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 // 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 // from different invoices. It is the caller's responsibility to ensure that
// we bubble up an error in those cases. // we bubble up an error in those cases.
@@ -58,14 +58,14 @@ type Querier interface {
GetKVInvoicePaymentHashByAddIndex(ctx context.Context, addIndex int64) ([]byte, error) GetKVInvoicePaymentHashByAddIndex(ctx context.Context, addIndex int64) ([]byte, error)
GetMigration(ctx context.Context, version int32) (time.Time, error) GetMigration(ctx context.Context, version int32) (time.Time, error)
GetNodeAddressesByPubKey(ctx context.Context, arg GetNodeAddressesByPubKeyParams) ([]GetNodeAddressesByPubKeyRow, error) GetNodeAddressesByPubKey(ctx context.Context, arg GetNodeAddressesByPubKeyParams) ([]GetNodeAddressesByPubKeyRow, error)
GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (Node, error) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (GraphNode, error)
GetNodeFeatures(ctx context.Context, nodeID int64) ([]NodeFeature, error) GetNodeFeatures(ctx context.Context, nodeID int64) ([]GraphNodeFeature, error)
GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error)
GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyParams) (int64, 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) GetPruneHashByHeight(ctx context.Context, blockHeight int64) ([]byte, error)
GetPruneTip(ctx context.Context) (PruneLog, error) GetPruneTip(ctx context.Context) (GraphPruneLog, error)
GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]Channel, error) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]GraphChannel, error)
GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error) GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error)
GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error)
// NOTE: this is V1 specific since for V1, disabled is a // 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 // structure will have a more complex disabled bit vector
// and so the query for V2 may differ. // and so the query for V2 may differ.
GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) 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) HighestSCID(ctx context.Context, version int16) ([]byte, error)
InsertAMPSubInvoice(ctx context.Context, arg InsertAMPSubInvoiceParams) error InsertAMPSubInvoice(ctx context.Context, arg InsertAMPSubInvoiceParams) error
InsertAMPSubInvoiceHTLC(ctx context.Context, arg InsertAMPSubInvoiceHTLCParams) error InsertAMPSubInvoiceHTLC(ctx context.Context, arg InsertAMPSubInvoiceHTLCParams) error
@@ -95,7 +95,7 @@ type Querier interface {
ListChannelsPaginated(ctx context.Context, arg ListChannelsPaginatedParams) ([]ListChannelsPaginatedRow, error) ListChannelsPaginated(ctx context.Context, arg ListChannelsPaginatedParams) ([]ListChannelsPaginatedRow, error)
ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error) ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error)
ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, 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) NextInvoiceSettleIndex(ctx context.Context) (int64, error)
OnAMPSubInvoiceCanceled(ctx context.Context, arg OnAMPSubInvoiceCanceledParams) error OnAMPSubInvoiceCanceled(ctx context.Context, arg OnAMPSubInvoiceCanceledParams) error
OnAMPSubInvoiceCreated(ctx context.Context, arg OnAMPSubInvoiceCreatedParams) error OnAMPSubInvoiceCreated(ctx context.Context, arg OnAMPSubInvoiceCreatedParams) error
+116 -116
View File
@@ -1,10 +1,10 @@
/* ───────────────────────────────────────────── /* ─────────────────────────────────────────────
nodes table queries graph_nodes table queries
───────────────────────────────────────────── ───────────────────────────��─────────────────
*/ */
-- name: UpsertNode :one -- name: UpsertNode :one
INSERT INTO nodes ( INSERT INTO graph_nodes (
version, pub_key, alias, last_update, color, signature version, pub_key, alias, last_update, color, signature
) VALUES ( ) VALUES (
$1, $2, $3, $4, $5, $6 $1, $2, $3, $4, $5, $6
@@ -17,32 +17,32 @@ ON CONFLICT (pub_key, version)
last_update = EXCLUDED.last_update, last_update = EXCLUDED.last_update,
color = EXCLUDED.color, color = EXCLUDED.color,
signature = EXCLUDED.signature signature = EXCLUDED.signature
WHERE nodes.last_update IS NULL WHERE graph_nodes.last_update IS NULL
OR EXCLUDED.last_update > nodes.last_update OR EXCLUDED.last_update > graph_nodes.last_update
RETURNING id; RETURNING id;
-- name: GetNodeByPubKey :one -- name: GetNodeByPubKey :one
SELECT * SELECT *
FROM nodes FROM graph_nodes
WHERE pub_key = $1 WHERE pub_key = $1
AND version = $2; AND version = $2;
-- name: GetNodeIDByPubKey :one -- name: GetNodeIDByPubKey :one
SELECT id SELECT id
FROM nodes FROM graph_nodes
WHERE pub_key = $1 WHERE pub_key = $1
AND version = $2; AND version = $2;
-- name: ListNodesPaginated :many -- name: ListNodesPaginated :many
SELECT * SELECT *
FROM nodes FROM graph_nodes
WHERE version = $1 AND id > $2 WHERE version = $1 AND id > $2
ORDER BY id ORDER BY id
LIMIT $3; LIMIT $3;
-- name: ListNodeIDsAndPubKeys :many -- name: ListNodeIDsAndPubKeys :many
SELECT id, pub_key SELECT id, pub_key
FROM nodes FROM graph_nodes
WHERE version = $1 AND id > $2 WHERE version = $1 AND id > $2
ORDER BY id ORDER BY id
LIMIT $3; LIMIT $3;
@@ -50,8 +50,8 @@ LIMIT $3;
-- name: IsPublicV1Node :one -- name: IsPublicV1Node :one
SELECT EXISTS ( SELECT EXISTS (
SELECT 1 SELECT 1
FROM channels c FROM graph_channels c
JOIN nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2 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 -- NOTE: we hard-code the version here since the clauses
-- here that determine if a node is public is specific -- here that determine if a node is public is specific
-- to the V1 gossip protocol. In V1, a node is public -- to the V1 gossip protocol. In V1, a node is public
@@ -66,37 +66,37 @@ SELECT EXISTS (
); );
-- name: DeleteUnconnectedNodes :many -- name: DeleteUnconnectedNodes :many
DELETE FROM nodes DELETE FROM graph_nodes
WHERE WHERE
-- Ignore any of our source nodes. -- Ignore any of our source nodes.
NOT EXISTS ( NOT EXISTS (
SELECT 1 SELECT 1
FROM source_nodes sn FROM graph_source_nodes sn
WHERE sn.node_id = nodes.id WHERE sn.node_id = graph_nodes.id
) )
-- Select all nodes that do not have any channels. -- Select all nodes that do not have any channels.
AND NOT EXISTS ( AND NOT EXISTS (
SELECT 1 SELECT 1
FROM channels c FROM graph_channels c
WHERE c.node_id_1 = nodes.id OR c.node_id_2 = nodes.id WHERE c.node_id_1 = graph_nodes.id OR c.node_id_2 = graph_nodes.id
) RETURNING pub_key; ) RETURNING pub_key;
-- name: DeleteNodeByPubKey :execresult -- name: DeleteNodeByPubKey :execresult
DELETE FROM nodes DELETE FROM graph_nodes
WHERE pub_key = $1 WHERE pub_key = $1
AND version = $2; AND version = $2;
-- name: DeleteNode :exec -- name: DeleteNode :exec
DELETE FROM nodes DELETE FROM graph_nodes
WHERE id = $1; WHERE id = $1;
/* ───────────────────────────────────────────── /* ─────────────────────────────────────────────
node_features table queries graph_node_features table queries
───────────────────────────────────────────── ─────────────────────────────────────────────
*/ */
-- name: InsertNodeFeature :exec -- name: InsertNodeFeature :exec
INSERT INTO node_features ( INSERT INTO graph_node_features (
node_id, feature_bit node_id, feature_bit
) VALUES ( ) VALUES (
$1, $2 $1, $2
@@ -104,28 +104,28 @@ INSERT INTO node_features (
-- name: GetNodeFeatures :many -- name: GetNodeFeatures :many
SELECT * SELECT *
FROM node_features FROM graph_node_features
WHERE node_id = $1; WHERE node_id = $1;
-- name: GetNodeFeaturesByPubKey :many -- name: GetNodeFeaturesByPubKey :many
SELECT f.feature_bit SELECT f.feature_bit
FROM nodes n FROM graph_nodes n
JOIN node_features f ON f.node_id = n.id JOIN graph_node_features f ON f.node_id = n.id
WHERE n.pub_key = $1 WHERE n.pub_key = $1
AND n.version = $2; AND n.version = $2;
-- name: DeleteNodeFeature :exec -- name: DeleteNodeFeature :exec
DELETE FROM node_features DELETE FROM graph_node_features
WHERE node_id = $1 WHERE node_id = $1
AND feature_bit = $2; AND feature_bit = $2;
/* ───────────────────────────────────────────── /* ─────────────────────────────────────────────
node_addresses table queries graph_node_addresses table queries
───────────────────────────────────────────── ───────────────────────────────────��─────────
*/ */
-- name: InsertNodeAddress :exec -- name: InsertNodeAddress :exec
INSERT INTO node_addresses ( INSERT INTO graph_node_addresses (
node_id, node_id,
type, type,
address, address,
@@ -136,28 +136,28 @@ INSERT INTO node_addresses (
-- name: GetNodeAddressesByPubKey :many -- name: GetNodeAddressesByPubKey :many
SELECT a.type, a.address SELECT a.type, a.address
FROM nodes n FROM graph_nodes n
LEFT JOIN node_addresses a ON a.node_id = n.id LEFT JOIN graph_node_addresses a ON a.node_id = n.id
WHERE n.pub_key = $1 AND n.version = $2 WHERE n.pub_key = $1 AND n.version = $2
ORDER BY a.type ASC, a.position ASC; ORDER BY a.type ASC, a.position ASC;
-- name: GetNodesByLastUpdateRange :many -- name: GetNodesByLastUpdateRange :many
SELECT * SELECT *
FROM nodes FROM graph_nodes
WHERE last_update >= @start_time WHERE last_update >= @start_time
AND last_update < @end_time; AND last_update < @end_time;
-- name: DeleteNodeAddresses :exec -- name: DeleteNodeAddresses :exec
DELETE FROM node_addresses DELETE FROM graph_node_addresses
WHERE node_id = $1; WHERE node_id = $1;
/* ───────────────────────────────────────────── /* ─────────────────────────────────────────────
node_extra_types table queries graph_node_extra_types table queries
───────────────────────────────────────────── ─────────────────────────────────────────────
*/ */
-- name: UpsertNodeExtraType :exec -- name: UpsertNodeExtraType :exec
INSERT INTO node_extra_types ( INSERT INTO graph_node_extra_types (
node_id, type, value node_id, type, value
) )
VALUES ($1, $2, $3) VALUES ($1, $2, $3)
@@ -168,37 +168,37 @@ ON CONFLICT (type, node_id)
-- name: GetExtraNodeTypes :many -- name: GetExtraNodeTypes :many
SELECT * SELECT *
FROM node_extra_types FROM graph_node_extra_types
WHERE node_id = $1; WHERE node_id = $1;
-- name: DeleteExtraNodeType :exec -- name: DeleteExtraNodeType :exec
DELETE FROM node_extra_types DELETE FROM graph_node_extra_types
WHERE node_id = $1 WHERE node_id = $1
AND type = $2; AND type = $2;
/* ───────────────────────────────────────────── /* ─────────────────────────────────────────────
source_nodes table queries graph_source_nodes table queries
───────────────────────────────────────────── ─────────────────────────────────────────────
*/ */
-- name: AddSourceNode :exec -- name: AddSourceNode :exec
INSERT INTO source_nodes (node_id) INSERT INTO graph_source_nodes (node_id)
VALUES ($1) VALUES ($1)
ON CONFLICT (node_id) DO NOTHING; ON CONFLICT (node_id) DO NOTHING;
-- name: GetSourceNodesByVersion :many -- name: GetSourceNodesByVersion :many
SELECT sn.node_id, n.pub_key SELECT sn.node_id, n.pub_key
FROM source_nodes sn FROM graph_source_nodes sn
JOIN nodes n ON sn.node_id = n.id JOIN graph_nodes n ON sn.node_id = n.id
WHERE n.version = $1; WHERE n.version = $1;
/* ───────────────────────────────────────────── /* ─────────────────────────────────────────────
channels table queries graph_channels table queries
───────────────────────────────────────────── ─────────────────────────────────────────────
*/ */
-- name: CreateChannel :one -- name: CreateChannel :one
INSERT INTO channels ( INSERT INTO graph_channels (
version, scid, node_id_1, node_id_2, version, scid, node_id_1, node_id_2,
outpoint, capacity, bitcoin_key_1, bitcoin_key_2, outpoint, capacity, bitcoin_key_1, bitcoin_key_2,
node_1_signature, node_2_signature, bitcoin_1_signature, node_1_signature, node_2_signature, bitcoin_1_signature,
@@ -209,7 +209,7 @@ INSERT INTO channels (
RETURNING id; RETURNING id;
-- name: AddV1ChannelProof :execresult -- name: AddV1ChannelProof :execresult
UPDATE channels UPDATE graph_channels
SET node_1_signature = $2, SET node_1_signature = $2,
node_2_signature = $3, node_2_signature = $3,
bitcoin_1_signature = $4, bitcoin_1_signature = $4,
@@ -221,14 +221,14 @@ WHERE scid = $1
SELECT sqlc.embed(c), SELECT sqlc.embed(c),
n1.pub_key AS node1_pub_key, n1.pub_key AS node1_pub_key,
n2.pub_key AS node2_pub_key n2.pub_key AS node2_pub_key
FROM channels c FROM graph_channels c
JOIN nodes n1 ON c.node_id_1 = n1.id JOIN graph_nodes n1 ON c.node_id_1 = n1.id
JOIN nodes n2 ON c.node_id_2 = n2.id JOIN graph_nodes n2 ON c.node_id_2 = n2.id
WHERE scid >= @start_scid WHERE scid >= @start_scid
AND scid < @end_scid; AND scid < @end_scid;
-- name: GetChannelBySCID :one -- name: GetChannelBySCID :one
SELECT * FROM channels SELECT * FROM graph_channels
WHERE scid = $1 AND version = $2; WHERE scid = $1 AND version = $2;
-- name: GetChannelByOutpoint :one -- name: GetChannelByOutpoint :one
@@ -236,9 +236,9 @@ SELECT
sqlc.embed(c), sqlc.embed(c),
n1.pub_key AS node1_pubkey, n1.pub_key AS node1_pubkey,
n2.pub_key AS node2_pubkey n2.pub_key AS node2_pubkey
FROM channels c FROM graph_channels c
JOIN nodes n1 ON c.node_id_1 = n1.id JOIN graph_nodes n1 ON c.node_id_1 = n1.id
JOIN nodes n2 ON c.node_id_2 = n2.id JOIN graph_nodes n2 ON c.node_id_2 = n2.id
WHERE c.outpoint = $1; WHERE c.outpoint = $1;
-- name: GetChannelAndNodesBySCID :one -- name: GetChannelAndNodesBySCID :one
@@ -246,9 +246,9 @@ SELECT
c.*, c.*,
n1.pub_key AS node1_pub_key, n1.pub_key AS node1_pub_key,
n2.pub_key AS node2_pub_key n2.pub_key AS node2_pub_key
FROM channels c FROM graph_channels c
JOIN nodes n1 ON c.node_id_1 = n1.id JOIN graph_nodes n1 ON c.node_id_1 = n1.id
JOIN nodes n2 ON c.node_id_2 = n2.id JOIN graph_nodes n2 ON c.node_id_2 = n2.id
WHERE c.scid = $1 WHERE c.scid = $1
AND c.version = $2; AND c.version = $2;
@@ -259,7 +259,7 @@ SELECT
cf.feature_bit AS feature_bit, cf.feature_bit AS feature_bit,
NULL AS extra_key, NULL AS extra_key,
NULL AS value NULL AS value
FROM channel_features cf FROM graph_channel_features cf
WHERE cf.channel_id = $1 WHERE cf.channel_id = $1
UNION ALL UNION ALL
@@ -270,11 +270,11 @@ SELECT
0 AS feature_bit, 0 AS feature_bit,
cet.type AS extra_key, cet.type AS extra_key,
cet.value AS value cet.value AS value
FROM channel_extra_types cet FROM graph_channel_extra_types cet
WHERE cet.channel_id = $1; WHERE cet.channel_id = $1;
-- name: GetSCIDByOutpoint :one -- name: GetSCIDByOutpoint :one
SELECT scid from channels SELECT scid from graph_channels
WHERE outpoint = $1 AND version = $2; WHERE outpoint = $1 AND version = $2;
-- name: GetChannelsByPolicyLastUpdateRange :many -- name: GetChannelsByPolicyLastUpdateRange :many
@@ -317,12 +317,12 @@ SELECT
cp2.channel_flags AS policy2_channel_flags, cp2.channel_flags AS policy2_channel_flags,
cp2.signature AS policy2_signature cp2.signature AS policy2_signature
FROM channels c FROM graph_channels c
JOIN nodes n1 ON c.node_id_1 = n1.id JOIN graph_nodes n1 ON c.node_id_1 = n1.id
JOIN nodes n2 ON c.node_id_2 = n2.id JOIN graph_nodes n2 ON c.node_id_2 = n2.id
LEFT JOIN channel_policies cp1 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 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 ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
WHERE c.version = @version WHERE c.version = @version
AND ( AND (
@@ -377,18 +377,18 @@ SELECT
cp2.message_flags AS policy_2_message_flags, cp2.message_flags AS policy_2_message_flags,
cp2.channel_flags AS policy_2_channel_flags, cp2.channel_flags AS policy_2_channel_flags,
cp2.signature AS policy_2_signature cp2.signature AS policy_2_signature
FROM channels c FROM graph_channels c
JOIN nodes n1 ON c.node_id_1 = n1.id JOIN graph_nodes n1 ON c.node_id_1 = n1.id
JOIN nodes n2 ON c.node_id_2 = n2.id JOIN graph_nodes n2 ON c.node_id_2 = n2.id
LEFT JOIN channel_policies cp1 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 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 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; WHERE c.outpoint = $1 AND c.version = $2;
-- name: HighestSCID :one -- name: HighestSCID :one
SELECT scid SELECT scid
FROM channels FROM graph_channels
WHERE version = $1 WHERE version = $1
ORDER BY scid DESC ORDER BY scid DESC
LIMIT 1; LIMIT 1;
@@ -435,26 +435,26 @@ SELECT sqlc.embed(c),
cp2.channel_flags AS policy2_channel_flags, cp2.channel_flags AS policy2_channel_flags,
cp2.signature AS policy2_signature cp2.signature AS policy2_signature
FROM channels c FROM graph_channels c
JOIN nodes n1 ON c.node_id_1 = n1.id JOIN graph_nodes n1 ON c.node_id_1 = n1.id
JOIN nodes n2 ON c.node_id_2 = n2.id JOIN graph_nodes n2 ON c.node_id_2 = n2.id
LEFT JOIN channel_policies cp1 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 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 ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
WHERE c.version = $1 WHERE c.version = $1
AND (c.node_id_1 = $2 OR c.node_id_2 = $2); AND (c.node_id_1 = $2 OR c.node_id_2 = $2);
-- name: GetPublicV1ChannelsBySCID :many -- name: GetPublicV1ChannelsBySCID :many
SELECT * SELECT *
FROM channels FROM graph_channels
WHERE node_1_signature IS NOT NULL WHERE node_1_signature IS NOT NULL
AND scid >= @start_scid AND scid >= @start_scid
AND scid < @end_scid; AND scid < @end_scid;
-- name: ListChannelsPaginated :many -- name: ListChannelsPaginated :many
SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint
FROM channels c FROM graph_channels c
WHERE c.version = $1 AND c.id > $2 WHERE c.version = $1 AND c.id > $2
ORDER BY c.id ORDER BY c.id
LIMIT $3; LIMIT $3;
@@ -501,50 +501,50 @@ SELECT
cp2.channel_flags AS policy2_channel_flags, cp2.channel_flags AS policy2_channel_flags,
cp2.signature AS policy_2_signature cp2.signature AS policy_2_signature
FROM channels c FROM graph_channels c
JOIN nodes n1 ON c.node_id_1 = n1.id JOIN graph_nodes n1 ON c.node_id_1 = n1.id
JOIN nodes n2 ON c.node_id_2 = n2.id JOIN graph_nodes n2 ON c.node_id_2 = n2.id
LEFT JOIN channel_policies cp1 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 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 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 WHERE c.version = $1 AND c.id > $2
ORDER BY c.id ORDER BY c.id
LIMIT $3; LIMIT $3;
-- name: DeleteChannel :exec -- 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 -- name: InsertChannelFeature :exec
INSERT INTO channel_features ( INSERT INTO graph_channel_features (
channel_id, feature_bit channel_id, feature_bit
) VALUES ( ) VALUES (
$1, $2 $1, $2
); );
/* ───────────────────────────────────────────── /* ─────────────────────────────────────────────
channel_extra_types table queries graph_channel_extra_types table queries
───────────────────────────────────────────── ─────────────────────────────────────────────
*/ */
-- name: CreateChannelExtraType :exec -- name: CreateChannelExtraType :exec
INSERT INTO channel_extra_types ( INSERT INTO graph_channel_extra_types (
channel_id, type, value channel_id, type, value
) )
VALUES ($1, $2, $3); VALUES ($1, $2, $3);
/* ───────────────────────────────────────────── /* ─────────────────────────────────────────────
channel_policies table queries graph_channel_policies table queries
───────────────────────────────────────────── ─────────────────────────────────────────────
*/ */
-- name: UpsertEdgePolicy :one -- name: UpsertEdgePolicy :one
INSERT INTO channel_policies ( INSERT INTO graph_channel_policies (
version, channel_id, node_id, timelock, fee_ppm, version, channel_id, node_id, timelock, fee_ppm,
base_fee_msat, min_htlc_msat, last_update, disabled, base_fee_msat, min_htlc_msat, last_update, disabled,
max_htlc_msat, inbound_base_fee_msat, max_htlc_msat, inbound_base_fee_msat,
@@ -569,12 +569,12 @@ ON CONFLICT (channel_id, node_id, version)
message_flags = EXCLUDED.message_flags, message_flags = EXCLUDED.message_flags,
channel_flags = EXCLUDED.channel_flags, channel_flags = EXCLUDED.channel_flags,
signature = EXCLUDED.signature signature = EXCLUDED.signature
WHERE EXCLUDED.last_update > channel_policies.last_update WHERE EXCLUDED.last_update > graph_channel_policies.last_update
RETURNING id; RETURNING id;
-- name: GetChannelPolicyByChannelAndNode :one -- name: GetChannelPolicyByChannelAndNode :one
SELECT * SELECT *
FROM channel_policies FROM graph_channel_policies
WHERE channel_id = $1 WHERE channel_id = $1
AND node_id = $2 AND node_id = $2
AND version = $3; AND version = $3;
@@ -619,23 +619,23 @@ SELECT
cp2.channel_flags AS policy_2_channel_flags, cp2.channel_flags AS policy_2_channel_flags,
cp2.signature AS policy2_signature cp2.signature AS policy2_signature
FROM channels c FROM graph_channels c
JOIN nodes n1 ON c.node_id_1 = n1.id JOIN graph_nodes n1 ON c.node_id_1 = n1.id
JOIN nodes n2 ON c.node_id_2 = n2.id JOIN graph_nodes n2 ON c.node_id_2 = n2.id
LEFT JOIN channel_policies cp1 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 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 ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
WHERE c.scid = @scid WHERE c.scid = @scid
AND c.version = @version; AND c.version = @version;
/* ───────────────────────────────────────────── /* ─────────────────────────────────────────────
channel_policy_extra_types table queries graph_channel_policy_extra_types table queries
───────────────────────────────────────────── ─────────────────────────────────────────────
*/ */
-- name: InsertChanPolicyExtraType :exec -- name: InsertChanPolicyExtraType :exec
INSERT INTO channel_policy_extra_types ( INSERT INTO graph_channel_policy_extra_types (
channel_policy_id, type, value channel_policy_id, type, value
) )
VALUES ($1, $2, $3); VALUES ($1, $2, $3);
@@ -647,15 +647,15 @@ SELECT
cp.node_id, cp.node_id,
cpet.type, cpet.type,
cpet.value cpet.value
FROM channel_policies cp FROM graph_channel_policies cp
JOIN channel_policy_extra_types cpet JOIN graph_channel_policy_extra_types cpet
ON cp.id = cpet.channel_policy_id ON cp.id = cpet.channel_policy_id
WHERE cp.id = $1 OR cp.id = $2; WHERE cp.id = $1 OR cp.id = $2;
-- name: GetV1DisabledSCIDs :many -- name: GetV1DisabledSCIDs :many
SELECT c.scid SELECT c.scid
FROM channels c FROM graph_channels c
JOIN channel_policies cp ON cp.channel_id = c.id JOIN graph_channel_policies cp ON cp.channel_id = c.id
-- NOTE: this is V1 specific since for V1, disabled is a -- NOTE: this is V1 specific since for V1, disabled is a
-- simple, single boolean. The proposed V2 policy -- simple, single boolean. The proposed V2 policy
-- structure will have a more complex disabled bit vector -- structure will have a more complex disabled bit vector
@@ -666,55 +666,55 @@ GROUP BY c.scid
HAVING COUNT(*) > 1; HAVING COUNT(*) > 1;
-- name: DeleteChannelPolicyExtraTypes :exec -- name: DeleteChannelPolicyExtraTypes :exec
DELETE FROM channel_policy_extra_types DELETE FROM graph_channel_policy_extra_types
WHERE channel_policy_id = $1; WHERE channel_policy_id = $1;
/* ───────────────────────────────────────────── /* ─────────────────────────────────────────────
zombie_channels table queries graph_zombie_channels table queries
───────────────────────────────────────────── ─────────────────────────────────────────────
*/ */
-- name: UpsertZombieChannel :exec -- 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) VALUES ($1, $2, $3, $4)
ON CONFLICT (scid, version) ON CONFLICT (scid, version)
DO UPDATE SET DO UPDATE SET
-- If a conflict exists for the SCID and version pair, then we -- If a conflict exists for the SCID and version pair, then we
-- update the node keys. -- update the node keys.
node_key_1 = COALESCE(EXCLUDED.node_key_1, zombie_channels.node_key_1), node_key_1 = COALESCE(EXCLUDED.node_key_1, graph_zombie_channels.node_key_1),
node_key_2 = COALESCE(EXCLUDED.node_key_2, zombie_channels.node_key_2); node_key_2 = COALESCE(EXCLUDED.node_key_2, graph_zombie_channels.node_key_2);
-- name: DeleteZombieChannel :execresult -- name: DeleteZombieChannel :execresult
DELETE FROM zombie_channels DELETE FROM graph_zombie_channels
WHERE scid = $1 WHERE scid = $1
AND version = $2; AND version = $2;
-- name: CountZombieChannels :one -- name: CountZombieChannels :one
SELECT COUNT(*) SELECT COUNT(*)
FROM zombie_channels FROM graph_zombie_channels
WHERE version = $1; WHERE version = $1;
-- name: GetZombieChannel :one -- name: GetZombieChannel :one
SELECT * SELECT *
FROM zombie_channels FROM graph_zombie_channels
WHERE scid = $1 WHERE scid = $1
AND version = $2; AND version = $2;
-- name: IsZombieChannel :one -- name: IsZombieChannel :one
SELECT EXISTS ( SELECT EXISTS (
SELECT 1 SELECT 1
FROM zombie_channels FROM graph_zombie_channels
WHERE scid = $1 WHERE scid = $1
AND version = $2 AND version = $2
) AS is_zombie; ) AS is_zombie;
/* ───────────────────────────────────────────── /* ───────────────────────────���─────────────────
prune_log table queries graph_prune_log table queries
───────────────────────────────────────────── ─────────────────────────────────────────────
*/ */
-- name: UpsertPruneLogEntry :exec -- name: UpsertPruneLogEntry :exec
INSERT INTO prune_log ( INSERT INTO graph_prune_log (
block_height, block_hash block_height, block_hash
) VALUES ( ) VALUES (
$1, $2 $1, $2
@@ -724,33 +724,33 @@ ON CONFLICT(block_height) DO UPDATE SET
-- name: GetPruneTip :one -- name: GetPruneTip :one
SELECT block_height, block_hash SELECT block_height, block_hash
FROM prune_log FROM graph_prune_log
ORDER BY block_height DESC ORDER BY block_height DESC
LIMIT 1; LIMIT 1;
-- name: GetPruneHashByHeight :one -- name: GetPruneHashByHeight :one
SELECT block_hash SELECT block_hash
FROM prune_log FROM graph_prune_log
WHERE block_height = $1; WHERE block_height = $1;
-- name: DeletePruneLogEntriesInRange :exec -- name: DeletePruneLogEntriesInRange :exec
DELETE FROM prune_log DELETE FROM graph_prune_log
WHERE block_height >= @start_height WHERE block_height >= @start_height
AND block_height <= @end_height; AND block_height <= @end_height;
/* ───────────────────────────────────────────── /* ─────────────────────────────────────────────
closed_scid table queries graph_closed_scid table queries
────────────────────────────────────────────- ────────────────────────────────────────────-
*/ */
-- name: InsertClosedChannel :exec -- name: InsertClosedChannel :exec
INSERT INTO closed_scids (scid) INSERT INTO graph_closed_scids (scid)
VALUES ($1) VALUES ($1)
ON CONFLICT (scid) DO NOTHING; ON CONFLICT (scid) DO NOTHING;
-- name: IsClosedChannel :one -- name: IsClosedChannel :one
SELECT EXISTS ( SELECT EXISTS (
SELECT 1 SELECT 1
FROM closed_scids FROM graph_closed_scids
WHERE scid = $1 WHERE scid = $1
); );