@@ -20,6 +20,7 @@ import { RunStatusCode } from '@lodestar/light-client'
2020import type { Debugger } from 'debug'
2121import type { BeaconNetwork , HistoryNetwork , PortalNetwork , StateNetwork } from 'portalnetwork'
2222import type { GetEnrResult } from '../schema/types.js'
23+ import { BitArray } from '@chainsafe/ssz'
2324
2425const methods = [
2526 // state
@@ -573,7 +574,7 @@ export class portal {
573574 )
574575
575576 let encodedPayload = undefined
576- if ( payload !== undefined ) {
577+ if ( payload !== undefined && payload !== null ) {
577578 encodedPayload = encodeExtensionPayloadFromJson ( extension , payload )
578579 }
579580 const pong = await this . _history . sendPing ( encodedENR , extension , encodedPayload )
@@ -597,7 +598,7 @@ export class portal {
597598 `PING request received on StateNetwork for ${ shortId ( encodedENR . nodeId ) } with extension ${ extension } ` ,
598599 )
599600 let encodedPayload = undefined
600- if ( payload !== undefined ) {
601+ if ( payload !== undefined && payload !== null ) {
601602 encodedPayload = encodeExtensionPayloadFromJson ( extension , payload )
602603 }
603604 const pong = await this . _state . sendPing ( encodedENR , extension , encodedPayload )
@@ -623,7 +624,7 @@ export class portal {
623624 )
624625
625626 let encodedPayload = undefined
626- if ( payload !== undefined ) {
627+ if ( payload !== undefined && payload !== null ) {
627628 encodedPayload = encodeExtensionPayloadFromJson ( extension , payload )
628629 }
629630
@@ -1159,14 +1160,11 @@ export class portal {
11591160 const contentKeys = contentItems . map ( ( item ) => hexToBytes ( item [ 0 ] ) )
11601161 const contentValues = contentItems . map ( ( item ) => hexToBytes ( item [ 1 ] ) )
11611162 const enr = ENR . decodeTxt ( enrHex )
1162- if ( this . _history . routingTable . getWithPending ( enr . nodeId ) ?. value === undefined ) {
1163- const res = await this . _history . sendPing ( enr )
1164- if ( res === undefined ) {
1165- return '0x'
1166- }
1167- }
11681163 const res = await this . _history . sendOffer ( enr , contentKeys , contentValues )
1169- return res
1164+ if ( res === undefined ) {
1165+ return '0x'
1166+ }
1167+ return res instanceof BitArray ? bytesToHex ( res . uint8Array ) : bytesToHex ( res )
11701168 }
11711169 async stateOffer (
11721170 params : [ string , [ string , string ] [ ] ] ,
@@ -1175,14 +1173,11 @@ export class portal {
11751173 const contentKeys = contentItems . map ( ( item ) => hexToBytes ( item [ 0 ] ) )
11761174 const contentValues = contentItems . map ( ( item ) => hexToBytes ( item [ 1 ] ) )
11771175 const enr = ENR . decodeTxt ( enrHex )
1178- if ( this . _state . routingTable . getWithPending ( enr . nodeId ) ?. value === undefined ) {
1179- const res = await this . _state . sendPing ( enr )
1180- if ( res === undefined ) {
1181- return '0x'
1182- }
1183- }
11841176 const res = await this . _state . sendOffer ( enr , contentKeys , contentValues )
1185- return res
1177+ if ( res === undefined ) {
1178+ return '0x'
1179+ }
1180+ return res instanceof BitArray ? bytesToHex ( res . uint8Array ) : bytesToHex ( res )
11861181 }
11871182 async beaconOffer (
11881183 params : [ string , [ string , string ] [ ] ] ,
@@ -1191,14 +1186,11 @@ export class portal {
11911186 const contentKeys = contentItems . map ( ( item ) => hexToBytes ( item [ 0 ] ) )
11921187 const contentValues = contentItems . map ( ( item ) => hexToBytes ( item [ 1 ] ) )
11931188 const enr = ENR . decodeTxt ( enrHex )
1194- if ( this . _beacon . routingTable . getWithPending ( enr . nodeId ) ?. value === undefined ) {
1195- const res = await this . _beacon . sendPing ( enr )
1196- if ( res === undefined ) {
1197- return '0x'
1198- }
1199- }
12001189 const res = await this . _beacon . sendOffer ( enr , contentKeys , contentValues )
1201- return res
1190+ if ( res === undefined ) {
1191+ return '0x'
1192+ }
1193+ return res instanceof BitArray ? bytesToHex ( res . uint8Array ) : bytesToHex ( res )
12021194 }
12031195
12041196 // portal_*Gossip
0 commit comments