Skip to content

sqldb+graph/db: add channel tables and implement some channel CRUD#9869

Merged
guggero merged 5 commits intolightningnetwork:masterfrom
ellemouton:graphSQL8-channels-schema
Jun 2, 2025
Merged

sqldb+graph/db: add channel tables and implement some channel CRUD#9869
guggero merged 5 commits intolightningnetwork:masterfrom
ellemouton:graphSQL8-channels-schema

Conversation

@ellemouton
Copy link
Collaborator

In this PR, the following schemas are defined for storing graph channel data. NOTE the nodes table here is only to show
how it fits - the full nodes picture can be seen here.

Screenshot 2025-05-27 at 08 56 29

The following methods are then implemented on the SQLStore:

  • AddChannelEdge
  • HighestChanID

This then allows us to run the following unit tests against the SQL backends:

  • TestPartialNode
  • TestAddChannelEdgeShellNodes
  • TestHighestChanID

Part of #9795

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 27, 2025

Important

Review skipped

Auto reviews are limited to specific labels.

🏷️ Labels to auto review (1)
  • llm-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ellemouton ellemouton added this to the v0.20.0 milestone May 27, 2025
@saubyk saubyk added this to lnd v0.20 May 27, 2025
@saubyk saubyk moved this to In progress in lnd v0.20 May 27, 2025
@ellemouton ellemouton self-assigned this May 28, 2025
@ellemouton ellemouton changed the base branch from elle-graph7 to master May 28, 2025 07:32
@ellemouton ellemouton force-pushed the graphSQL8-channels-schema branch 2 times, most recently from 08fc1d6 to 2d0c276 Compare May 28, 2025 08:12
@ellemouton ellemouton requested review from bhandras and guggero May 28, 2025 08:44
@ellemouton ellemouton force-pushed the graphSQL8-channels-schema branch from 2d0c276 to 7720c7d Compare May 28, 2025 11:50
Copy link
Collaborator

@bhandras bhandras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good!

@ellemouton ellemouton requested a review from bhandras May 30, 2025 10:09
Copy link
Collaborator

@bhandras bhandras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🎉

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, LGTM 🎉

node_id_2 BIGINT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,

-- The outpoint of the funding transaction.
outpoint TEXT NOT NULL,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to be hex encoded? Perhaps we can save some bytes here and use a serialized outpoint, stored as a BLOB?

Copy link
Collaborator Author

@ellemouton ellemouton Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so it's currently the string: "txid:index" which is nice for users to be able to query by i'd say.

The other option is to switch it to BLOB and then use our WriteOutpoint encoding helper to serialise the outpoint. But then it isnt really useful from a user perspective

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Def recommend using the string version of any txids we store as reversing bytes is really hard in SQL (likely not even possible in SQLite), so debugging would be quite a bit harder.

@ellemouton ellemouton force-pushed the graphSQL8-channels-schema branch from 7720c7d to 0d15b99 Compare June 2, 2025 12:36
In this commit, we define the SQL schemas for storing graph channel
data. This includes a new `channels` table and a new `channel_features`
table along with various indices.
In preparation for having consistency with the structs created by the
SQLStore and the KVStore (so that they have the same behaviour when
tested by the unit tests), here we make sure not to init the
ExtraOpaqueData field of the LightningNode struct unless there are
actualy bytes to set.
Expand the existing TestAddChannelEdgeShellNodes test so that we have
coverage for error we expect when AddChannelEdge is called a second time
if we already know of a channel.
In this commit, the `AddChannelEdge` method of the SQLStore is
implemented. Like the KVStore implementation, it makes use of the
available channel `batch.Scheduler` and also updates the reject and
channel caches.

This then lets us convert the following 2 unit tests to run against the
SQL backends:
- TestPartialNode
- TestAddChannelEdgeShellNodes
@ellemouton ellemouton force-pushed the graphSQL8-channels-schema branch from 0d15b99 to cf54245 Compare June 2, 2025 12:54
@ellemouton
Copy link
Collaborator Author

cc @guggero for override merge 🙏

@guggero guggero merged commit e9692f8 into lightningnetwork:master Jun 2, 2025
33 of 36 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Done in lnd v0.20 Jun 2, 2025
@ellemouton ellemouton deleted the graphSQL8-channels-schema branch June 2, 2025 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants