Skip to content

gossipd: check for existing channel announcement before sigcheck #8322

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

Merged

Conversation

whitslack
Copy link
Collaborator

Checking a signature is a CPU-intensive operation that should be performed only if gossmap doesn't already have the channel announcement in question and we're not already checking for the announcement's UTxO.

Changelog-Fixed: gossipd doesn't waste CPU cycles checking signatures on channel announcements that are already known
Issue: #7972

Checklist

Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:

  • The changelog has been updated in the relevant commit(s) according to the guidelines.
  • Tests have been added or modified to reflect the changes. (No relevant changes; tests still pass.)
  • Documentation has been reviewed and updated as needed. (No documentation needed.)
  • Related issues have been listed and linked, including any that this PR closes.

Checking a signature is a CPU-intensive operation that should be performed only
if gossmap doesn't already have the channel announcement in question and we're
not already checking for the announcement's UTxO.

Changelog-Fixed: `gossipd` doesn't waste CPU cycles checking signatures on channel announcements that are already known
Issue: ElementsProject#7972
Copy link
Member

@cdecker cdecker left a comment

Choose a reason for hiding this comment

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

ACK

I guess the assumption was that seeking in the gossmap for the node would be more expensive than the signature check. But if experiments show that not to be true, this is good.

@whitslack
Copy link
Collaborator Author

whitslack commented Jun 5, 2025

I guess the assumption was that seeking in the gossmap for the node would be more expensive than the signature check.

A few syscalls to read from an open file descriptor (especially when the requested pages are already hot in cache) constitute much less work than checking an ECDSA signature. lightning_gossipd was one of the most CPU-hungry processes on my system previously, and now it's barely on the radar.

EDIT: Actually, looking at the perf report, it looks as though gossipd mmaps the gossip store, so that's even better. Instead of a few syscalls to read from an open file descriptor, you only have potentially a few page faults to fetch pages of a mapped file in the worst case and only hot memory reads in the best case. Not even close to the same order of magnitude as ECDSA signature verification.

Note: gossipd really ought to be using asyncio to service gossmap queries since it's a single-threaded process that services a queue of requests by consulting the disk. Modern storage subsystems can support hundreds of overlapped requests, but gossipd presently is only ever submitting one at a time.

@rustyrussell rustyrussell added this to the v25.05 milestone Jun 6, 2025
@endothermicdev endothermicdev merged commit 3f6cd59 into ElementsProject:master Jun 10, 2025
38 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants