From 21ef655b9c22ea0dae8e5487c30777a92810dc2e Mon Sep 17 00:00:00 2001 From: Kim De Mey Date: Fri, 21 Apr 2023 17:00:55 +0200 Subject: [PATCH] Fix dataRadius in result of Portal ping JSON-RPC (#1553) --- fluffy/rpc/rpc_portal_api.nim | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/fluffy/rpc/rpc_portal_api.nim b/fluffy/rpc/rpc_portal_api.nim index e4aed9c9b..ffe49d2ac 100644 --- a/fluffy/rpc/rpc_portal_api.nim +++ b/fluffy/rpc/rpc_portal_api.nim @@ -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]: