Fix dataRadius in result of Portal ping JSON-RPC (#1553)

This commit is contained in:
Kim De Mey 2023-04-21 17:00:55 +02:00 committed by GitHub
parent 04137f1c98
commit 21ef655b9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 5 deletions

View File

@ -81,10 +81,9 @@ proc installPortalApiHandlers*(
raise newException(ValueError, "Record not found in DHT lookup.")
rpcServer.rpc("portal_" & network & "Ping") do(
enr: Record) -> tuple[enrSeq: uint64, customPayload: string]:
enr: Record) -> tuple[enrSeq: uint64, dataRadius: UInt256]:
# TODO: Not fully according to spec:
# - missing optional dataRadius
# - customPayload instead of dataRadius returned
# - Missing optional dataRadius parameter
let
node = toNodeWithAddress(enr)
pong = await p.ping(node)
@ -92,8 +91,18 @@ proc installPortalApiHandlers*(
if pong.isErr():
raise newException(ValueError, $pong.error)
else:
let p = pong.get()
return (p.enrSeq, p.customPayload.asSeq().toHex())
let
p = pong.get()
# Note: the SSZ.decode cannot fail here as it has already been verified
# in the ping call.
decodedPayload =
try: SSZ.decode(p.customPayload.asSeq(), CustomPayload)
except MalformedSszError, SszSizeMismatchError:
raiseAssert("Already verified")
return (
p.enrSeq,
decodedPayload.dataRadius
)
rpcServer.rpc("portal_" & network & "FindNodes") do(
enr: Record, distances: seq[uint16]) -> seq[Record]: