Simplify legacy lightpush autosharding path to a direct getShard call

The single-content-topic path went through getShardsFromContentTopics,
iterated the resulting table under the assumption it was 1-entry, and
had a defensive fallthrough (`resolved = false` → bare `return`) for
the empty-table case. That case is unreachable: on success the table
always has exactly one entry, and the fallthrough returned a default-
initialized Result — not behavior worth preserving.

Replace with the same two-step pattern the modern lightpushPublish uses
(NsContentTopic.parse → sharding.getShard) so both handlers share a
shape and the (now-explicit) failure paths surface useful error strings.

Verified against tests/node/test_wakunode_legacy_lightpush.nim (9/9).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
stubbsta 2026-07-09 10:10:26 +02:00
parent a95dbdfc72
commit af94b3c3cf
No known key found for this signature in database

View File

@ -128,17 +128,11 @@ proc legacyLightpushPublish*(
else:
if node.wakuAutoSharding.isNone():
return err("Pubsub topic must be specified when static sharding is enabled")
let topicMap =
?node.wakuAutoSharding.get().getShardsFromContentTopics(message.contentTopic)
var resolved = false
for pubsub, _ in topicMap.pairs: # There's only one pair anyway
pubsubForPublish = $pubsub
resolved = true
break
if not resolved:
# Preserve pre-existing behavior: an empty topicMap fell off the end
# of the loop and returned the default-initialized Result.
return
let parsedTopic = NsContentTopic.parse(message.contentTopic).valueOr:
return err("Invalid content-topic: " & $error)
let shard = node.wakuAutoSharding.get().getShard(parsedTopic).valueOr:
return err("Autosharding error: " & error)
pubsubForPublish = $shard
let firstResult = await internalPublish(node, pubsubForPublish, msgWithProof, peer)