Skip to content

Commit 77ede5c

Browse files
MorganaFutureIvansete-status
authored andcommitted
fix: admin API peer shards field from metadata protocol
Store and return peer shard info from metadata protocol exchange instead of only checking ENR records.
1 parent 08d14fb commit 77ede5c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

waku/node/peer_manager/peer_manager.nim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,15 @@ proc onPeerMetadata(pm: PeerManager, peerId: PeerId) {.async.} =
658658
$clusterId
659659
break guardClauses
660660

661+
# Store the shard information from metadata in the peer store
662+
if pm.switch.peerStore.peerExists(peerId):
663+
var peerInfo = pm.switch.peerStore.getPeer(peerId)
664+
peerInfo.shards = metadata.shards.mapIt(it.uint16)
665+
# Note: We don't need to call updatePeerInfo since we modified the reference directly
666+
debug "Updated peer shards from metadata",
667+
peerId = peerId,
668+
shards = peerInfo.shards
669+
661670
return
662671

663672
info "disconnecting from peer", peerId = peerId, reason = reason

waku/waku_core/peers.nim

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type RemotePeerInfo* = ref object
4848
addrs*: seq[MultiAddress]
4949
enr*: Option[enr.Record]
5050
protocols*: seq[string]
51+
shards*: seq[uint16]
5152

5253
agent*: string
5354
protoVersion*: string
@@ -73,6 +74,7 @@ proc init*(
7374
addrs: seq[MultiAddress] = @[],
7475
enr: Option[enr.Record] = none(enr.Record),
7576
protocols: seq[string] = @[],
77+
shards: seq[uint16] = @[],
7678
publicKey: crypto.PublicKey = crypto.PublicKey(),
7779
agent: string = "",
7880
protoVersion: string = "",
@@ -88,6 +90,7 @@ proc init*(
8890
addrs: addrs,
8991
enr: enr,
9092
protocols: protocols,
93+
shards: shards,
9194
publicKey: publicKey,
9295
agent: agent,
9396
protoVersion: protoVersion,
@@ -105,9 +108,10 @@ proc init*(
105108
addrs: seq[MultiAddress] = @[],
106109
enr: Option[enr.Record] = none(enr.Record),
107110
protocols: seq[string] = @[],
111+
shards: seq[uint16] = @[],
108112
): T {.raises: [Defect, ResultError[cstring], LPError].} =
109113
let peerId = PeerID.init(peerId).tryGet()
110-
RemotePeerInfo(peerId: peerId, addrs: addrs, enr: enr, protocols: protocols)
114+
RemotePeerInfo(peerId: peerId, addrs: addrs, enr: enr, protocols: protocols, shards: shards)
111115

112116
## Parse
113117

@@ -327,6 +331,7 @@ converter toRemotePeerInfo*(peerInfo: PeerInfo): RemotePeerInfo =
327331
addrs: peerInfo.listenAddrs,
328332
enr: none(enr.Record),
329333
protocols: peerInfo.protocols,
334+
shards: @[],
330335
agent: peerInfo.agentVersion,
331336
protoVersion: peerInfo.protoVersion,
332337
publicKey: peerInfo.publicKey,
@@ -363,6 +368,9 @@ proc getAgent*(peer: RemotePeerInfo): string =
363368
return peer.agent
364369

365370
proc getShards*(peer: RemotePeerInfo): seq[uint16] =
371+
if peer.shards.len > 0:
372+
return peer.shards
373+
366374
if peer.enr.isNone():
367375
return @[]
368376

0 commit comments

Comments
 (0)