Skip to content

Commit

Permalink
Add support for multiple sources of rlp blocks (#3442)
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed May 31, 2024
1 parent 1566a30 commit e8297a5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
45 changes: 24 additions & 21 deletions packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ const args: ClientOpts = yargs
.option('loadBlocksFromRlp', {
describe: 'path to a file of RLP encoded blocks',
string: true,
array: true,
})
.option('pruneEngineCache', {
describe: 'Enable/Disable pruning engine block cache (disable for testing against hive etc)',
Expand Down Expand Up @@ -652,27 +653,29 @@ async function startClient(

if (args.loadBlocksFromRlp !== undefined) {
// Specifically for Hive simulator, preload blocks provided in RLP format
const blockRlp = readFileSync(args.loadBlocksFromRlp)
const blocks: Block[] = []
let buf = RLP.decode(blockRlp, true)
while (buf.data?.length > 0 || buf.remainder?.length > 0) {
try {
const block = Block.fromValuesArray(buf.data as BlockBytes, {
common: config.chainCommon,
setHardfork: true,
})
blocks.push(block)
buf = RLP.decode(buf.remainder, true)
config.logger.info(
`Preloading block hash=0x${short(bytesToHex(block.header.hash()))} number=${
block.header.number
}`
)
} catch (err: any) {
config.logger.info(
`Encountered error while while preloading chain data error=${err.message}`
)
break
for (const rlpBlock of args.loadBlocksFromRlp) {
const blockRlp = readFileSync(rlpBlock)
let buf = RLP.decode(blockRlp, true)
while (buf.data?.length > 0 || buf.remainder?.length > 0) {
try {
const block = Block.fromValuesArray(buf.data as BlockBytes, {
common: config.chainCommon,
setHardfork: true,
})
blocks.push(block)
buf = RLP.decode(buf.remainder, true)
config.logger.info(
`Preloading block hash=0x${short(bytesToHex(block.header.hash()))} number=${
block.header.number
}`
)
} catch (err: any) {
config.logger.info(
`Encountered error while while preloading chain data error=${err.message}`
)
break
}
}
}

Expand All @@ -681,7 +684,7 @@ async function startClient(
await client.chain.open()
}

await client.chain.putBlocks(blocks)
await client.chain.putBlocks(blocks, true)
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export interface ClientOpts {
isSingleNode?: boolean
vmProfileBlocks?: boolean
vmProfileTxs?: boolean
loadBlocksFromRlp?: string
loadBlocksFromRlp?: string[]
pruneEngineCache?: boolean
savePreimages?: boolean
verkleGenesisStateRoot?: Uint8Array
Expand Down

0 comments on commit e8297a5

Please sign in to comment.