@@ -16,18 +16,19 @@ import {
16
16
wakuStore
17
17
} from "@waku/core" ;
18
18
import { enrTree , wakuDnsDiscovery } from "@waku/dns-discovery" ;
19
- import type {
20
- CreateLibp2pOptions ,
21
- FullNode ,
22
- IMetadata ,
23
- Libp2p ,
24
- Libp2pComponents ,
25
- LightNode ,
26
- ProtocolCreateOptions ,
27
- ShardingParams
19
+ import {
20
+ type CreateLibp2pOptions ,
21
+ type FullNode ,
22
+ type IMetadata ,
23
+ type Libp2p ,
24
+ type Libp2pComponents ,
25
+ type LightNode ,
26
+ type ProtocolCreateOptions ,
27
+ type ShardInfo
28
28
} from "@waku/interfaces" ;
29
29
import { wakuPeerExchangeDiscovery } from "@waku/peer-exchange" ;
30
30
import { RelayCreateOptions , wakuGossipSub , wakuRelay } from "@waku/relay" ;
31
+ import { ensureShardingConfigured } from "@waku/utils" ;
31
32
import { createLibp2p } from "libp2p" ;
32
33
33
34
const DEFAULT_NODE_REQUIREMENTS = {
@@ -38,17 +39,6 @@ const DEFAULT_NODE_REQUIREMENTS = {
38
39
39
40
export { Libp2pComponents } ;
40
41
41
- const ensureShardingConfigured = ( shardInfo : ShardingParams ) : void => {
42
- if (
43
- ( "shards" in shardInfo && shardInfo . shards . length < 1 ) ||
44
- ( "contentTopics" in shardInfo && shardInfo . contentTopics . length < 1 )
45
- ) {
46
- throw new Error (
47
- "Missing required configuration options for static sharding or autosharding."
48
- ) ;
49
- }
50
- } ;
51
-
52
42
/**
53
43
* Create a Waku node configured to use autosharding or static sharding.
54
44
*/
@@ -61,7 +51,7 @@ export async function createNode(
61
51
throw new Error ( "Shard info must be set" ) ;
62
52
}
63
53
64
- ensureShardingConfigured ( options . shardInfo ) ;
54
+ const shardInfo = ensureShardingConfigured ( options . shardInfo ) ;
65
55
66
56
const libp2pOptions = options ?. libp2p ?? { } ;
67
57
const peerDiscovery = libp2pOptions . peerDiscovery ?? [ ] ;
@@ -71,7 +61,7 @@ export async function createNode(
71
61
}
72
62
73
63
const libp2p = await defaultLibp2p (
74
- undefined ,
64
+ shardInfo . shardInfo ,
75
65
wakuGossipSub ( options ) ,
76
66
libp2pOptions ,
77
67
options ?. userAgent
@@ -85,7 +75,7 @@ export async function createNode(
85
75
options ?? { } ,
86
76
[ ] ,
87
77
libp2p ,
88
- options . shardInfo ,
78
+ shardInfo . shardInfo ,
89
79
store ,
90
80
lightPush ,
91
81
filter
@@ -102,9 +92,9 @@ export async function createLightNode(
102
92
) : Promise < LightNode > {
103
93
options = options ?? { } ;
104
94
105
- if ( options . shardInfo ) {
106
- ensureShardingConfigured ( options . shardInfo ) ;
107
- }
95
+ const shardInfo = options . shardInfo
96
+ ? ensureShardingConfigured ( options . shardInfo )
97
+ : undefined ;
108
98
109
99
const libp2pOptions = options ?. libp2p ?? { } ;
110
100
const peerDiscovery = libp2pOptions . peerDiscovery ?? [ ] ;
@@ -114,7 +104,7 @@ export async function createLightNode(
114
104
}
115
105
116
106
const libp2p = await defaultLibp2p (
117
- options . shardInfo ,
107
+ shardInfo ? .shardInfo ,
118
108
wakuGossipSub ( options ) ,
119
109
libp2pOptions ,
120
110
options ?. userAgent
@@ -128,7 +118,7 @@ export async function createLightNode(
128
118
options ?? { } ,
129
119
options . pubsubTopics ,
130
120
libp2p ,
131
- options . shardInfo ,
121
+ shardInfo ?. shardingParams ,
132
122
store ,
133
123
lightPush ,
134
124
filter
@@ -153,9 +143,9 @@ export async function createFullNode(
153
143
) : Promise < FullNode > {
154
144
options = options ?? { } ;
155
145
156
- if ( options . shardInfo ) {
157
- ensureShardingConfigured ( options . shardInfo ) ;
158
- }
146
+ const shardInfo = options . shardInfo
147
+ ? ensureShardingConfigured ( options . shardInfo )
148
+ : undefined ;
159
149
160
150
const libp2pOptions = options ?. libp2p ?? { } ;
161
151
const peerDiscovery = libp2pOptions . peerDiscovery ?? [ ] ;
@@ -165,7 +155,7 @@ export async function createFullNode(
165
155
}
166
156
167
157
const libp2p = await defaultLibp2p (
168
- options . shardInfo ,
158
+ shardInfo ? .shardInfo ,
169
159
wakuGossipSub ( options ) ,
170
160
libp2pOptions ,
171
161
options ?. userAgent
@@ -180,7 +170,7 @@ export async function createFullNode(
180
170
options ?? { } ,
181
171
options . pubsubTopics ,
182
172
libp2p ,
183
- options . shardInfo ,
173
+ shardInfo ?. shardingParams ,
184
174
store ,
185
175
lightPush ,
186
176
filter ,
@@ -207,7 +197,7 @@ type MetadataService = {
207
197
} ;
208
198
209
199
export async function defaultLibp2p (
210
- shardInfo ?: ShardingParams ,
200
+ shardInfo ?: ShardInfo ,
211
201
wakuGossipSub ?: PubsubService [ "pubsub" ] ,
212
202
options ?: Partial < CreateLibp2pOptions > ,
213
203
userAgent ?: string
0 commit comments