@@ -5,10 +5,17 @@ import {
55 NetworkConfig ,
66 CreateNodeOptions ,
77} from "@waku/sdk" ;
8- import { DEFAULT_CLUSTER_ID , DEFAULT_NUM_SHARDS } from "@waku/interfaces" ;
8+ import {
9+ AutoSharding ,
10+ DEFAULT_CLUSTER_ID ,
11+ DEFAULT_NUM_SHARDS ,
12+ ShardId ,
13+ StaticSharding ,
14+ } from "@waku/interfaces" ;
915import { bootstrap } from "@libp2p/bootstrap" ;
1016import { EnrDecoder , TransportProtocol } from "@waku/enr" ;
1117import type { ITestBrowser } from "../types/global.js" ;
18+ import { StaticShardingRoutingInfo } from "@waku/utils" ;
1219
1320export interface SerializableSDKProtocolResult {
1421 successes : string [ ] ;
@@ -119,18 +126,22 @@ export class WakuHeadless {
119126 Array . isArray ( staticShards ) &&
120127 staticShards . length > 0
121128 ) {
129+ console . log ( "Using static sharding with shards:" , staticShards ) ;
122130 return {
123131 clusterId,
124- shards : staticShards ,
125- } as NetworkConfig ;
132+ } as StaticSharding ;
126133 }
127134
128135 const numShardsInCluster =
129136 ( providedConfig as any ) ?. numShardsInCluster ?? DEFAULT_NUM_SHARDS ;
137+ console . log (
138+ "Using auto sharding with num shards in cluster:" ,
139+ numShardsInCluster ,
140+ ) ;
130141 return {
131142 clusterId,
132143 numShardsInCluster,
133- } as NetworkConfig ;
144+ } as AutoSharding ;
134145 }
135146
136147 async pushMessageV3 (
@@ -141,7 +152,12 @@ export class WakuHeadless {
141152 if ( ! this . waku ) {
142153 throw new Error ( "Waku node not started" ) ;
143154 }
144- console . log ( "Pushing message via v3 lightpush:" , contentTopic , payload , pubsubTopic ) ;
155+ console . log (
156+ "Pushing message via v3 lightpush:" ,
157+ contentTopic ,
158+ payload ,
159+ pubsubTopic ,
160+ ) ;
145161 console . log ( "Waku node:" , this . waku ) ;
146162 console . log ( "Network config:" , this . networkConfig ) ;
147163
@@ -163,7 +179,20 @@ export class WakuHeadless {
163179 throw new Error ( "Lightpush service not available" ) ;
164180 }
165181
166- const encoder = this . waku . createEncoder ( { contentTopic } ) ;
182+ let shardId : ShardId | undefined ;
183+ if ( pubsubTopic ) {
184+ const staticShardingRoutingInfo =
185+ StaticShardingRoutingInfo . fromPubsubTopic (
186+ pubsubTopic ,
187+ this . networkConfig as StaticSharding ,
188+ ) ;
189+ shardId = staticShardingRoutingInfo ?. shardId ;
190+ }
191+
192+ const encoder = this . waku . createEncoder ( {
193+ contentTopic,
194+ shardId,
195+ } ) ;
167196 console . log ( "Encoder:" , encoder ) ;
168197 console . log ( "Pubsub topic:" , pubsubTopic ) ;
169198 console . log ( "Encoder pubsub topic:" , encoder . pubsubTopic ) ;
@@ -192,7 +221,10 @@ export class WakuHeadless {
192221 ) ;
193222 }
194223 } catch ( error ) {
195- console . error ( "Couldn't send message via preferred lightpush node:" , error ) ;
224+ console . error (
225+ "Couldn't send message via preferred lightpush node:" ,
226+ error ,
227+ ) ;
196228 result = await lightPush . send ( encoder , {
197229 payload : processedPayload ,
198230 timestamp : new Date ( ) ,
@@ -264,7 +296,7 @@ export class WakuHeadless {
264296 filterMultiaddrs : false ,
265297 } ;
266298
267- if ( this . enrBootstrap && this . shouldUseCustomBootstrap ( options ) ) {
299+ if ( this . enrBootstrap ) {
268300 const multiaddrs = await this . getBootstrapMultiaddrs ( ) ;
269301
270302 if ( multiaddrs . length > 0 ) {
@@ -307,7 +339,10 @@ export class WakuHeadless {
307339 await this . waku . dial ( this . lightpushNode ) ;
308340 } catch {
309341 // Ignore dial errors
310- console . warn ( "Failed to dial preferred lightpush node:" , this . lightpushNode ) ;
342+ console . warn (
343+ "Failed to dial preferred lightpush node:" ,
344+ this . lightpushNode ,
345+ ) ;
311346 }
312347 }
313348
0 commit comments