From ff7fd2223ede97cfe92d0a579239a144b2742dd1 Mon Sep 17 00:00:00 2001 From: acolytec3 <17355484+acolytec3@users.noreply.github.com> Date: Thu, 9 Nov 2023 12:05:48 -0500 Subject: [PATCH] Move ui to user network terminology --- .../networks/history/historyNetwork.spec.ts | 2 +- packages/ui/src/Components/Client.tsx | 2 +- packages/ui/src/server/procedures.ts | 6 +++--- packages/ui/src/server/rpc/trpcTypes.ts | 2 +- packages/ui/src/server/server.ts | 6 +++--- packages/ui/src/server/subscriptions.ts | 12 +++++------ packages/ui/src/util.ts | 20 +++++++++---------- packages/ui/src/utils/router.ts | 10 +++++----- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/portalnetwork/test/networks/history/historyNetwork.spec.ts b/packages/portalnetwork/test/networks/history/historyNetwork.spec.ts index 7f788a1ed..a09668b31 100644 --- a/packages/portalnetwork/test/networks/history/historyNetwork.spec.ts +++ b/packages/portalnetwork/test/networks/history/historyNetwork.spec.ts @@ -157,7 +157,7 @@ describe('store -- Block Bodies and Receipts', async () => { const epochHash = '0x987cb6206e5bae4b68ce0eeb6c05ae090d02b7331e47d1705a2a515ac88475aa' await network.store(HistoryNetworkContentType.EpochAccumulator, epochHash, hexToBytes(epoch)) - const _epochHash = toHexString(epochRootByBlocknumber(207686n)) + const _epochHash = toHexString(epochRootByBlocknumber(207686n)!) it('Should store and retrieve a block body from DB', async () => { assert.equal(epochHash, _epochHash, 'Epoch hash matches expected value') }) diff --git a/packages/ui/src/Components/Client.tsx b/packages/ui/src/Components/Client.tsx index 20788c060..980ca2fb5 100644 --- a/packages/ui/src/Components/Client.tsx +++ b/packages/ui/src/Components/Client.tsx @@ -107,7 +107,7 @@ export default function Client(props: { name: string }) { }, }) trpc.onNodeAdded.useSubscription(undefined, { - onData({ nodeId, protocolId }) { + onData({ nodeId, networkId }) { console.info('node added: ', nodeId) }, onStarted() { diff --git a/packages/ui/src/server/procedures.ts b/packages/ui/src/server/procedures.ts index 007fbedd5..2bbac5882 100644 --- a/packages/ui/src/server/procedures.ts +++ b/packages/ui/src/server/procedures.ts @@ -1,9 +1,9 @@ import { ENR, ContentLookup, - HistoryProtocol, + HistoryNetwork, PortalNetwork, - ProtocolId, + NetworkId, fromHexString, toHexString, } from 'portalnetwork' @@ -54,7 +54,7 @@ export const bootnodes = bootnodeENRs.map((b) => { } }) export const websocketProcedures = (portal: PortalNetwork, publicProcedure: PublicProcudure) => { - const history = portal.protocols.get(ProtocolId.HistoryNetwork) as HistoryProtocol + const history = portal.networks.get(NetworkId.HistoryNetwork) as HistoryNetwork const start = publicProcedure .meta({ diff --git a/packages/ui/src/server/rpc/trpcTypes.ts b/packages/ui/src/server/rpc/trpcTypes.ts index 4452598f4..47f813669 100644 --- a/packages/ui/src/server/rpc/trpcTypes.ts +++ b/packages/ui/src/server/rpc/trpcTypes.ts @@ -33,7 +33,7 @@ export const z_udpPort = z_uint(16) export const z_isTcp = z.boolean() export const z_distance = z.number() export const z_RequestId = z_bytes(8) -export const z_ProtocolId = z.number().gte(0).lte(4) +export const z_NetworkId = z.number().gte(0).lte(4) export const z_Discv5Payload = z_hexString() export const z_ContentKey = z_hexString() export const z_Content = z.string() diff --git a/packages/ui/src/server/server.ts b/packages/ui/src/server/server.ts index d3e7948e7..3efacc30f 100644 --- a/packages/ui/src/server/server.ts +++ b/packages/ui/src/server/server.ts @@ -6,7 +6,7 @@ import { ENR, SignableENR } from '@chainsafe/discv5' import { createSecp256k1PeerId } from '@libp2p/peer-id-factory' import { multiaddr } from '@multiformats/multiaddr' import { execSync } from 'child_process' -import { HistoryProtocol, PortalNetwork, ProtocolId } from 'portalnetwork' +import { HistoryNetwork, PortalNetwork, NetworkId } from 'portalnetwork' import ws from 'ws' @@ -49,13 +49,13 @@ const main = async () => { const portal = await PortalNetwork.create({ config: config, radius: 2n ** 256n - 1n, - supportedProtocols: [ProtocolId.HistoryNetwork], + supportedNetworks: [NetworkId.HistoryNetwork], eventLog: true, }) portal.discv5.enableLogs() portal.enableLog('*') - const history = portal.protocols.get(ProtocolId.HistoryNetwork) as HistoryProtocol + const history = portal.networks.get(NetworkId.HistoryNetwork) as HistoryNetwork const router = t.router // WSS Client Methods diff --git a/packages/ui/src/server/subscriptions.ts b/packages/ui/src/server/subscriptions.ts index a65651809..e3fd87650 100644 --- a/packages/ui/src/server/subscriptions.ts +++ b/packages/ui/src/server/subscriptions.ts @@ -6,12 +6,12 @@ import { initTRPC } from '@trpc/server' import { observable } from '@trpc/server/observable' import debug from 'debug' import { - HistoryProtocol, + HistoryNetwork, MessageCodes, PortalNetwork, PortalNetworkEventEmitter, PortalWireMessageType, - ProtocolId, + NetworkId, fromHexString, toHexString, } from 'portalnetwork' @@ -66,7 +66,7 @@ export type PublicProcudure = typeof pubProcedure export const subscriptions = async ( portal: PortalNetwork, - history: HistoryProtocol, + history: HistoryNetwork, publicProcedure: PublicProcudure, ) => { const log = debug('ui:subscription') @@ -82,7 +82,7 @@ export const subscriptions = async ( .subscription(() => { return observable((emit) => { const talkReq = (src: INodeAddress, sourceId: ENR | null, message: ITalkReqMessage) => { - if (toHexString(message.protocol) === ProtocolId.UTPNetwork) { + if (toHexString(message.protocol) === NetworkId.UTPNetwork) { emit.next({ nodeId: '0x' + src.nodeId, topic: 'UTP', @@ -176,10 +176,10 @@ export const subscriptions = async ( }) .subscription(() => { return observable((emit) => { - const utpEvent = (peerId: string, msg: Buffer, protocolId: ProtocolId) => { + const utpEvent = (peerId: string, msg: Buffer, networkId: NetworkId) => { emit.next({ peerId, - protocolId, + networkId, msg: toHexString(msg), }) } diff --git a/packages/ui/src/util.ts b/packages/ui/src/util.ts index d337fbf64..a0b4fd8d0 100644 --- a/packages/ui/src/util.ts +++ b/packages/ui/src/util.ts @@ -2,11 +2,11 @@ import { BlockHeader } from '@ethereumjs/block' import { RLP } from '@ethereumjs/rlp' import { TransactionFactory } from '@ethereumjs/tx' import { - BaseProtocol, + BaseNetwork, BlockBodyContentType, BlockHeaderWithProof, EpochAccumulator, - ProtocolId, + NetworkId, sszReceiptType, sszUnclesType, toHexString, @@ -49,19 +49,19 @@ export const isValidEnr = (enr: Enr) => { /** * Add a valid Ethereum Node Record (ENR) that is compliant with EIP-778 * https://eips.ethereum.org/EIPS/eip-778 as a bootnode to an instance of a Portal Network - * protocol - * @param protocolId the protocolId associated with an instance of a Portal Network protocol - * @param baseProtocol the methods of the protocolId instance of a Portal Network protocol + * network + * @param networkId the networkId associated with an instance of a Portal Network network + * @param baseNetwork the methods of the networkId instance of a Portal Network network * @param enr a base64 encoded string containing an Ethereum Node Record (ENR) * @throws {Error} */ -export const addBootNode = async (protocolId: ProtocolId, baseProtocol: BaseProtocol, enr: Enr) => { +export const addBootNode = async (networkId: NetworkId, baseNetwork: BaseNetwork, enr: Enr) => { try { - await baseProtocol!.addBootNode(enr) - baseProtocol!.logger(`Added bootnode ${enr} to ${protocolId}`) + await baseNetwork!.addBootNode(enr) + baseNetwork!.logger(`Added bootnode ${enr} to ${networkId}`) } catch (error: any) { - throw new Error(`Error adding bootnode ${enr} to protocol \ - ${protocolId}: ${error.message ?? error}`) + throw new Error(`Error adding bootnode ${enr} to network \ + ${networkId}: ${error.message ?? error}`) } } diff --git a/packages/ui/src/utils/router.ts b/packages/ui/src/utils/router.ts index 1914fb08c..9a4e8a72c 100644 --- a/packages/ui/src/utils/router.ts +++ b/packages/ui/src/utils/router.ts @@ -105,15 +105,15 @@ const onContentAdded = publicProcedure.subscription(({ input }) => { const onNodeAdded = publicProcedure.subscription(() => { const ee = new EventEmitter() return observable((emit) => { - const nodeAdded = (nodeId: string, protocolId: number) => { - console.log('nodeAdded', { nodeId, protocolId }) + const nodeAdded = (nodeId: string, networkId: number) => { + console.log('nodeAdded', { nodeId, networkId }) emit.next({ nodeId, - protocolId, + networkId, }) } - ee.on('NodeAdded', (nodeId: string, protocolId: number) => { - nodeAdded(nodeId, protocolId) + ee.on('NodeAdded', (nodeId: string, networkId: number) => { + nodeAdded(nodeId, networkId) }) return () => { ee.off('NodeAdded', () => {