From af94b3c3cf12f3194bd81cade1fab65ed24ddf26 Mon Sep 17 00:00:00 2001 From: stubbsta Date: Thu, 9 Jul 2026 10:10:26 +0200 Subject: [PATCH] Simplify legacy lightpush autosharding path to a direct getShard call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- logos_delivery/waku/node/waku_node/lightpush.nim | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/logos_delivery/waku/node/waku_node/lightpush.nim b/logos_delivery/waku/node/waku_node/lightpush.nim index 256249f8c..ebeb28be4 100644 --- a/logos_delivery/waku/node/waku_node/lightpush.nim +++ b/logos_delivery/waku/node/waku_node/lightpush.nim @@ -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)