Skip to content

Commit

Permalink
fix announced shards
Browse files Browse the repository at this point in the history
  • Loading branch information
alrevuelta committed Mar 12, 2024
1 parent 3fc208b commit 39e125a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
9 changes: 5 additions & 4 deletions tests/wakunode_rest/test_rest_relay.nim
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ suite "Waku v2 Rest API - Relay":
let node = testWakuNode()
await node.start()
await node.mountRelay()
require node.mountSharding(1, 8).isOk

var restPort = Port(0)
let restAddress = parseIpAddress("0.0.0.0")
Expand All @@ -268,9 +269,9 @@ suite "Waku v2 Rest API - Relay":
restServer.start()

let contentTopics = @[
ContentTopic("/waku/2/default-content1/proto"),
ContentTopic("/waku/2/default-content2/proto"),
ContentTopic("/waku/2/default-content3/proto")
ContentTopic("/app-1/2/default-content/proto"),
ContentTopic("/app-2/2/default-content/proto"),
ContentTopic("/app-3/2/default-content/proto")
]

# When
Expand All @@ -290,7 +291,7 @@ suite "Waku v2 Rest API - Relay":

check:
# Node should be subscribed to all shards
toSeq(node.wakuRelay.subscribedTopics).len == 3
node.wakuRelay.subscribedTopics == @["/waku/2/rs/1/7", "/waku/2/rs/1/2", "/waku/2/rs/1/5"]

await restServer.stop()
await restServer.closeWait()
Expand Down
4 changes: 3 additions & 1 deletion waku/factory/internal_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ proc enrConfiguration*(conf: WakuNodeConf, netConfig: NetConfig, key: crypto.Pri
enrBuilder.withMultiaddrs(netConfig.enrMultiaddrs)

let shards: seq[uint16] =
if conf.shards.len == 0: toSeq(0..8).mapIt(uint16(it))
# no shards configured
if conf.shards.len == 0: toSeq(0..<conf.topics.len).mapIt(uint16(it))
# some shards configured
else: toSeq(conf.shards.mapIt(uint16(it)))

enrBuilder.withWakuRelaySharding(RelayShards(clusterId:uint16(conf.clusterId), shardIds: shards)).isOkOr():
Expand Down
4 changes: 4 additions & 0 deletions waku/node/waku_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ proc mountMetadata*(node: WakuNode, clusterId: uint32): Result[void, string] =

## Waku Sharding
proc mountSharding*(node: WakuNode, clusterId: uint32, shardCount: uint32): Result[void, string] =
info "mounting sharding", clusterId=clusterId, shardCount=shardCount
node.wakuSharding = Sharding(clusterId: clusterId, shardCountGenZero: shardCount)
return ok()

Expand Down Expand Up @@ -261,9 +262,12 @@ proc subscribe*(node: WakuNode, subscription: SubscriptionEvent, handler = none(
let (pubsubTopic, contentTopicOp) =
case subscription.kind:
of ContentSub:
echo "ente content sub"
let shard = node.wakuSharding.getShard((subscription.topic)).valueOr:
error "Autosharding error", error=error
return
echo "shard:", shard
echo "subtc", subscription.topic

(shard, some(subscription.topic))
of PubsubSub: (subscription.topic, none(ContentTopic))
Expand Down

0 comments on commit 39e125a

Please sign in to comment.