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
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/package--ethereumjs-era.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: 'Package: @ethereumjs/era'
about: Create issue for @ethereumjs/era package
title: ''
labels: 'package: era'
assignees: ''
---
3 changes: 2 additions & 1 deletion config/cspell-md.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@
"Unsnappy",
"unsnappy",
"ethportal",
"bytevector"
"bytevector",
"eraSync"
]
}
3 changes: 2 additions & 1 deletion config/cspell-ts.json
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@
"unsnappy",
"ethportal",
"bytevector",
"blobschedule"
"blobschedule",
"eraSync"
]
}
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import { EthereumClient } from '../src/client.js'
import { DataDirectory } from '../src/config.js'
import { LevelDB } from '../src/execution/level.js'
import { eraSync } from '../src/sync/erasync.js'

Check warning on line 14 in packages/client/bin/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/cli.ts#L14

Added line #L14 was not covered by tests
import { type ClientOpts } from '../src/types.js'
import { generateVKTStateRoot } from '../src/util/vkt.js'

import { helpRPC, startRPCServers } from './startRPC.js'
Expand All @@ -19,7 +21,6 @@
import type { Config } from '../src/config.js'
import type { Logger } from '../src/logging.js'
import type { FullEthereumService } from '../src/service/index.js'
import type { ClientOpts } from '../src/types.js'
import type { RPCArgs } from './startRPC.js'
import type { Block, BlockBytes } from '@ethereumjs/block'
import type { ConsensusDict } from '@ethereumjs/blockchain'
Expand Down Expand Up @@ -219,7 +220,9 @@
...dbs,
})
await client.open()

if (args.loadBlocksFromEra1 !== undefined) {
await eraSync(client, config, { loadBlocksFromEra1: args.loadBlocksFromEra1 })
}

Check warning on line 225 in packages/client/bin/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/cli.ts#L223-L225

Added lines #L223 - L225 were not covered by tests
if (args.loadBlocksFromRlp !== undefined) {
// Specifically for Hive simulator, preload blocks provided in RLP format
const blocks: Block[] = []
Expand Down
5 changes: 5 additions & 0 deletions packages/client/bin/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@
string: true,
array: true,
})
.option('loadBlocksFromEra1', {
describe: 'path to a directory of era1 files',
string: true,
optional: true,
})

Check warning on line 429 in packages/client/bin/utils.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/utils.ts#L425-L429

Added lines #L425 - L429 were not covered by tests
.option('pruneEngineCache', {
describe:
'Enable/Disable pruning engine block cache (disable for testing against hive etc)',
Expand Down
1 change: 1 addition & 0 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@ethereumjs/devp2p": "7.0.0-alpha.1",
"@ethereumjs/ethash": "4.0.0-alpha.1",
"@ethereumjs/evm": "4.0.0-alpha.1",
"@ethereumjs/era": "1.0.0-alpha.1",
"@ethereumjs/genesis": "0.3.0-alpha.1",
"@ethereumjs/mpt": "7.0.0-alpha.1",
"@ethereumjs/rlp": "6.0.0-alpha.1",
Expand Down
36 changes: 36 additions & 0 deletions packages/client/src/sync/erasync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { blockFromTuple, parseBlockTuple, readBinaryFile, readERA1 } from '@ethereumjs/era'
import { readdirSync } from 'fs'

import { DBKey } from '../util/metaDBManager.js'

import type { Config, EthereumClient } from '../index.js'
// import type { Block } from '@ethereumjs/block'

export async function eraSync(
client: EthereumClient,
config: Config,
args: { loadBlocksFromEra1: string },
) {
await client.chain.open()
const service = client.service
await service.execution.open()
const eraDir = readdirSync(args.loadBlocksFromEra1)
.filter((file) => file.endsWith('.era1'))
.sort()
for (const file of eraDir) {
config.logger.info(`Loading era1 file ${file}`)
const era1File = readBinaryFile(args.loadBlocksFromEra1 + '/' + file)
const blockTuples = await readERA1(era1File)
for await (const tuple of blockTuples) {
const { header, body, receipts } = await parseBlockTuple(tuple)
const block = blockFromTuple({ header, body })
await client.chain.blockchain.putBlock(block)
if (config.saveReceipts && service.execution.receiptsManager) {
await service.execution.receiptsManager?.put(DBKey.Receipts, block.hash(), receipts)
void service.execution.receiptsManager['updateIndex'](0, 0, block)
}
}
await client.chain.update(false)
await service.execution.run()
}
}

Check warning on line 36 in packages/client/src/sync/erasync.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/src/sync/erasync.ts#L9-L36

Added lines #L9 - L36 were not covered by tests
1 change: 1 addition & 0 deletions packages/client/src/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// need this weird re-export for vitest to be able to mock reverseblockfetcher in test/sync/beaconsync.spec.ts
export * from '../service/skeleton.js'
export * from './beaconsync.js'
export * from './erasync.js'
export * from './fullsync.js'
export * from './snapsync.js'
export * from './sync.js'
1 change: 1 addition & 0 deletions packages/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export interface ClientOpts {
vmProfileBlocks?: boolean
vmProfileTxs?: boolean
loadBlocksFromRlp?: string[]
loadBlocksFromEra1?: string
pruneEngineCache?: boolean
savePreimages?: boolean
verkleGenesisStateRoot?: Uint8Array
Expand Down
1 change: 1 addition & 0 deletions packages/client/tsconfig.prod.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
{ "path": "../blockchain/tsconfig.prod.esm.json" },
{ "path": "../common/tsconfig.prod.esm.json" },
{ "path": "../devp2p/tsconfig.prod.esm.json" },
{ "path": "../era/tsconfig.prod.esm.json" },
{ "path": "../rlp/tsconfig.prod.esm.json" },
{ "path": "../mpt/tsconfig.prod.esm.json" },
{ "path": "../tx/tsconfig.prod.esm.json" },
Expand Down
Loading