Skip to content

Commit

Permalink
Merge branch 'master' into beacon-light-client-scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Jul 27, 2023
2 parents ba06e35 + 698520c commit ba9fbaa
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 141 deletions.
4 changes: 2 additions & 2 deletions DEVNET.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Notes: The nodes started by the script have a JSON-RPC server enabled. The por
```sh
npx ts-node scripts/seeder.ts --rpcPort=8546 --numBlocks=[number of blocks to seed into network] --sourceFile="[path/to/json/file/with/block/data.json]" --numNodes=[number of nodes in devnet (same as above)]
```
This will load the first `numBlocks` blocks from your `sourceFile` to the the node with the `rpcPort` specified.
This will load the first `numBlocks` blocks from your `sourceFile` to the node with the `rpcPort` specified.

3. If all goes well, you should see the nodes start to connect with one another

Expand Down Expand Up @@ -48,4 +48,4 @@ scrape_configs:

static_configs:
- targets: ["localhost:5051"]
```
```
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This monorepo comprises a suite of tools **currently in development** to allow dapps, wallet providers, and really any Javascript based Ethereum application to connect into the Portal Network once development is complete and the Portal Network is live.

## Prequisites
## Prerequisites

Node v16+, NPM v7+

Expand Down
2 changes: 1 addition & 1 deletion packages/browser-client/docs/mobile.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The nice part of this for our purposes is that the React web app is the same cod
## Debugging the mobile app

There are a couple of ways to debug Android apps but far and away the easiest is:
- Run `npx cap open android` from `[directory root]/packages/browser-client` and then select the "Run" tab on the very bottom left of the Android Studio UI and it wll show you all of the debug logs from the app.
- Run `npx cap open android` from `[directory root]/packages/browser-client` and then select the "Run" tab on the very bottom left of the Android Studio UI and it will show you all of the debug logs from the app.

## Local development notes

Expand Down
62 changes: 25 additions & 37 deletions packages/cli/scripts/seeder.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import jayson, { HttpClient } from 'jayson/promise/index.js'
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'
import {
fromHexString,
getContentKey,
ContentType,
ProtocolId,
} from 'portalnetwork'
import { fromHexString, getContentKey, ContentType, ProtocolId, toHexString } from 'portalnetwork'
import { createRequire } from 'module'
import { readFileSync } from 'fs'
import { Block } from '@ethereumjs/block'

const require = createRequire(import.meta.url)
const { Client } = jayson
Expand Down Expand Up @@ -73,8 +69,10 @@ const main = async () => {
const blockData = require(args.sourceFile)
const blocks = Object.entries(blockData)
const epoch = require('./testEpoch.json')
const epoch25 = readFileSync('./scripts/0x03f216a28afb2212269b634b9b44ff327a4a79f261640ff967f7e3283e3a184c70.portalcontent', {encoding: 'hex'})

const epoch25 = readFileSync(
'./scripts/0x03f216a28afb2212269b634b9b44ff327a4a79f261640ff967f7e3283e3a184c70.portalcontent',
{ encoding: 'hex' }
)

async function testRes(clients: HttpClient[], method: string, params: any[][]) {
for (const [i, client] of clients.entries()) {
Expand All @@ -85,10 +83,7 @@ const main = async () => {
}
console.log(`ok ${method} test`)
}
const epochKey = getContentKey(
ContentType.EpochAccumulator,
fromHexString(epoch.hash)
)
const epochKey = getContentKey(ContentType.EpochAccumulator, fromHexString(epoch.hash))
let res = await clientInfo.ultralight.client.request('ultralight_addContentToDB', [
epochKey,
epoch.serialized,
Expand All @@ -97,7 +92,7 @@ const main = async () => {
throw new Error(`ultralight_addContentToDB error`)
}
res = await clientInfo.ultralight.client.request('ultralight_addContentToDB', [
"0x03f216a28afb2212269b634b9b44ff327a4a79f261640ff967f7e3283e3a184c70",
'0x03f216a28afb2212269b634b9b44ff327a4a79f261640ff967f7e3283e3a184c70',
'0x' + epoch25,
])
if (res.error) {
Expand Down Expand Up @@ -149,46 +144,39 @@ const main = async () => {
// portal_historyRoutingTableInfo
await testRes(clients, 'portal_historyRoutingTableInfo', [[], [], [], []])
// portal_historyLookupEnr
await testRes([clients[0]], 'portal_historyLookupEnr', [[clientInfo.peer1.enr]])
await testRes([clients[0]], 'portal_historyLookupEnr', [['0x' + clientInfo.peer1.nodeId]])
// portal_historyPing
await testRes(clients.slice(1), 'portal_historyPing', [
[clientInfo.ultralight.enr, "0x00"],
[clientInfo.ultralight.enr, "0x00"],
[clientInfo.ultralight.enr, "0x00"],
[clientInfo.ultralight.enr, '0x00'],
[clientInfo.ultralight.enr, '0x00'],
[clientInfo.ultralight.enr, '0x00'],
])
// portal_historyFindNodes
await testRes([clients[1]], 'portal_historyFindNodes', [
[clientInfo.ultralight.nodeId.slice(2), [255]],
])
await testRes([clients[1]], 'portal_historyFindNodes', [[clientInfo.ultralight.enr, [255]]])
// portal_historyFindContent
await testRes([clients[1]], 'portal_historyFindContent', [
[clientInfo.ultralight.nodeId.slice(2), blocks[1][0]],
[clientInfo.ultralight.enr, blocks[1][0]],
])
// portal_historyLocalContent
await testRes([clients[0]], 'portal_historyLocalContent', [[epochKey]])
// portal_historyOffer
await testRes([clients[0]], 'portal_historyOffer', [
[
clientInfo.peer1.nodeId.slice(2),
for (const block of blocks.slice(0, 1)) {
await testRes([clients[0]], 'portal_historyOffer', [
[
getContentKey(
ContentType.BlockHeader,
fromHexString(blocks[3][0])
),
getContentKey(
ContentType.BlockBody,
fromHexString(blocks[3][0])
clientInfo.peer1.enr,
getContentKey(ContentType.BlockHeader, fromHexString(block[0])),
toHexString(
Block.fromRLPSerializedBlock(Buffer.from((block[1] as any).rlp.slice(2), 'hex'), {
hardforkByBlockNumber: true,
}).header.serialize()
),
],
],
])
])
}
// eth_getBlockByHash
await testRes([clients[2]], 'eth_getBlockByHash', [[blocks[2][0], false]])
// eth_getBlockByNumber
await clientInfo.peer3.client.request('ultralight_addContentToDB', [
epochKey,
epoch.serialized,
])
await clientInfo.peer3.client.request('ultralight_addContentToDB', [epochKey, epoch.serialized])
await testRes([clients[3]], 'eth_getBlockByNumber', [['0x3e8', false]])
await testRes([clients[2]], 'eth_getBlockByNumber', [['0x3e8', false]])
}
Expand Down
Loading

0 comments on commit ba9fbaa

Please sign in to comment.