Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/cli/scripts/beaconBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
LightClientOptimisticUpdateKey,
LightClientUpdatesByRange,
LightClientUpdatesByRangeKey,
getBeaconContentKey,
encodeBeaconContentKey,
} from 'portalnetwork'

const { Client } = jayson
Expand All @@ -34,7 +34,7 @@ const main = async () => {
console.log(
`Retrieved latest optimistic update for slot ${BigInt(optimisticUpdate.signatureSlot)}`,
)
const optimisticUpdateKey = getBeaconContentKey(
const optimisticUpdateKey = encodeBeaconContentKey(
BeaconNetworkContentType.LightClientOptimisticUpdate,
LightClientOptimisticUpdateKey.serialize({
signatureSlot: BigInt(optimisticUpdate.signatureSlot),
Expand All @@ -58,7 +58,7 @@ const main = async () => {
)
}
const serializedRange = LightClientUpdatesByRange.serialize(range)
const rangeKey = getBeaconContentKey(
const rangeKey = encodeBeaconContentKey(
BeaconNetworkContentType.LightClientUpdatesByRange,
LightClientUpdatesByRangeKey.serialize({ startPeriod: BigInt(oldPeriod), count: 3n }),
)
Expand All @@ -77,7 +77,7 @@ const main = async () => {
`Retrieved bootstrap for finalized checkpoint ${bootstrapRoot} from starting sync period ${oldPeriod}...`,
)
const res = await ultralight.request('portal_beaconStore', [
getBeaconContentKey(
encodeBeaconContentKey(
BeaconNetworkContentType.LightClientBootstrap,
LightClientBootstrapKey.serialize({ blockHash: hexToBytes(bootstrapRoot) }),
),
Expand Down Expand Up @@ -114,14 +114,14 @@ const main = async () => {
console.log('Caught interrupt signal. Shutting down...')
process.exit(0)
})

while (true) {
await new Promise((resolve) => setTimeout(() => resolve(undefined), 13000))
const optimisticUpdate = ssz.capella.LightClientOptimisticUpdate.fromJson(
(await (await fetch(beaconNode + 'eth/v1/beacon/light_client/optimistic_update')).json())
.data,
)
const optimisticUpdateKey = getBeaconContentKey(
const optimisticUpdateKey = encodeBeaconContentKey(
BeaconNetworkContentType.LightClientOptimisticUpdate,
LightClientOptimisticUpdateKey.serialize({
signatureSlot: BigInt(optimisticUpdate.signatureSlot),
Expand All @@ -143,7 +143,7 @@ const main = async () => {
const finalityUpdate = ssz.capella.LightClientFinalityUpdate.fromJson(
(await (await fetch(beaconNode + 'eth/v1/beacon/light_client/finality_update')).json()).data,
)
const finalityUpdateKey = getBeaconContentKey(
const finalityUpdateKey = encodeBeaconContentKey(
BeaconNetworkContentType.LightClientFinalityUpdate,
LightClientFinalityUpdateKey.serialize({
finalitySlot: BigInt(finalityUpdate.finalizedHeader.beacon.slot),
Expand Down
23 changes: 11 additions & 12 deletions packages/cli/scripts/bootstrapFinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
LightClientOptimisticUpdateKey,
LightClientUpdatesByRange,
LightClientUpdatesByRangeKey,
getBeaconContentKey,
encodeBeaconContentKey,
} from 'portalnetwork'

import type { ForkLightClient } from '@lodestar/params'
Expand All @@ -36,7 +36,7 @@ const main = async () => {

console.log('Retrieving bootstrap and updates from Beacon node...')
const optimisticUpdate = (await api.lightclient.getOptimisticUpdate()).response!
const optimisticUpdateKey = getBeaconContentKey(
const optimisticUpdateKey = encodeBeaconContentKey(
BeaconNetworkContentType.LightClientOptimisticUpdate,
LightClientOptimisticUpdateKey.serialize({
signatureSlot: BigInt(optimisticUpdate.data.attestedHeader.beacon.slot),
Expand All @@ -53,14 +53,14 @@ const main = async () => {
beaconConfig.forkName2ForkDigest(update.version as ForkLightClient),
(
ssz.allForksLightClient[
update.version as LightClientForkName
update.version as LightClientForkName
] as allForks.AllForksLightClientSSZTypes
).LightClientUpdate.serialize(update.data),
),
)
}
const serializedRange = LightClientUpdatesByRange.serialize(range)
const rangeKey = getBeaconContentKey(
const rangeKey = encodeBeaconContentKey(
BeaconNetworkContentType.LightClientUpdatesByRange,
LightClientUpdatesByRangeKey.serialize({ startPeriod: BigInt(oldPeriod), count: 4n }),
)
Expand All @@ -72,7 +72,7 @@ const main = async () => {
)
const bootstrap = (await api.lightclient.getBootstrap(bootstrapRoot)).response!
await ultralights[Math.floor(Math.random() * 10)].request('portal_beaconStore', [
getBeaconContentKey(
encodeBeaconContentKey(
BeaconNetworkContentType.LightClientBootstrap,
LightClientBootstrapKey.serialize({ blockHash: hexToBytes(bootstrapRoot) }),
),
Expand All @@ -81,15 +81,14 @@ const main = async () => {
beaconConfig.forkName2ForkDigest(bootstrap.version),
(
ssz.allForksLightClient[
bootstrap.version as LightClientForkName
bootstrap.version as LightClientForkName
] as allForks.AllForksLightClientSSZTypes
).LightClientBootstrap.serialize(bootstrap.data),
),
),
])
console.log(
`Retrieved bootstrap for finalized checkpoint ${bootstrapRoot} from sync period ${
oldPeriod + x
`Retrieved bootstrap for finalized checkpoint ${bootstrapRoot} from sync period ${oldPeriod + x
} and seeding to network...`,
)
}
Expand Down Expand Up @@ -119,7 +118,7 @@ const main = async () => {
beaconConfig.forkName2ForkDigest(optimisticUpdate.version),
(
ssz.allForksLightClient[
optimisticUpdate.version as LightClientForkName
optimisticUpdate.version as LightClientForkName
] as allForks.AllForksLightClientSSZTypes
).LightClientOptimisticUpdate.serialize(optimisticUpdate.data),
),
Expand All @@ -134,12 +133,12 @@ const main = async () => {
console.log('Caught interrupt signal. Shuttind down...')
process.exit(0)
})

while (true) {
await new Promise((resolve) => setTimeout(() => resolve(undefined), 13000))
const optimisticUpdate = (await api.lightclient.getOptimisticUpdate()).response!
console.log('new update')
const optimisticUpdateKey = getBeaconContentKey(
const optimisticUpdateKey = encodeBeaconContentKey(
BeaconNetworkContentType.LightClientOptimisticUpdate,
LightClientOptimisticUpdateKey.serialize({
signatureSlot: BigInt(optimisticUpdate.data.attestedHeader.beacon.slot),
Expand All @@ -152,7 +151,7 @@ const main = async () => {
beaconConfig.forkName2ForkDigest(optimisticUpdate.version),
(
ssz.allForksLightClient[
optimisticUpdate.version as LightClientForkName
optimisticUpdate.version as LightClientForkName
] as allForks.AllForksLightClientSSZTypes
).LightClientOptimisticUpdate.serialize(optimisticUpdate.data),
),
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/scripts/postCapellaBlockBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import jayson from 'jayson/promise/index.js'
import {
BeaconNetworkContentType,
BlockHeaderWithProof,
getBeaconContentKey,
encodeBeaconContentKey,
getContentKey,
HistoricalSummariesBlockProof,
HistoricalSummariesKey,
Expand Down Expand Up @@ -54,7 +54,7 @@ const main = async () => {
console.log(
`Retrieved latest optimistic update for slot ${BigInt(optimisticUpdate.signatureSlot)}`,
)
const optimisticUpdateKey = getBeaconContentKey(
const optimisticUpdateKey = encodeBeaconContentKey(
BeaconNetworkContentType.LightClientOptimisticUpdate,
LightClientOptimisticUpdateKey.serialize({
signatureSlot: BigInt(optimisticUpdate.signatureSlot),
Expand Down Expand Up @@ -85,7 +85,7 @@ const main = async () => {
// Push the bootstrap into the Portal Network
let res = await ultralight.request('portal_beaconStore', [
bytesToHex(
getBeaconContentKey(
encodeBeaconContentKey(
BeaconNetworkContentType.LightClientBootstrap,
LightClientBootstrapKey.serialize({ blockHash: hexToBytes(bootstrapRoot) }),
),
Expand All @@ -110,7 +110,7 @@ const main = async () => {
console.log('Retrieving latest historical summaries...')
const res2 = await fetch(
beaconNode +
`/eth/v1/lodestar/historical_summaries/${finalityUpdate.finalizedHeader.beacon.slot}`,
`/eth/v1/lodestar/historical_summaries/${finalityUpdate.finalizedHeader.beacon.slot}`,
)
const res2Json = await res2.json()

Expand All @@ -125,7 +125,7 @@ const main = async () => {

res = await ultralight.request('portal_beaconStore', [
bytesToHex(
getBeaconContentKey(
encodeBeaconContentKey(
BeaconNetworkContentType.HistoricalSummaries,
HistoricalSummariesKey.serialize({ epoch: BigInt(finalityEpoch) }),
),
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/rpc/modules/beacon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
NetworkIdByChain,
type PortalNetwork,
computeLightClientKeyFromPeriod,
getBeaconContentKey,
encodeBeaconContentKey,
} from 'portalnetwork'

import { INTERNAL_ERROR } from '../error-code.js'
Expand Down Expand Up @@ -89,7 +89,7 @@ export class beacon {

async getLightClientUpdate(params: [string]) {
const period = Number(BigInt(params[0]))
const rangeKey = getBeaconContentKey(
const rangeKey = encodeBeaconContentKey(
BeaconNetworkContentType.LightClientUpdate,
hexToBytes(computeLightClientKeyFromPeriod(period) as PrefixedHexString),
)
Expand All @@ -101,7 +101,7 @@ export class beacon {
}
const lookup = new ContentLookup(
this._beacon,
getBeaconContentKey(
encodeBeaconContentKey(
BeaconNetworkContentType.LightClientUpdatesByRange,
LightClientUpdatesByRangeKey.serialize({ startPeriod: BigInt(params[0]), count: 1n }),
),
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/test/rpc/beacon/getLightClientUpdate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ssz } from '@lodestar/types'
import {
BeaconNetworkContentType,
computeLightClientKeyFromPeriod,
getBeaconContentKey,
encodeBeaconContentKey,
} from 'portalnetwork'
import { assert, afterAll, beforeAll, describe, it } from 'vitest'

Expand All @@ -14,7 +14,7 @@ describe(`${method} tests`, () => {
let ultralight, rpc

beforeAll(async () => {
;({ ultralight, rpc } = await startRpc({ networks: ['beacon'], rpcPort: 8548, port: 9003 }))
; ({ ultralight, rpc } = await startRpc({ networks: ['beacon'], rpcPort: 8548, port: 9003 }))
})

afterAll(() => {
Expand All @@ -23,7 +23,7 @@ describe(`${method} tests`, () => {

it('should retrieve a light client update', async () => {
const rangeJson = require('./range.json')[0]
const rangeKey = getBeaconContentKey(
const rangeKey = encodeBeaconContentKey(
BeaconNetworkContentType.LightClientUpdate,
hexToBytes(
computeLightClientKeyFromPeriod(
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/rpc/portal/beaconLocalContent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { bytesToHex } from '@ethereumjs/util'
import {
BeaconNetworkContentType,
LightClientOptimisticUpdateKey,
getBeaconContentKey,
encodeBeaconContentKey,
} from 'portalnetwork'
import { assert, afterAll, beforeAll, describe, it } from 'vitest'

Expand All @@ -24,7 +24,7 @@ describe(`${method} tests`, () => {
it('should not find any local content', async () => {
const key = LightClientOptimisticUpdateKey.serialize({ signatureSlot: 7807053n })
const res = await rp.request(method, [
bytesToHex(getBeaconContentKey(BeaconNetworkContentType.LightClientOptimisticUpdate, key)),
bytesToHex(encodeBeaconContentKey(BeaconNetworkContentType.LightClientOptimisticUpdate, key)),
])
console.log(res)
assert.equal(res.error.code, -32009)
Expand Down
Loading