Skip to content

Commit

Permalink
add engine_getPayloadBodiesByHashV1
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Jan 25, 2023
1 parent c53e0c7 commit 27ea7f4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/client/lib/rpc/error-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export const INVALID_REQUEST = -32600
export const METHOD_NOT_FOUND = -32601
export const INVALID_PARAMS = -32602
export const INTERNAL_ERROR = -32603
export const TOO_LARGE_REQUEST = -38004
56 changes: 54 additions & 2 deletions packages/client/lib/rpc/modules/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { Hardfork } from '@ethereumjs/common'
import { TransactionFactory } from '@ethereumjs/tx'
import { Withdrawal, bigIntToHex, bufferToHex, toBuffer, zeros } from '@ethereumjs/util'

import { RPCManager } from '..'
import { PendingBlock } from '../../miner'
import { short } from '../../util'
import { INTERNAL_ERROR, INVALID_PARAMS } from '../error-code'
import { INTERNAL_ERROR, INVALID_PARAMS, TOO_LARGE_REQUEST } from '../error-code'
import { CLConnectionManager, middleware as cmMiddleware } from '../util/CLConnectionManager'
import { middleware, validators } from '../validation'

Expand Down Expand Up @@ -103,6 +102,12 @@ type BlobsBundleV1 = {
kzgs: Bytes48[]
blobs: Blob[]
}

type ExecutionPayloadBodyV1 = {
transactions: string[]
withdrawals: WithdrawalV1[] | null
}

const EngineError = {
UnknownPayload: {
code: -32001,
Expand Down Expand Up @@ -447,6 +452,13 @@ export class Engine {
this.getCapabilities = cmMiddleware(middleware(this.getCapabilities.bind(this), 0, []), () =>
this.connectionManager.updateStatus()
)

this.getPayloadBodiesByHashV1 = cmMiddleware(
middleware(this.getPayloadBodiesByHashV1.bind(this), 1, [
validators.array(validators.bytes32),
]),
() => this.connectionManager.updateStatus()
)
}

/**
Expand Down Expand Up @@ -1001,4 +1013,44 @@ export class Engine {
)
return engineMethods.map((el) => 'engine_' + el)
}

/**
*
* @param params a list of block hashes as hex prefixed strings
* @returns an array of ExecutionPayloadBodyV1 objects or null if a given execution payload isn't stored locally
*/
private getPayloadBodiesByHashV1 = async (
params: [[Bytes32]]
): Promise<(ExecutionPayloadBodyV1 | null)[]> => {
if (params[0].length > 32) {
throw {
code: TOO_LARGE_REQUEST,
message: 'More than 32 execution payload bodies requested',
}
}
const hashes = params[0].map((hash) => toBuffer(hash))
const blocks: (ExecutionPayloadBodyV1 | null)[] = []
for (const hash of hashes) {
try {
const block = await this.chain.getBlock(hash)
const transactions: string[] = []
for (const txn of block.transactions) {
transactions.push('0x' + txn.serialize())
}
let withdrawals
if (block._common.gteHardfork(Hardfork.Shanghai)) {
withdrawals = []
for (const withdrawal of block.withdrawals!) {
withdrawals.push(withdrawal.toJSON() as WithdrawalV1)
}
} else {
withdrawals = null
}
blocks.push({ transactions, withdrawals })
} catch {
blocks.push(null)
}
}
return blocks
}
}

1 comment on commit 27ea7f4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 27ea7f4 Previous: 5283b88 Ratio
Block 9422907 9420 ops/sec (±6.65%) 18849 ops/sec (±1.49%) 2.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.