Skip to content

Conversation

@ellemouton
Copy link
Collaborator

@ellemouton ellemouton commented Jun 2, 2025

In this PR, the following schemas are defined for storing graph channel policy data. NOTE the nodes & channels tables here are only to show how they fit in - the full nodes & channels pictures can be seen here and here.

Screenshot 2025-06-02 at 17 43 35

NOTE: here we only define the schemas and add enough queries so that we can implement the UpdateEdgePolicy method. So with this PR we are not really yet testing reading from these new tables. This is left to follow up PRs since those will be quite a lot of code and I want to keep this PR contained as it already contains new schemas etc.

Part of #9795

See #9932 for the full picture that we are aiming at

@ellemouton ellemouton added this to the v0.20.0 milestone Jun 2, 2025
@ellemouton ellemouton self-assigned this Jun 2, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 2, 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 force-pushed the graphSQL9-chan-policies-schema branch from 4cc895b to 96e5716 Compare June 3, 2025 03:56
@ellemouton ellemouton requested review from bhandras and guggero June 3, 2025 03:57
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 good just one question.

@ellemouton
Copy link
Collaborator Author

note: im going to update the chan_policy table here to have explicit colums for inbound fee fields.

So this will then depend on #9897

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 🎉

@ellemouton ellemouton force-pushed the graphSQL9-chan-policies-schema branch from 96e5716 to b59e927 Compare June 11, 2025 13:43
@ellemouton ellemouton changed the base branch from master to elle-graph9 June 11, 2025 13:43
Copy link
Collaborator Author

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

Thanks @bhandras 🙏

Updated this so that the newly added inbound fees columns are in place 👍

@ellemouton ellemouton changed the title graph/db+sqldb: channel policy SQL schemas, queries and upsert CRUD [9] graph/db+sqldb: channel policy SQL schemas, queries and upsert CRUD Jun 11, 2025
@ellemouton ellemouton changed the title [9] graph/db+sqldb: channel policy SQL schemas, queries and upsert CRUD graph/db+sqldb: channel policy SQL schemas, queries and upsert CRUD Jun 11, 2025
@ellemouton ellemouton force-pushed the graphSQL9-chan-policies-schema branch from b59e927 to e882735 Compare June 11, 2025 16:14
@ellemouton ellemouton changed the base branch from elle-graph9 to master June 11, 2025 18:25
@ellemouton ellemouton force-pushed the graphSQL9-chan-policies-schema branch from e882735 to 1950bd5 Compare June 11, 2025 18:25
Ensure that the graph tables are dropped in reverse dependency order.
Define the SQL tables for representing channel policies. Namely:

- channel_policies
- channel_policy_extra_types
In this commit, we introduce a SQLStoreConfig struct which for the time
being only has the ChainHash of the genesis block of the chain this node
is running on. This is used to reconstruct lnwire messages from what we
have persisted in the DB. This means we dont need need to persist the
chain-hash of gossip messages since we know it will always be the same
for a given node. If a node were to be started with a different network,
the lnwire messages it reconstructs for gossip will be invalid.
@ellemouton ellemouton force-pushed the graphSQL9-chan-policies-schema branch from 1950bd5 to b1e8fe5 Compare June 12, 2025 05:17
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.

One potential optimization, otherwise LGTM 🎉

func upsertChanPolicyExtraSignedFields(ctx context.Context, db SQLQueries,
chanPolicyID int64, extraFields map[uint64][]byte) error {

// Get any existing extra signed fields for the channel policy.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why can't we just delete all extra types and insert the new ones?
Would probably be more efficient from a SQL standpoint as well: 1 delete query and a couple of inserts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good point: my original thinking was that mostly the TLV data wont change very often and so we wont actually need to do deletes often. But now thinking about it, while that might be true for other messages, for channel_updates, the only TLV data we have right now (that we know of) is inbound fees which might actually change quite frequently - so yeah - I'll update this to just do a delete 👍
Probs something we can revisit again then at benchmark/tuning time.

In this commit, the various SQL queries are defined that we will need in
order to implement the SQLStore UpdateEdgePolicy method. Channel
policies can be "replaced" and so we use the upsert pattern for them
with the rule that any new channel policy must have a timestamp greater
than the previous one we persisted.

As is done for the KVStore implementation of the method, we use the
batch scheduler for this method.
@ellemouton ellemouton force-pushed the graphSQL9-chan-policies-schema branch from b1e8fe5 to c327988 Compare June 17, 2025 11:43
@ellemouton
Copy link
Collaborator Author

cc @guggero for override merge 🙏
thanks for review!

@guggero guggero merged commit c1740c1 into lightningnetwork:master Jun 17, 2025
32 of 37 checks passed
@ellemouton ellemouton deleted the graphSQL9-chan-policies-schema branch June 17, 2025 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants