Skip to content

Commit

Permalink
fix types and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Feb 28, 2025
1 parent fb9a054 commit 7a61983
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
5 changes: 0 additions & 5 deletions packages/portalnetwork/src/networks/beacon/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,3 @@ export type HistoricalSummaries = Array<{
blockSummaryRoot: Uint8Array
stateSummaryRoot: Uint8Array
}>

export type EphemeralHeaderKeyValues = {
blockHash: Uint8Array
ancestorCount: number
}
5 changes: 5 additions & 0 deletions packages/portalnetwork/src/networks/history/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ export class HistoryNetwork extends BaseNetwork {
beacon.lightClient?.status === RunStatusCode.uninitialized ||
beacon.lightClient?.status === RunStatusCode.stopped
) {
// TODO: Decide whether to keep this or not. It's not technically correct according to the spec
// since you can track the HEAD of the chan however you want.
const errorMessage = 'Cannot verify ephemeral headers when beacon network is not running'
this.logger.extend('FINDCONTENT')(errorMessage)
throw new Error(errorMessage)
Expand Down Expand Up @@ -450,6 +452,9 @@ export class HistoryNetwork extends BaseNetwork {
}
}
}
this.logger.extend('FOUNDCONTENT')(
`found ${headersList.length} ancestor headers for ${bytesToHex(contentKey.keyOpt.blockHash)}`,
)
value = EphemeralHeaderPayload.serialize(headersList)
}
} else {
Expand Down
5 changes: 5 additions & 0 deletions packages/portalnetwork/src/networks/history/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,8 @@ export const EphemeralHeaderPayload = new ListCompositeType(
BlockHeader,
MAX_EPHEMERAL_HEADERS_PAYLOAD,
)

export type EphemeralHeaderKeyValues = {
blockHash: Uint8Array
ancestorCount: number
}
2 changes: 1 addition & 1 deletion packages/portalnetwork/src/networks/history/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import type { WithdrawalBytes } from '@ethereumjs/util'
import type { ForkConfig } from '@lodestar/config'
import type { HistoryNetwork } from './history.js'
import type { BlockBodyContent, Witnesses } from './types.js'
import type { EphemeralHeaderKeyValues } from '../beacon/types.js'
import type { EphemeralHeaderKeyValues } from '../history/types.js'

export const BlockHeaderByNumberKey = (blockNumber: bigint) => {
return Uint8Array.from([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BlockHeader, JsonRpcBlock } from '@ethereumjs/block'
import { Block } from '@ethereumjs/block'
import { hexToBytes } from '@ethereumjs/util'
import { bytesToHex, hexToBytes } from '@ethereumjs/util'
import { assert, beforeAll, describe, it } from 'vitest'
import {
EphemeralHeaderPayload,
Expand Down Expand Up @@ -35,7 +35,10 @@ describe('ephemeral header handling', () => {
await network!.store(contentKey, headerPayload)
const storedHeaderPayload = await network?.get(getEphemeralHeaderDbKey(headers[0].hash()))
assert.deepEqual(hexToBytes(storedHeaderPayload!), headers[0].serialize())
assert.deepEqual(network!.ephemeralHeaderIndex.getByKey(headers[1].number), headers[1].hash())
assert.deepEqual(
network!.ephemeralHeaderIndex.getByKey(headers[1].number),
bytesToHex(headers[1].hash()),
)
})
it('should produce the correct HISTORY_RADIUS ping payload', async () => {
const node = await PortalNetwork.create({})
Expand Down

0 comments on commit 7a61983

Please sign in to comment.