File tree Expand file tree Collapse file tree 1 file changed +23
-5
lines changed
packages/discovery/src/peer-exchange Expand file tree Collapse file tree 1 file changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -207,18 +207,20 @@ export class PeerExchangeDiscovery
207
207
continue ;
208
208
}
209
209
210
+ const hasPrevShardInfo = await this . hasShardInfo ( peerInfo . id ) ;
211
+ const metadata =
212
+ ! hasPrevShardInfo && shardInfo
213
+ ? { metadata : { shardInfo : encodeRelayShard ( shardInfo ) } }
214
+ : undefined ;
215
+
210
216
// merge is smart enough to overwrite only changed parts
211
217
await this . components . peerStore . merge ( peerInfo . id , {
212
218
tags : {
213
219
[ DEFAULT_PEER_EXCHANGE_TAG_NAME ] : {
214
220
value : DEFAULT_PEER_EXCHANGE_TAG_VALUE
215
221
}
216
222
} ,
217
- ...( shardInfo && {
218
- metadata : {
219
- shardInfo : encodeRelayShard ( shardInfo )
220
- }
221
- } ) ,
223
+ ...metadata ,
222
224
...( peerInfo . multiaddrs && {
223
225
multiaddrs : peerInfo . multiaddrs
224
226
} )
@@ -236,6 +238,22 @@ export class PeerExchangeDiscovery
236
238
) ;
237
239
}
238
240
}
241
+
242
+ private async hasShardInfo ( peerId : PeerId ) : Promise < boolean > {
243
+ try {
244
+ const peer = await this . components . peerStore . get ( peerId ) ;
245
+
246
+ if ( ! peer ) {
247
+ return false ;
248
+ }
249
+
250
+ return peer . metadata . has ( "shardInfo" ) ;
251
+ } catch ( err ) {
252
+ log . warn ( `Error getting shard info for ${ peerId . toString ( ) } ` , err ) ;
253
+ }
254
+
255
+ return false ;
256
+ }
239
257
}
240
258
241
259
export function wakuPeerExchangeDiscovery (
You can’t perform that action at this time.
0 commit comments