Skip to content

Commit 9172690

Browse files
author
ScottyPoi
committed
RPC: use chain specific subnetworks
1 parent ddb9068 commit 9172690

4 files changed

Lines changed: 15 additions & 13 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ContentLookup,
88
LightClientUpdatesByRangeKey,
99
NetworkId,
10+
NetworkIdByChain,
1011
type PortalNetwork,
1112
computeLightClientKeyFromPeriod,
1213
getBeaconContentKey,
@@ -31,7 +32,7 @@ export class beacon {
3132
* @param rpcManager RPC client to which the module binds
3233
*/
3334
constructor(client: PortalNetwork, logger: Debugger) {
34-
this._beacon = client.networks.get(NetworkId.BeaconChainNetwork) as BeaconNetwork
35+
this._beacon = client.networks.get(NetworkIdByChain[client.chainId].BeaconChainNetwork) as BeaconNetwork
3536
this.logger = logger.extend('beacon')
3637

3738
this.methods = middleware(this.methods.bind(this), 0, [])

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { PrefixedHexString } from '@ethereumjs/util'
22
import { bigIntToHex, hexToBytes, intToHex, toBytes } from '@ethereumjs/util'
3-
import { GET_LOGS_BLOCK_RANGE_LIMIT, NetworkId, getLogs } from 'portalnetwork'
3+
import { GET_LOGS_BLOCK_RANGE_LIMIT, NetworkId, NetworkIdByChain, getLogs } from 'portalnetwork'
44

55
import { INTERNAL_ERROR, INVALID_PARAMS } from '../error-code.js'
66
import { jsonRpcLog } from '../types.js'
@@ -26,7 +26,7 @@ export class eth {
2626
*/
2727
constructor(client: PortalNetwork, logger: Debugger) {
2828
this._client = client
29-
this._history = client.networks.get(NetworkId.HistoryNetwork) as HistoryNetwork
29+
this._history = client.networks.get(NetworkIdByChain[client.chainId].HistoryNetwork) as HistoryNetwork
3030
this.logger = logger.extend('eth')
3131

3232
this.getBlockByNumber = middleware(

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
ContentLookup,
1212
FoundContent,
1313
NetworkId,
14+
NetworkIdByChain,
1415
NodeLookup,
1516
decodeExtensionPayloadToJson,
1617
encodeExtensionPayloadFromJson,
@@ -98,9 +99,9 @@ export class portal {
9899

99100
constructor(client: PortalNetwork, logger: Debugger) {
100101
this._client = client
101-
this._history = this._client.networks.get(NetworkId.HistoryNetwork) as HistoryNetwork
102-
this._beacon = this._client.networks.get(NetworkId.BeaconChainNetwork) as BeaconNetwork
103-
this._state = this._client.networks.get(NetworkId.StateNetwork) as StateNetwork
102+
this._history = this._client.networks.get(NetworkIdByChain[client.chainId].HistoryNetwork) as HistoryNetwork
103+
this._beacon = this._client.networks.get(NetworkIdByChain[client.chainId].BeaconChainNetwork) as BeaconNetwork
104+
this._state = this._client.networks.get(NetworkIdByChain[client.chainId].StateNetwork) as StateNetwork
104105
this.logger = logger
105106
this.methods = middleware(this.methods.bind(this), 0, [])
106107

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type PrefixedHexString, bytesToHex, hexToBytes } from '@ethereumjs/util'
2-
import { HistoryNetworkContentType, NetworkId } from 'portalnetwork'
2+
import { HistoryNetworkContentType, type NetworkId, NetworkIdByChain } from 'portalnetwork'
33

44
import { INTERNAL_ERROR } from '../error-code.js'
55
import { middleware, validators } from '../validators.js'
@@ -29,9 +29,9 @@ export class ultralight {
2929

3030
constructor(client: PortalNetwork, logger: Debugger) {
3131
this._client = client
32-
this._history = this._client.network()[NetworkId.HistoryNetwork] as HistoryNetwork | undefined
33-
this._state = this._client.network()[NetworkId.StateNetwork] as StateNetwork | undefined
34-
this._beacon = this._client.network()[NetworkId.BeaconChainNetwork] as BeaconNetwork | undefined
32+
this._history = this._client.network()[NetworkIdByChain[client.chainId].HistoryNetwork] as HistoryNetwork | undefined
33+
this._state = this._client.network()[NetworkIdByChain[client.chainId].StateNetwork] as StateNetwork | undefined
34+
this._beacon = this._client.network()[NetworkIdByChain[client.chainId].BeaconChainNetwork] as BeaconNetwork | undefined
3535
this.logger = logger
3636
this.methods = middleware(this.methods.bind(this), 0, [])
3737
this.addContentToDB = middleware(this.addContentToDB.bind(this), 2, [
@@ -106,15 +106,15 @@ export class ultralight {
106106
const [networkId, radius] = params
107107
try {
108108
switch (networkId) {
109-
case NetworkId.HistoryNetwork: {
109+
case NetworkIdByChain[this._client.chainId].HistoryNetwork: {
110110
await this._history!.setRadius(2n ** BigInt(Number.parseInt(radius)) - 1n)
111111
return '0x' + this._history!.nodeRadius.toString(16)
112112
}
113-
case NetworkId.StateNetwork: {
113+
case NetworkIdByChain[this._client.chainId].StateNetwork: {
114114
await this._state!.setRadius(2n ** BigInt(Number.parseInt(radius)) - 1n)
115115
return '0x' + this._state!.nodeRadius.toString(16)
116116
}
117-
case NetworkId.BeaconChainNetwork: {
117+
case NetworkIdByChain[this._client.chainId].BeaconChainNetwork: {
118118
await this._beacon!.setRadius(2n ** BigInt(Number.parseInt(radius)) - 1n)
119119
return '0x' + this._beacon!.nodeRadius.toString(16)
120120
}

0 commit comments

Comments
 (0)