Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const main = async () => {
portalConfig.operatingSystemAndCpuArchitecture = args.arch
portalConfig.shortCommit = args.commit ?? execSync('git rev-parse HEAD').toString().slice(0, 7)
portalConfig.dbSize = dirSize
portalConfig.supportedVersions = [0, 1]
const portal = await createPortalNetwork(portalConfig)

log(`discv5Config: ${JSON.stringify(portal.discv5['config'], null, 2)}`)
Expand Down
40 changes: 16 additions & 24 deletions packages/cli/src/rpc/modules/portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { RunStatusCode } from '@lodestar/light-client'
import type { Debugger } from 'debug'
import type { BeaconNetwork, HistoryNetwork, PortalNetwork, StateNetwork } from 'portalnetwork'
import type { GetEnrResult } from '../schema/types.js'
import { BitArray } from '@chainsafe/ssz'

const methods = [
// state
Expand Down Expand Up @@ -573,7 +574,7 @@ export class portal {
)

let encodedPayload = undefined
if (payload !== undefined) {
if (payload !== undefined && payload !== null) {
encodedPayload = encodeExtensionPayloadFromJson(extension, payload)
}
const pong = await this._history.sendPing(encodedENR, extension, encodedPayload)
Expand All @@ -597,7 +598,7 @@ export class portal {
`PING request received on StateNetwork for ${shortId(encodedENR.nodeId)} with extension ${extension}`,
)
let encodedPayload = undefined
if (payload !== undefined) {
if (payload !== undefined && payload !== null) {
encodedPayload = encodeExtensionPayloadFromJson(extension, payload)
}
const pong = await this._state.sendPing(encodedENR, extension, encodedPayload)
Expand All @@ -623,7 +624,7 @@ export class portal {
)

let encodedPayload = undefined
if (payload !== undefined) {
if (payload !== undefined && payload !== null) {
encodedPayload = encodeExtensionPayloadFromJson(extension, payload)
}

Expand Down Expand Up @@ -1159,14 +1160,11 @@ export class portal {
const contentKeys = contentItems.map((item) => hexToBytes(item[0]))
const contentValues = contentItems.map((item) => hexToBytes(item[1]))
const enr = ENR.decodeTxt(enrHex)
if (this._history.routingTable.getWithPending(enr.nodeId)?.value === undefined) {
const res = await this._history.sendPing(enr)
if (res === undefined) {
return '0x'
}
}
const res = await this._history.sendOffer(enr, contentKeys, contentValues)
return res
if (res === undefined) {
return '0x'
}
return res instanceof BitArray ? bytesToHex(res.uint8Array) : bytesToHex(res)
}
async stateOffer(
params: [string, [string, string][]],
Expand All @@ -1175,14 +1173,11 @@ export class portal {
const contentKeys = contentItems.map((item) => hexToBytes(item[0]))
const contentValues = contentItems.map((item) => hexToBytes(item[1]))
const enr = ENR.decodeTxt(enrHex)
if (this._state.routingTable.getWithPending(enr.nodeId)?.value === undefined) {
const res = await this._state.sendPing(enr)
if (res === undefined) {
return '0x'
}
}
const res = await this._state.sendOffer(enr, contentKeys, contentValues)
return res
if (res === undefined) {
return '0x'
}
return res instanceof BitArray ? bytesToHex(res.uint8Array) : bytesToHex(res)
}
async beaconOffer(
params: [string, [string, string][]],
Expand All @@ -1191,14 +1186,11 @@ export class portal {
const contentKeys = contentItems.map((item) => hexToBytes(item[0]))
const contentValues = contentItems.map((item) => hexToBytes(item[1]))
const enr = ENR.decodeTxt(enrHex)
if (this._beacon.routingTable.getWithPending(enr.nodeId)?.value === undefined) {
const res = await this._beacon.sendPing(enr)
if (res === undefined) {
return '0x'
}
}
const res = await this._beacon.sendOffer(enr, contentKeys, contentValues)
return res
if (res === undefined) {
return '0x'
}
return res instanceof BitArray ? bytesToHex(res.uint8Array) : bytesToHex(res)
}

// portal_*Gossip
Expand Down
7 changes: 0 additions & 7 deletions packages/portalnetwork/src/wire/utp/Socket/WriteSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ export class WriteSocket extends UtpSocket {
}
async sendDataPacket(bytes: Uint8Array): Promise<void> {
this.state = ConnectionState.Connected
try {
await this.packetManager.congestionControl.canSend()
} catch (e) {
this.logger(`DATA packet not acked. Closing connection to ${this.remoteAddress}`)
await this.sendResetPacket()
this.close()
}
const packet = this.createPacket<PacketType.ST_DATA>({
pType: PacketType.ST_DATA,
payload: bytes,
Expand Down