lnd
lnd copied to clipboard
localchans: recreate missing edge if not found
Change Description
Description of change / link to associated issue.If a node contains a channel, but doesn't have a corresponding edge in the graph database, updating the channel policy would fail. In this commit the edge is recreated if the channel exists. This ensures a node can recover from a missing edge in the graph database by calling updatechanpolicy.
Alternative for https://github.com/lightningnetwork/lnd/pull/8768, namely option 2 in https://github.com/lightningnetwork/lnd/pull/8768#issuecomment-2143799767
Partially fixes https://github.com/lightningnetwork/lnd/issues/7261 by allowing to recreate the edge by calling updatechanpolicy.
Steps to Test
- Create a node that has a channel with a missing edge
- Calling getchaninfo on this channel will fail
- Call updatechanpolicy on this channel
- Calling getchaninfo on this channel should succeed
I'm not sure how to create an integration test where I can modify the graph database to delete an edge in order to test this. Please advise.
Pull Request Checklist
Testing
- [x] Your PR passes all CI checks.
- [x] Tests covering the positive and negative (error paths) are included.
- [x] Bug fixes contain tests triggering the bug to prevent regressions.
Code Style and Documentation
- [x] The change obeys the Code Documentation and Commenting guidelines, and lines wrap at 80.
- [x] Commits follow the Ideal Git Commit Structure.
- [x] Any new logging statements use an appropriate subsystem and logging level.
- [x] Any new lncli commands have appropriate tags in the comments for the rpc in the proto file.
- [x] There is a change description in the release notes, or
[skip ci]in the commit message for small changes.
📝 Please see our Contribution Guidelines for further guidance.
[!IMPORTANT]
Review skipped
Auto reviews are limited to specific labels.
:label: Labels to auto review (1)
- llm-review
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
🪧 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.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin 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 generate unit testing code.@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.
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 pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.
Release notes need to be moved to the v0.18.1 file.
Maybe it's related to this?
Maybe it's related to https://github.com/lightningnetwork/lnd/issues/8870#issuecomment-2192464477?
Hmm I don't think so, not having the edge available means somehow that our own ChanAnnouncment didn't got through? Not receiving the node announcment would just leave us with a NodeAnnouncement Shell, we add during adding the edge to the db.
Concept Ack from my side as well, I think it's the best way to fix broken channels suffering from the Edge not Found problem. I think we still have not traced down the origin of the problem, this gives us at least the possibility to mitigate the problem.
Sorry for letting this sit for so long. Updated with your feedback now @yyforyongyu
what about passing the graph db as a config to the localchan_manager, so that we can when recreating the edge just call AddChannelEdge and short-circuit all the other stuff which is done in the gossiper ? Later during the ChanUpdate (PropagateChanPolicyUpdate) all the necessary stuff is done (adding the update to the Topology etc.).
It's a mitigation to a unknown bug anyways which we will find as soon as we improved logging in the gossiper.
Handled most comments. Still have to create a test.
Added a test for createEdge
Now also added a test to the UpdatePolicy function
Handled Ziggie's comments.
If this gets a thumbs up, we'll try it out in production to see whether it helps with our edge not found issues.
Awesome job @JssDWt 🎉, thanks for fixing this in LND. Just a little style nit.
I will approve this PR once you give us feedback how your local testing went but it's gtg from my side.
@JssDWt have you tested already, because we are planning to ship it in 18.3 ?
@ziggie1984 you can't ship it with 0.18.3. There was a crash. I'm afk for the next week, I'll look at it next week.
@ziggie1984 you can't ship it with 0.18.3. There was a crash. I'm afk for the next week, I'll look at it next week.
Moved to 0.19
Added a fix for a crash, because SchedulerOptions were nil.
Rebased
Just for general information this was the problem:
AddEdge: func(edge *models.ChannelEdgeInfo) error {
return s.chanRouter.AddEdge(edge, nil)}
by accident we provided a nil for the SchedulerOptions
now it's fixed, we don't test db interaction in the unit-test case.
AddEdge: func(edge *models.ChannelEdgeInfo) error {
return s.graphBuilder.AddEdge(edge)
},
However I think because this happened lets add a nil checke here:
for _, f := range op {
if f != nil{
f(r)
}
}
better safe than sorry.
Noting that during the rebase I had to replace chanRouter with graphBuilder here.
However I think because this happened lets add a
nilchecke here:for _, f := range op { if f != nil{ f(r) } }better safe than sorry.
Added this in this PR
Fixed a bug where the timestamp was not set, so the policy wouldn't be added.
And rebased.
Added a commit that ensures the policy is also recreated if the edge exists, but only not the policy.
Looking good, waiting your final test and hope we can get this thing merged then.
Will approve as soon as @JssDWt reports back that this actually fixes the problem of missing edges, so it is only on hold because we cannot easily reproduce missing edgeinfo in a db testing it in an itest.
Will approve as soon as @JssDWt reports back that this actually fixes the problem of missing edges, so it is only on hold because we cannot easily reproduce missing
edgeinfoin a db testing it in an itest.
Ah, sorry. Wasn't sure if the latest push contained those (probably should've checked :sweat_smile:).
@jssdwt, remember to re-request review from reviewers when ready
Added comments that the ForAllOutgoingChannels function may invoke the callback with a nil channel policy.
Also rebased.
Ok let's not change too much right now let's do the following:
-
We cannot just log a warning in the
edge=nilcase, with the combination ofcreateMissingEdgewe would attempt in the worst case scenario to readd an edge => so let's return an error here, because that should never be the case. -
In
updateEdge=> use a NON-Pointer for the*models.ChannelEdgePolicy -
remove this form updateEdge:
if edge == nil { _, edge, err = r.createEdge(channel, time.Now()) if err != nil { return nil, err } }
We now check the policy so I don't think there is a need for the above.
Then we should be good to go
I undid the tryout commit.
- In
updateEdge=> use a NON-Pointer for the*models.ChannelEdgePolicy
This we can't do, because that wouldn't update the edge outside the updateEdge function.
- We cannot just log a warning in the
edge=nilcase, with the combination ofcreateMissingEdgewe would attempt in the worst case scenario to readd an edge => so let's return an error here, because that should never be the case.- remove this form updateEdge:
if edge == nil { _, edge, err = r.createEdge(channel, time.Now()) if err != nil { return nil, err } }
So this basically means revert commit 7d9d100e94cab9fc5adce139fe2a9a8b3dd77538 correct?
That would also address this comment: https://github.com/lightningnetwork/lnd/pull/8805#discussion_r1845605281
This we can't do, because that wouldn't update the edge outside the updateEdge function.
I am not sure I understand, I am talking about the func (r *Manager) updateEdge(tx kvdb.RTx, chanPoint wire.OutPoint, function, which is only used 2 times and also returns the specified edge so we can use the return value here, as we currently do anyways ?