fix: apply modulus in sharding (#3530)

This commit is contained in:
Ivan FB 2025-08-03 17:28:28 +02:00 committed by GitHub
parent 7cfa66837a
commit 7611137c1f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -25,8 +25,7 @@ proc getGenZeroShard*(s: Sharding, topic: NsContentTopic, count: int): RelayShar
# We only use the last 64 bits of the hash as having more shards is unlikely.
let hashValue = uint64.fromBytesBE(hash.data[24 .. 31])
# This is equilavent to modulo shard count but faster
let shard = hashValue and uint64((count - 1))
let shard = hashValue mod uint64(count)
RelayShard(clusterId: s.clusterId, shardId: uint16(shard))