Skip to content

Commit

Permalink
Merge branch 'master' into evm-error-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Jan 14, 2025
2 parents b4458d7 + 99cfdd6 commit 293f4cc
Show file tree
Hide file tree
Showing 81 changed files with 1,554 additions and 912 deletions.
8 changes: 5 additions & 3 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions packages/block/src/block/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export class Block {
}
}
if (this.common.isActivatedEIP(4844)) {
const blobGasLimit = this.common.param('maxblobGasPerBlock')
const blobGasLimit = this.common.param('maxBlobGasPerBlock')
const blobGasPerBlob = this.common.param('blobGasPerBlob')
if (tx instanceof Blob4844Tx) {
blobGasUsed += BigInt(tx.numBlobs()) * blobGasPerBlob
Expand Down Expand Up @@ -354,7 +354,7 @@ export class Block {
*/
validateBlobTransactions(parentHeader: BlockHeader) {
if (this.common.isActivatedEIP(4844)) {
const blobGasLimit = this.common.param('maxblobGasPerBlock')
const blobGasLimit = this.common.param('maxBlobGasPerBlock')
const blobGasPerBlob = this.common.param('blobGasPerBlob')
let blobGasUsed = BIGINT_0

Expand Down
5 changes: 4 additions & 1 deletion packages/block/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ export function genRequestsRoot(

let flatRequests = new Uint8Array()
for (const req of requests) {
flatRequests = concatBytes(flatRequests, sha256Function(req.bytes))
if (req.bytes.length > 1) {
// Only append requests if they have content
flatRequests = concatBytes(flatRequests, sha256Function(req.bytes))
}
}

return sha256Function(flatRequests)
Expand Down
13 changes: 11 additions & 2 deletions packages/block/src/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const paramsBlock: ParamsDict = {
gasLimitBoundDivisor: 1024, // The bound divisor of the gas limit, used in update calculations
targetBlobGasPerBlock: 0, // Base value needed here since called pre-4844 in BlockHeader.calcNextExcessBlobGas()
blobGasPerBlob: 0,
maxblobGasPerBlock: 0,
maxBlobGasPerBlock: 0,
// format
maxExtraDataSize: 32, // Maximum size extra data may be after Genesis
// pow
Expand Down Expand Up @@ -72,7 +72,7 @@ export const paramsBlock: ParamsDict = {
// gasConfig
targetBlobGasPerBlock: 393216, // The target blob gas consumed per block
blobGasPerBlob: 131072, // The base fee for blob gas per blob
maxblobGasPerBlock: 786432, // The max blob gas allowable per block
maxBlobGasPerBlock: 786432, // The max blob gas allowable per block
blobGasPriceUpdateFraction: 3338477, // The denominator used in the exponential when calculating a blob gas price
// gasPrices
simplePerBlobGas: 12000, // The basic gas fee for each blob
Expand All @@ -85,4 +85,13 @@ export const paramsBlock: ParamsDict = {
// pow
difficultyBombDelay: 11400000, // the amount of blocks to delay the difficulty bomb with
},
/**
. * Blob throughput increase
. */
7691: {
// gasConfig
targetBlobGasPerBlock: 786432, // The target blob gas consumed per block
maxBlobGasPerBlock: 1179648, // The max blob gas allowable per block
blobGasPriceUpdateFraction: 5007716, // The denominator used in the exponential when calculating a blob gas price
},
}
4 changes: 2 additions & 2 deletions packages/client/src/miner/pendingBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class PendingBlock {
// Get if and how many blobs are allowed in the tx
let allowedBlobs
if (vm.common.isActivatedEIP(4844)) {
const blobGasLimit = vm.common.param('maxblobGasPerBlock')
const blobGasLimit = vm.common.param('maxBlobGasPerBlock')
const blobGasPerBlob = vm.common.param('blobGasPerBlob')
allowedBlobs = Number(blobGasLimit / blobGasPerBlob)
} else {
Expand Down Expand Up @@ -270,7 +270,7 @@ export class PendingBlock {
let allowedBlobs
if (vm.common.isActivatedEIP(4844)) {
const bundle = this.blobsBundles.get(payloadId) ?? { blobs: [], commitments: [], proofs: [] }
const blobGasLimit = vm.common.param('maxblobGasPerBlock')
const blobGasLimit = vm.common.param('maxBlobGasPerBlock')
const blobGasPerBlob = vm.common.param('blobGasPerBlob')
allowedBlobs = Number(blobGasLimit / blobGasPerBlob) - bundle.blobs.length
} else {
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/rpc/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BIGINT_0, bigIntToHex, bytesToHex, intToHex } from '@ethereumjs/util'
import { INTERNAL_ERROR, INVALID_BLOCK, INVALID_PARAMS } from './error-code.js'

import type { Chain } from '../blockchain/index.js'
import type { RPCMethod } from './types.js'
import type { Block } from '@ethereumjs/block'
import type { JSONRPCTx, TypedTransaction } from '@ethereumjs/tx'

Expand All @@ -13,7 +14,7 @@ type RPCError = {
data?: string
}

export function callWithStackTrace(handler: Function, debug: boolean) {
export function callWithStackTrace(handler: Function, debug: boolean): RPCMethod {
return async (...args: any) => {
try {
const res = await handler(...args)
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/rpc/modules/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export class Admin {
this._client = client
this._rpcDebug = rpcDebug

this.nodeInfo = middleware(callWithStackTrace(this.nodeInfo.bind(this), this._rpcDebug), 0, [])
this.peers = middleware(callWithStackTrace(this.peers.bind(this), this._rpcDebug), 0, [])
this.nodeInfo = callWithStackTrace(this.nodeInfo.bind(this), this._rpcDebug)
this.peers = callWithStackTrace(this.peers.bind(this), this._rpcDebug)
this.addPeer = middleware(callWithStackTrace(this.addPeer.bind(this), this._rpcDebug), 1, [
[
validators.object({
Expand Down
29 changes: 29 additions & 0 deletions packages/client/src/rpc/modules/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ export class Debug {
1,
[[validators.hex]],
)
this.setHead = middleware(callWithStackTrace(this.setHead.bind(this), this._rpcDebug), 1, [
[validators.blockOption],
])
this.verbosity = middleware(callWithStackTrace(this.verbosity.bind(this), this._rpcDebug), 1, [
[validators.unsignedInteger],
])
Expand Down Expand Up @@ -457,4 +460,30 @@ export class Debug {
this.client.config.logger.configure({ level: logLevels[level] })
return `level: ${this.client.config.logger.level}`
}

/**
* Sets the current head of the local chain by block number. Note, this is a
* destructive action and may severely damage your chain. Use with extreme
* caution.
* @param blockOpt Block number or tag to set as head of chain
*/
async setHead(params: [string]) {
const [blockOpt] = params
if (blockOpt === 'pending') {
throw {
code: INVALID_PARAMS,
message: `"pending" is not supported`,
}
}

const block = await getBlockByOption(blockOpt, this.chain)
try {
await this.service.skeleton?.setHead(block, true)
await this.service.execution.setHead([block])
} catch (e) {
throw {
code: INTERNAL_ERROR,
}
}
}
}
13 changes: 12 additions & 1 deletion packages/client/src/rpc/modules/engine/util/getPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,20 @@ export const blockToExecutionPayload = (
// ethereumjs does not provide any transaction censoring detection (yet) to suggest
// overriding builder/mev-boost blocks
const shouldOverrideBuilder = false

let executionRequests = undefined
if (requests !== undefined) {
executionRequests = []
for (const request of requests) {
if (request.bytes.length > 1) {
executionRequests.push(bytesToHex(request.bytes))
}
}
}

return {
executionPayload,
executionRequests: requests?.map((req) => bytesToHex(req.data)),
executionRequests,
blockValue: bigIntToHex(value),
blobsBundle,
shouldOverrideBuilder,
Expand Down
49 changes: 27 additions & 22 deletions packages/client/src/rpc/modules/engine/util/newPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,35 @@ export const validateAndGen7685RequestsHash = (
common: Common,
executionRequests: PrefixedHexString[],
): PrefixedHexString => {
let validationError: string | null = null

const requests: CLRequest<CLRequestType>[] = []
let requestIndex = 0
if (common.isActivatedEIP(6110)) {
requests.push(new CLRequest(CLRequestType.Deposit, hexToBytes(executionRequests[requestIndex])))
requestIndex++
}
if (common.isActivatedEIP(7002)) {
requests.push(
new CLRequest(CLRequestType.Withdrawal, hexToBytes(executionRequests[requestIndex])),
)
requestIndex++
}
if (common.isActivatedEIP(7251)) {
requests.push(
new CLRequest(CLRequestType.Consolidation, hexToBytes(executionRequests[requestIndex])),
)
requestIndex++
}

if (requestIndex !== executionRequests.length) {
validationError = `Invalid executionRequests=${executionRequests.length} expected=${requestIndex}`
throw validationError
for (const request of executionRequests) {
const bytes = hexToBytes(request)
if (bytes.length === 0) {
throw new Error('Got a request without a request-identifier')
}
switch (bytes[0]) {
case CLRequestType.Deposit:
if (!common.isActivatedEIP(6110)) {
throw new Error(`Deposit requests are not active`)
}
requests.push(new CLRequest(CLRequestType.Deposit, bytes.slice(1)))
break
case CLRequestType.Withdrawal:
if (!common.isActivatedEIP(7002)) {
throw new Error(`Withdrawal requests are not active`)
}
requests.push(new CLRequest(CLRequestType.Withdrawal, bytes.slice(1)))
break
case CLRequestType.Consolidation:
if (!common.isActivatedEIP(7251)) {
throw new Error(`Consolidation requests are not active`)
}
requests.push(new CLRequest(CLRequestType.Consolidation, bytes.slice(1)))
break
default:
throw new Error(`Unknown request identifier: got ${bytes[0]}`)
}
}

const sha256Function = common.customCrypto.sha256 ?? sha256
Expand Down
Loading

0 comments on commit 293f4cc

Please sign in to comment.