@@ -5,10 +5,17 @@ import {
5
5
NetworkConfig ,
6
6
CreateNodeOptions ,
7
7
} 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" ;
9
15
import { bootstrap } from "@libp2p/bootstrap" ;
10
16
import { EnrDecoder , TransportProtocol } from "@waku/enr" ;
11
17
import type { ITestBrowser } from "../types/global.js" ;
18
+ import { StaticShardingRoutingInfo } from "@waku/utils" ;
12
19
13
20
export interface SerializableSDKProtocolResult {
14
21
successes : string [ ] ;
@@ -119,18 +126,22 @@ export class WakuHeadless {
119
126
Array . isArray ( staticShards ) &&
120
127
staticShards . length > 0
121
128
) {
129
+ console . log ( "Using static sharding with shards:" , staticShards ) ;
122
130
return {
123
131
clusterId,
124
- shards : staticShards ,
125
- } as NetworkConfig ;
132
+ } as StaticSharding ;
126
133
}
127
134
128
135
const numShardsInCluster =
129
136
( providedConfig as any ) ?. numShardsInCluster ?? DEFAULT_NUM_SHARDS ;
137
+ console . log (
138
+ "Using auto sharding with num shards in cluster:" ,
139
+ numShardsInCluster ,
140
+ ) ;
130
141
return {
131
142
clusterId,
132
143
numShardsInCluster,
133
- } as NetworkConfig ;
144
+ } as AutoSharding ;
134
145
}
135
146
136
147
async pushMessageV3 (
@@ -141,7 +152,12 @@ export class WakuHeadless {
141
152
if ( ! this . waku ) {
142
153
throw new Error ( "Waku node not started" ) ;
143
154
}
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
+ ) ;
145
161
console . log ( "Waku node:" , this . waku ) ;
146
162
console . log ( "Network config:" , this . networkConfig ) ;
147
163
@@ -163,7 +179,20 @@ export class WakuHeadless {
163
179
throw new Error ( "Lightpush service not available" ) ;
164
180
}
165
181
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
+ } ) ;
167
196
console . log ( "Encoder:" , encoder ) ;
168
197
console . log ( "Pubsub topic:" , pubsubTopic ) ;
169
198
console . log ( "Encoder pubsub topic:" , encoder . pubsubTopic ) ;
@@ -192,7 +221,10 @@ export class WakuHeadless {
192
221
) ;
193
222
}
194
223
} 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
+ ) ;
196
228
result = await lightPush . send ( encoder , {
197
229
payload : processedPayload ,
198
230
timestamp : new Date ( ) ,
@@ -264,7 +296,7 @@ export class WakuHeadless {
264
296
filterMultiaddrs : false ,
265
297
} ;
266
298
267
- if ( this . enrBootstrap && this . shouldUseCustomBootstrap ( options ) ) {
299
+ if ( this . enrBootstrap ) {
268
300
const multiaddrs = await this . getBootstrapMultiaddrs ( ) ;
269
301
270
302
if ( multiaddrs . length > 0 ) {
@@ -307,7 +339,10 @@ export class WakuHeadless {
307
339
await this . waku . dial ( this . lightpushNode ) ;
308
340
} catch {
309
341
// 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
+ ) ;
311
346
}
312
347
}
313
348
0 commit comments