Skip to content

invoice: fix false BROKEN log in cmp_rr_number when sort self-compares#9153

Open
nGoline wants to merge 1 commit into
ElementsProject:masterfrom
nGoline:xpay-limited-max-accepted-htlcs
Open

invoice: fix false BROKEN log in cmp_rr_number when sort self-compares#9153
nGoline wants to merge 1 commit into
ElementsProject:masterfrom
nGoline:xpay-limited-max-accepted-htlcs

Conversation

@nGoline
Copy link
Copy Markdown
Collaborator

@nGoline nGoline commented May 20, 2026

  • cmp_rr_number() in lightningd/invoice.c logged BROKEN whenever two candidates had equal rr_numbers, but some qsort implementations (notably macOS) call the comparator with the same element against itself (a == b)
  • When a == b, a->c == b->c trivially — not a data corruption
  • Guard the BROKEN log with if (a->c != b->c): only log BROKEN when genuinely different channels share an rr_number
  • This silences the spurious BROKEN log on macOS that caused test_xpay_limited_max_accepted_htlcs to fail with "had BROKEN or That's weird messages" and exit with return code 1

Closes #9035

🤖 Generated with Claude Code

Some qsort implementations (notably macOS) call the comparator with
the same element against itself (a == b).  cmp_rr_number assumed
rr_numbers are unique across distinct channels and logged BROKEN on
any tie, but when a == b then a->c == b->c and the tie is trivially
expected — not a data corruption.

Guard the BROKEN log with `if (a->c != b->c)`: equal channel pointers
mean the same channel entry; only different channels sharing an
rr_number is genuinely broken.  This silences the spurious BROKEN log
on macOS that caused test_xpay_limited_max_accepted_htlcs to fail with
"had BROKEN or That's weird messages".

Changelog-Fixed: invoice: no longer spuriously logs BROKEN when macOS qsort compares a routehint candidate to itself.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@nGoline nGoline force-pushed the xpay-limited-max-accepted-htlcs branch from 0e73ed2 to a465fb9 Compare May 20, 2026 12:14
@sangbida
Copy link
Copy Markdown
Collaborator

I'm okay with this solution if @Lagrang3 is okay with it. When @rustyrussell and I were looking at it last we were considering changing the ccan implementation of asort because there seems to be a bug in it that causes it to be behave differently than the qsort implementation.

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.

pytest: *BROKEN* in test_xpay_limited_max_accepted_htlcs

2 participants