Skip to content
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

peer: always send channel update on reconnect #8963

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

Roasbeef
Copy link
Member

@Roasbeef Roasbeef commented Aug 1, 2024

We have existing logic to attempt to reliably send a channel update to the remote peer. In the wild, we've seen this fail, as it's possible right when we send the update the peer disconnects.

In this commit, we implement a simple fix which is just to send the chan update each time we connect to the remote party.

Fixes #6870.

@Roasbeef Roasbeef added bug Unintended code behaviour gossip labels Aug 1, 2024
@Roasbeef Roasbeef added this to the v0.18.3 milestone Aug 1, 2024
Copy link
Contributor

coderabbitai bot commented Aug 1, 2024

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.


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?

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>.
    • 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 @coderabbitai in 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 @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@Roasbeef Roasbeef force-pushed the always-send-chan-upd branch from 6c9af4e to ee4b52e Compare August 1, 2024 01:07
@Roasbeef Roasbeef requested review from Crypt-iQ, a team and morehouse and removed request for a team August 1, 2024 01:07
@saubyk saubyk requested a review from yyforyongyu August 1, 2024 15:25
peer/brontide.go Outdated Show resolved Hide resolved
peer/brontide.go Outdated Show resolved Hide resolved
@Roasbeef Roasbeef force-pushed the always-send-chan-upd branch 4 times, most recently from f82ac07 to bf5ff04 Compare August 2, 2024 01:10
Copy link
Member

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

Following this analysis, even a disconnection happens, the msg won't be deleted and will be retried again during the next connection? Unless it's considered stale here,

if s.cfg.IsMsgStale(msg) {
err := s.cfg.MessageStore.DeleteMessage(msg, peerPubKey)

which checks the channel_update via,

lnd/discovery/gossiper.go

Lines 2136 to 2168 in b7c59b3

case *lnwire.ChannelUpdate:
_, p1, p2, err := d.cfg.Graph.GetChannelByID(msg.ShortChannelID)
// If the channel cannot be found, it is most likely a leftover
// message for a channel that was closed, so we can consider it
// stale.
if errors.Is(err, channeldb.ErrEdgeNotFound) {
return true
}
if err != nil {
log.Debugf("Unable to retrieve channel=%v from graph: "+
"%v", msg.ShortChannelID, err)
return false
}
// Otherwise, we'll retrieve the correct policy that we
// currently have stored within our graph to check if this
// message is stale by comparing its timestamp.
var p *models.ChannelEdgePolicy
if msg.ChannelFlags&lnwire.ChanUpdateDirection == 0 {
p = p1
} else {
p = p2
}
// If the policy is still unknown, then we can consider this
// policy fresh.
if p == nil {
return false
}
timestamp := time.Unix(int64(msg.Timestamp), 0)
return p.LastUpdate.After(timestamp)

which seems to be related to #7261.

peer/brontide.go Outdated Show resolved Hide resolved
peer/brontide.go Outdated Show resolved Hide resolved
@Roasbeef
Copy link
Member Author

Roasbeef commented Aug 5, 2024

Following #6870 (comment), even a disconnection happens, the msg won't be deleted and will be retried again during the next connection? Unless it's considered stale here,

Hmm, I think you're right.

For channel updates, staleness comes down to if the on disk update is newer than the one we're trying to send:

lnd/discovery/gossiper.go

Lines 2172 to 2173 in c262b1b

timestamp := time.Unix(int64(msg.Timestamp), 0)
return p.LastUpdate.After(timestamp)
.

So if we haven't sent a newer channel update (compared to the default one we generated once everything confirmed), then this the update won't be seen as stale, and we'll continue to try and send it. However, we do have dynamic enable/disable logic, so if that triggers and disables/enables the channel, it'll generate a newer update, marking the one written to disk as stale.

With all that said, I think this PR does still cover an existing gap:

  • Peer is offline for > 20 mins, causing us to generate a new channel update on disk (enable/disable).
  • Peer comes back online, we try to send, but it actually doesn't get there.
  • Newer update generated for the first step, so we delete it, but they might have not gotten any of the updates.

@Roasbeef Roasbeef force-pushed the always-send-chan-upd branch from bf5ff04 to 5546080 Compare August 6, 2024 00:12
Copy link
Member Author

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

peer/brontide.go Outdated Show resolved Hide resolved
peer/brontide.go Outdated Show resolved Hide resolved
@Roasbeef Roasbeef requested review from yyforyongyu and Crypt-iQ and removed request for morehouse August 6, 2024 00:12
Copy link
Member

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

Cool pending linter and unit tests fix, otherwise it's good to go!

Copy link
Collaborator

@Crypt-iQ Crypt-iQ 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 need to add FetchLastChanUpdate to the test config

@Roasbeef Roasbeef force-pushed the always-send-chan-upd branch from 5546080 to 37cea0e Compare August 7, 2024 00:20
@Roasbeef
Copy link
Member Author

Roasbeef commented Aug 7, 2024

Fixed the unit test issue, and also added a slim one to exercise this new feature (TestAlwaysSendChannelUpdate).

Linter also should be good now....

@Roasbeef Roasbeef added the size/kilo medium, proper context needed, less than 1000 lines label Aug 7, 2024
@Roasbeef Roasbeef force-pushed the always-send-chan-upd branch from 37cea0e to 3e0cbfa Compare August 7, 2024 00:28
Copy link
Member

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

LGTM🦐 Need to fix the new race inTestAlwaysSendChannelUpdate before merging tho.


// TestAlwaysSendChannelUpdate tests that each time we connect to the peer if
// an active channel, we always send the latest channel update.
func TestAlwaysSendChannelUpdate(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

🙏

@Roasbeef Roasbeef force-pushed the always-send-chan-upd branch 2 times, most recently from a6f6fbc to 0add08d Compare August 8, 2024 00:21
We have existing logic to attempt to reliably send a channel update to
the remote peer. In the wild, we've seen this fail, as it's possible
right when we send the update the peer disconnects.

In this commit, we implement a simple fix which is just to send the chan
update each time we connect to the remote party.

Fixes lightningnetwork#6870.
@Roasbeef Roasbeef force-pushed the always-send-chan-upd branch from 0add08d to 9acad37 Compare August 8, 2024 00:50
@Roasbeef Roasbeef merged commit 51f3577 into lightningnetwork:master Aug 8, 2024
23 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unintended code behaviour gossip size/kilo medium, proper context needed, less than 1000 lines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not sending a channel_update for private channels
3 participants