Skip to content

Commit e803123

Browse files
authored
Small fixes for hive (#771)
* CLI: default to supported versions 0 and 1 * RPC: fix sendOffer results * RPC: fix Ping conditional * RPC: repeat fix for other subnetworks * remove congestion control check
1 parent c548c34 commit e803123

3 files changed

Lines changed: 17 additions & 31 deletions

File tree

packages/cli/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const main = async () => {
3737
portalConfig.operatingSystemAndCpuArchitecture = args.arch
3838
portalConfig.shortCommit = args.commit ?? execSync('git rev-parse HEAD').toString().slice(0, 7)
3939
portalConfig.dbSize = dirSize
40+
portalConfig.supportedVersions = [0, 1]
4041
const portal = await createPortalNetwork(portalConfig)
4142

4243
log(`discv5Config: ${JSON.stringify(portal.discv5['config'], null, 2)}`)

packages/cli/src/rpc/modules/portal.ts

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { RunStatusCode } from '@lodestar/light-client'
2020
import type { Debugger } from 'debug'
2121
import type { BeaconNetwork, HistoryNetwork, PortalNetwork, StateNetwork } from 'portalnetwork'
2222
import type { GetEnrResult } from '../schema/types.js'
23+
import { BitArray } from '@chainsafe/ssz'
2324

2425
const 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

packages/portalnetwork/src/wire/utp/Socket/WriteSocket.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,6 @@ export class WriteSocket extends UtpSocket {
9595
}
9696
async sendDataPacket(bytes: Uint8Array): Promise<void> {
9797
this.state = ConnectionState.Connected
98-
try {
99-
await this.packetManager.congestionControl.canSend()
100-
} catch (e) {
101-
this.logger(`DATA packet not acked. Closing connection to ${this.remoteAddress}`)
102-
await this.sendResetPacket()
103-
this.close()
104-
}
10598
const packet = this.createPacket<PacketType.ST_DATA>({
10699
pType: PacketType.ST_DATA,
107100
payload: bytes,

0 commit comments

Comments
 (0)