Skip to content

[epic]: graph db: SQL implementation & migration #9795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
7 of 63 tasks
ellemouton opened this issue May 8, 2025 · 0 comments
Open
7 of 63 tasks

[epic]: graph db: SQL implementation & migration #9795

ellemouton opened this issue May 8, 2025 · 0 comments
Assignees
Labels
epic Issues created to track large feature development graph migration sql
Milestone

Comments

@ellemouton
Copy link
Collaborator

ellemouton commented May 8, 2025

This is the tracking issue for the graph db SQL-ization project. It will be the go-to reference to see how the project is progressing.

I'll start with a check-list for easy reference & then will add any details & context lower down behind some drop-down tags.

High Level Project Check List

  • Prepare the code (exported methods and tests) such that everything is DB agnostic (ie, hide db specific types and behaviour) in preparation for having things ready to be run against a different DB backend.
  • Introduce an abstract graph DB interface & let the ChannelGraph use this interface instead of a raw pointer.
  • Introduce SQL schema, queries & CRUD
  • Implement the kvdb -> SQL migration for the above stores.
  • Plug the new migration into the main code base & add itest jobs to run against them (behind a feature flag s.t they are not yet available in prod build).
  • Once there is enough confidence in the code & migration, add the SQL impl & migrations to the main prod build

Lower Level Check Lists

1. Prep graph DB code to be ready for new db backend

2. Abstract graph DB interface

3. Introduce SQL schema, queries & CRUD

We'll define the schemas, queries and implement the crud required for each of the following data strucutres:

Note that this will be done in an incremental fashion s.t we are implementing the SQL impl of the new abstract graph store interface method by method. Here are all the methods that will be converted:

  • AddLightningNode
  • AddrsForNode
  • ForEachSourceNodeChannel
  • ForEachNodeChannel
  • ForEachNodeCached
  • ForEachNode
  • ForEachNodeCacheable
  • LookupAlias
  • DeleteLightningNode
  • NodeUpdatesInHorizon
  • FetchLightningNode
  • HasLightningNode
  • IsPublicNode
  • GraphSession
  • ForEachChannel
  • DisabledChannelIDs
  • AddChannelEdge
  • HasChannelEdge
  • DeleteChannelEdges
  • AddEdgeProof
  • ChannelID
  • HighestChanID
  • ChanUpdatesInHorizon
  • FilterKnownChanIDs
  • FilterChannelRange
  • FetchChanInfos
  • FetchChannelEdgesByOutpoint
  • FetchChannelEdgesByID
  • ChannelView
  • MarkEdgeZombie
  • MarkEdgeLive
  • IsZombieEdge
  • NumZombies
  • PutClosedScid
  • IsClosedScid
  • UpdateEdgePolicy
  • SourceNode
  • SetSourceNode
  • PruneTip
  • PruneGraphNodes
  • PruneGraph
  • DisconnectBlockAtHeight

Once all the above is complete we can:

  • run the full uint test suite against the SQL graph impls
  • run the full itest suite against the SQL graph impls

4. Migration

- write the migration code for the graph store along with a test for it - plug in to code behind a dev feature flag

Planned Schemas:

Nodes

NOTE:

  • the block_height column here is just to show how v2 data will fit into the picture. Our initial V1 impl will not include this column

(interact with the schema here)

Image

Channels

NOTES:

  1. the merkle_root_hash and schnorr_sig columns are only for demonstrating how future gossip V2 data will fit in to the picture. They wont be included in the initial schema.
  2. The nodes table here is not complete - it is just to show how channels link to nodes. See "Nodes" section above for details on the nodes table.

(interact here)

Image

Channel Policies

  1. the block_height and disabled_flags columns are just to show how v2 data will fit in. (might split disabled flags into own table? need way to easily query "get all disabled channels in v2")
  2. The nodes and channels tables here are not complete - it is just to show how channel_policies link to channels and to nodes. See "Nodes" & "Channels" sections above for details on the nodes and `channels tables.

Image

Other Graph Tables

Image

Extra checklist not to forget (comments during review):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
epic Issues created to track large feature development graph migration sql
Projects
Status: In progress
Development

No branches or pull requests

2 participants