Skip to content

Commit a465fb9

Browse files
nGolineclaude
andcommitted
invoice: fix false BROKEN log in cmp_rr_number when sort self-compares
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>
1 parent db4644f commit a465fb9

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

lightningd/invoice.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,12 @@ static int cmp_rr_number(const struct routehint_candidate *a,
606606
if (a->c->rr_number < b->c->rr_number)
607607
return -1;
608608

609-
/* They're unique, so can't be equal */
610-
log_broken(ld->log, "Two equal candidates %p and %p, channels %p and %p, rr_number %"PRIu64" and %"PRIu64,
611-
a, b, a->c, b->c, a->c->rr_number, b->c->rr_number);
609+
/* rr_numbers are unique per channel; equal means same channel.
610+
* Some qsort implementations (notably macOS) compare an element
611+
* with itself, so a->c == b->c is expected and not a bug. */
612+
if (a->c != b->c)
613+
log_broken(ld->log, "Two equal candidates %p and %p, channels %p and %p, rr_number %"PRIu64" and %"PRIu64,
614+
a, b, a->c, b->c, a->c->rr_number, b->c->rr_number);
612615
return 0;
613616
}
614617

0 commit comments

Comments
 (0)