Skip to content

Commit

Permalink
RPC: Fix PONG radius return value
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottyPoi committed Dec 12, 2024
1 parent b7d49bc commit 5049c9b
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions packages/cli/src/rpc/modules/portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
FoundContent,
NetworkId,
NodeLookup,
PingPongCustomDataType,
shortId,
} from 'portalnetwork'

Expand Down Expand Up @@ -542,15 +543,17 @@ export class portal {
const pong = await this._history.sendPing(encodedENR)
if (pong) {
this.logger(`PING/PONG successful with ${encodedENR.nodeId}`)
const decoded = PingPongCustomDataType.deserialize(pong.customPayload)
return (
{
enrSeq: Number(pong.enrSeq),
dataRadius: bigIntToHex(decoded.radius),
}
)
} else {
this.logger(`PING/PONG with ${encodedENR.nodeId} was unsuccessful`)
return false
}
return (
pong && {
enrSeq: Number(pong.enrSeq),
dataRadius: bytesToHex(pong.customPayload),
}
)
}
async statePing(params: [string]) {
const [enr] = params
Expand All @@ -559,15 +562,17 @@ export class portal {
const pong = await this._state.sendPing(encodedENR)
if (pong) {
this.logger(`PING/PONG successful with ${encodedENR.nodeId}`)
const decoded = PingPongCustomDataType.deserialize(pong.customPayload)
return (
{
enrSeq: Number(pong.enrSeq),
dataRadius: bigIntToHex(decoded.radius),
}
)
} else {
this.logger(`PING/PONG with ${encodedENR.nodeId} was unsuccessful`)
return false
}
return (
pong && {
enrSeq: Number(pong.enrSeq),
dataRadius: bytesToHex(pong.customPayload),
}
)
}
async beaconPing(params: [string]) {
const [enr] = params
Expand All @@ -576,17 +581,20 @@ export class portal {
const pong = await this._beacon.sendPing(encodedENR)
if (pong) {
this.logger(`PING/PONG successful with ${encodedENR.nodeId}`)
const decoded = PingPongCustomDataType.deserialize(pong.customPayload)
return (
{
enrSeq: Number(pong.enrSeq),
dataRadius: bigIntToHex(decoded.radius),
}
)
} else {
this.logger(`PING/PONG with ${encodedENR.nodeId} was unsuccessful`)
return false
}
return (
pong && {
enrSeq: Number(pong.enrSeq),
dataRadius: bytesToHex(pong.customPayload),
}
)
}


// portal_*FindNodes
async historyFindNodes(params: [string, number[]]) {
const [enr, distances] = params
Expand Down

0 comments on commit 5049c9b

Please sign in to comment.