Skip to content

Commit

Permalink
Move ui to user network terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Nov 9, 2023
1 parent 4d2cc20 commit ff7fd22
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/Components/Client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/src/server/procedures.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
ENR,
ContentLookup,
HistoryProtocol,
HistoryNetwork,
PortalNetwork,
ProtocolId,
NetworkId,
fromHexString,
toHexString,
} from 'portalnetwork'
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/server/rpc/trpcTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions packages/ui/src/server/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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')
Expand All @@ -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',
Expand Down Expand Up @@ -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),
})
}
Expand Down
20 changes: 10 additions & 10 deletions packages/ui/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}`)
}
}

Expand Down
10 changes: 5 additions & 5 deletions packages/ui/src/utils/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit ff7fd22

Please sign in to comment.