Skip to content

Enforce that node_ids are sorted in channel_announcements#4611

Open
TheBlueMatt wants to merge 1 commit into
lightningdevkit:mainfrom
TheBlueMatt:2026-05-sorted-nodes
Open

Enforce that node_ids are sorted in channel_announcements#4611
TheBlueMatt wants to merge 1 commit into
lightningdevkit:mainfrom
TheBlueMatt:2026-05-sorted-nodes

Conversation

@TheBlueMatt
Copy link
Copy Markdown
Collaborator

We already enforced that nodes can't have a chanel with themselves, but the spec was updated to require strict ordering at lightning/bolts#1333 so we enforce this as well.

@ldk-reviews-bot
Copy link
Copy Markdown

ldk-reviews-bot commented May 11, 2026

🎉 This PR is now ready for review!
Please choose at least one reviewer by assigning them on the right bar.
If no reviewers are assigned within 10 minutes, I'll automatically assign one.
Once the first reviewer has submitted a review, a second will be assigned if required.

Comment thread lightning/src/routing/gossip.rs
@ldk-claude-review-bot
Copy link
Copy Markdown
Collaborator

ldk-claude-review-bot commented May 11, 2026

Review Summary

Inline comments posted

  • lightning/src/routing/gossip.rs:2126get_signed_channel_announcement test helper not updated to sort node_ids (unlike the other two announcement helpers), making callers fragile.

Previously flagged (from prior review, not repeated)

  • lightning/src/routing/gossip.rs:2173update_channel_from_unsigned_announcement_intern still uses == not >= for node_id check (defense-in-depth inconsistency).
  • No test for the strictly-unsorted-but-not-equal case (node_id_1 > node_id_2).

No new bugs found

The core validation logic (>= checks in pre_channel_announcement_validation_check and add_channel_from_partial_announcement) is correct. The test helper updates in test_utils.rs and scoring.rs correctly handle node_id sorting and channel_flags bit 0 adjustment. The RGS binary test data changes are consistent with the sorted node_id requirement.

@ldk-reviews-bot ldk-reviews-bot requested a review from tankyleo May 11, 2026 20:56
@TheBlueMatt TheBlueMatt marked this pull request as draft May 11, 2026 20:59
@TheBlueMatt
Copy link
Copy Markdown
Collaborator Author

Drafting until claude fixes tests.

We already enforced that nodes can't have a chanel with themselves,
but the spec was updated to require strict ordering at
lightning/bolts#1333 so we enforce this as
well.

Test fixes by claude.
@TheBlueMatt TheBlueMatt force-pushed the 2026-05-sorted-nodes branch from 798f08f to 271ac91 Compare May 12, 2026 19:17
@TheBlueMatt TheBlueMatt marked this pull request as ready for review May 12, 2026 19:17
) -> Result<(), LightningError> {
let channels = self.channels.read().unwrap();

if msg.node_id_1 >= msg.node_id_2 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: The get_signed_channel_announcement test helper (defined at line 2838) was not updated to sort node_id_1/node_id_2, unlike the analogous helpers in test_utils.rs (channel_announcement) and scoring.rs (add_channel) which were both updated in this PR.

All callers implicitly rely on the key values ([42; 32]/[41; 32] and [99; 32]/[98; 32] in utxo.rs) happening to produce already-sorted node_ids. If any caller ever uses keys that produce unsorted node_ids, they'll get a cryptic "node_ids in channel_announcements must be sorted" error instead of the expected test behavior.

Consider adding sorting logic to get_signed_channel_announcement as well (while preserving the ability to create intentionally invalid announcements via the f closure for negative tests like the "channel with itself" test at line 3131).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's address this comment ?

@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 94.54545% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.12%. Comparing base (946ee09) to head (271ac91).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/routing/gossip.rs 88.88% 1 Missing ⚠️
lightning/src/routing/scoring.rs 95.45% 1 Missing ⚠️
lightning/src/routing/test_utils.rs 95.45% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4611      +/-   ##
==========================================
+ Coverage   86.11%   86.12%   +0.01%     
==========================================
  Files         157      157              
  Lines      108841   108982     +141     
  Branches   108841   108982     +141     
==========================================
+ Hits        93725    93859     +134     
- Misses      12497    12504       +7     
  Partials     2619     2619              
Flag Coverage Δ
tests 86.12% <94.54%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@tankyleo tankyleo left a comment

Choose a reason for hiding this comment

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

LGTM, just one nit from claude above

) -> Result<(), LightningError> {
let channels = self.channels.read().unwrap();

if msg.node_id_1 >= msg.node_id_2 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's address this comment ?

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