Conversation
Summary by OctaneNew ContractsNo new contracts were added. Updated Contracts
🔗 Commit Hash: d02f8ee |
| idx := sort.Search(len(nodeLocations), func(i int) bool { | ||
| return topicHash < nodeLocations[i] | ||
| return topicHash >= nodeLocations[i] | ||
| }) |
There was a problem hiding this comment.
🟠 High selectors/stable.go:69
The binary search predicate topicHash >= nodeLocations[i] is inverted, causing sort.Search to always return idx = 0. Since nodeLocations[0] = 0 and any topicHash >= 0 is always true for unsigned integers, all topics route to the first node regardless of hash value, defeating the stable hashing distribution. The correct predicate should find the first node location strictly greater than topicHash.
- idx := sort.Search(len(nodeLocations), func(i int) bool {
- return topicHash >= nodeLocations[i]
- })🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file pkg/api/payer/selectors/stable.go around lines 69-71:
The binary search predicate `topicHash >= nodeLocations[i]` is inverted, causing `sort.Search` to always return `idx = 0`. Since `nodeLocations[0] = 0` and any `topicHash >= 0` is always true for unsigned integers, all topics route to the first node regardless of hash value, defeating the stable hashing distribution. The correct predicate should find the first node location strictly greater than `topicHash`.
Evidence trail:
pkg/api/payer/selectors/stable.go lines 60-71 (REVIEWED_COMMIT) - Shows nodeLocations[i] = uint32(i) * spacing with nodeLocations[0] = 0, and the predicate `topicHash >= nodeLocations[i]` which is always true when i=0 since any uint32 >= 0. Go sort.Search documentation at https://pkg.go.dev/sort#Search confirms it returns the first index where f(i) is true, assuming false→true monotonicity.
ApprovabilityVerdict: Needs human review 1 blocking correctness issue found. This change modifies the binary search predicate in the stable hashing algorithm. An open review comment identifies that the new predicate You can customize Macroscope's approvability policy. Learn more. |
mkysel
left a comment
There was a problem hiding this comment.
the original code is correct
Overview
Detailed findings
|
Fix binary search predicate in
StableHashingNodeSelectorAlgorithm.GetNodeto return first node >= topicHashFixes an inverted predicate in the binary search in stable.go. The condition was changed from
topicHash < nodeLocations[i]totopicHash >= nodeLocations[i], so the algorithm now correctly selects the first node whose virtual position is greater than or equal to the topicHash. Risk: this changes which node is selected for every topic and banlist combination, affecting routing in production.📊 Macroscope summarized d02f8ee. 1 file reviewed, 1 issue evaluated, 0 issues filtered, 1 comment posted
🗂️ Filtered Issues