Skip to content

Commit

Permalink
client: add network config options for each portal network
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottyPoi committed Jun 18, 2024
1 parent fcd229f commit e62dfe6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
55 changes: 52 additions & 3 deletions packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import type { CustomCrypto } from '@ethereumjs/common'
import type { GenesisState, PrefixedHexString } from '@ethereumjs/util'
import type { AbstractLevel } from 'abstract-level'
import type { Server as RPCServer } from 'jayson/promise/index.js'
import type { NetworkConfig } from 'portalnetwork'

type Account = [address: Address, privateKey: Uint8Array]

Expand Down Expand Up @@ -462,11 +463,36 @@ const args: ClientOpts = yargs
boolean: true,
default: false,
})
.option('enablePortal', {
.option('enablePortalHistory', {
describe: 'Use Portal Network for historical block retrieval',
boolean: true,
default: false,
})
.option('portalHistory', {
describe: 'node radius (exponent) for history portal network client',
number: true,
default: 0,
})
.option('enablePortalState', {
describe: 'Use Portal Network for historical state retrieval',
boolean: true,
default: false,
})
.option('portalState', {
describe: 'node radius (exponent) for state portal network client',
number: true,
default: 0,
})
.option('enablePortalBeacon', {
describe: 'Use Portal Network for beacon light client data retrieval',
boolean: true,
default: false,
})
.option('portalBeacon', {
describe: 'node radius (exponent) for beacon portal network client',
number: true,
default: 0,
})
.completion()
// strict() ensures that yargs throws when an invalid arg is provided
.strict()
Expand Down Expand Up @@ -1109,10 +1135,33 @@ async function run() {
}

let portal
if (args.enablePortal === true) {
if (
args.enablePortalHistory === true ||
args.enablePortalState === true ||
args.enablePortalBeacon === true
) {
const supportedNetworks: NetworkConfig[] = []
if (args.enablePortalHistory === true) {
supportedNetworks.push({
networkId: NetworkId.HistoryNetwork,
radius: BigInt(2) ** BigInt(args.portalHistory) - BigInt(1),
})
}
if (args.enablePortalState === true) {
supportedNetworks.push({
networkId: NetworkId.StateNetwork,
radius: BigInt(2) ** BigInt(args.portalState) - BigInt(1),
})
}
if (args.enablePortalBeacon === true) {
supportedNetworks.push({
networkId: NetworkId.BeaconLightClientNetwork,
radius: BigInt(2) ** BigInt(args.portalBeacon) - BigInt(1),
})
}
portal = await PortalNetwork.create({
bindAddress: '0.0.0.0',
supportedNetworks: [{ networkId: NetworkId.HistoryNetwork, radius: 2n }],
supportedNetworks,
bootnodes: [
'enr:-Jy4QIs2pCyiKna9YWnAF0zgf7bT0GzlAGoF8MEKFJOExmtofBIqzm71zDvmzRiiLkxaEJcs_Amr7XIhLI74k1rtlXICY5Z0IDAuMS4xLWFscGhhLjEtMTEwZjUwgmlkgnY0gmlwhKEjVaWJc2VjcDI1NmsxoQLSC_nhF1iRwsCw0n3J4jRjqoaRxtKgsEe5a-Dz7y0JloN1ZHCCIyg',
'enr:-Jy4QKSLYMpku9F0Ebk84zhIhwTkmn80UnYvE4Z4sOcLukASIcofrGdXVLAUPVHh8oPCfnEOZm1W1gcAxB9kV2FJywkCY5Z0IDAuMS4xLWFscGhhLjEtMTEwZjUwgmlkgnY0gmlwhJO2oc6Jc2VjcDI1NmsxoQLMSGVlxXL62N3sPtaV-n_TbZFCEM5AR7RDyIwOadbQK4N1ZHCCIyg',
Expand Down
7 changes: 6 additions & 1 deletion packages/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,12 @@ export interface ClientOpts {
skipEngineExec?: boolean
ignoreStatelessInvalidExecs?: boolean
useJsCrypto?: boolean
enablePortal?: boolean
enablePortalHistory?: boolean
enablePortalState?: boolean
enablePortalBeacon?: boolean
portalHistory: number
portalState: number
portalBeacon: number
}

export type PrometheusMetrics = {
Expand Down

0 comments on commit e62dfe6

Please sign in to comment.