Skip to content

Commit

Permalink
Merge branch 'master' into cspell
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Aug 17, 2024
2 parents 5167780 + 0aa7445 commit 6a9c38a
Show file tree
Hide file tree
Showing 92 changed files with 582 additions and 676 deletions.
4 changes: 2 additions & 2 deletions packages/block/examples/4844.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createBlock } from '@ethereumjs/block'
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
import { create4844BlobTx } from '@ethereumjs/tx'
import { createBlob4844Tx } from '@ethereumjs/tx'
import { createAddressFromPrivateKey } from '@ethereumjs/util'
import { randomBytes } from 'crypto'
import { loadKZG } from 'kzg-wasm'
Expand All @@ -15,7 +15,7 @@ const main = async () => {
kzg,
},
})
const blobTx = create4844BlobTx(
const blobTx = createBlob4844Tx(
{ blobsData: ['myFirstBlob'], to: createAddressFromPrivateKey(randomBytes(32)) },
{ common },
)
Expand Down
16 changes: 6 additions & 10 deletions packages/block/src/block/block.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ConsensusType } from '@ethereumjs/common'
import { RLP } from '@ethereumjs/rlp'
import { Trie } from '@ethereumjs/trie'
import { BlobEIP4844Transaction, Capability } from '@ethereumjs/tx'
import { Blob4844Tx, Capability } from '@ethereumjs/tx'
import {
BIGINT_0,
CLRequestType,
Expand Down Expand Up @@ -34,11 +34,7 @@ import {
/* eslint-enable */
import type { BlockBytes, BlockOptions, ExecutionPayload, JsonBlock } from '../types.js'
import type { Common } from '@ethereumjs/common'
import type {
FeeMarketEIP1559Transaction,
LegacyTransaction,
TypedTransaction,
} from '@ethereumjs/tx'
import type { FeeMarket1559Tx, LegacyTx, TypedTransaction } from '@ethereumjs/tx'
import type {
CLRequest,
ConsolidationRequest,
Expand Down Expand Up @@ -284,12 +280,12 @@ export class Block {
const errs = tx.getValidationErrors()
if (this.common.isActivatedEIP(1559)) {
if (tx.supports(Capability.EIP1559FeeMarket)) {
tx = tx as FeeMarketEIP1559Transaction
tx = tx as FeeMarket1559Tx
if (tx.maxFeePerGas < this.header.baseFeePerGas!) {
errs.push('tx unable to pay base fee (EIP-1559 tx)')
}
} else {
tx = tx as LegacyTransaction
tx = tx as LegacyTx
if (tx.gasPrice < this.header.baseFeePerGas!) {
errs.push('tx unable to pay base fee (non EIP-1559 tx)')
}
Expand All @@ -298,7 +294,7 @@ export class Block {
if (this.common.isActivatedEIP(4844)) {
const blobGasLimit = this.common.param('maxblobGasPerBlock')
const blobGasPerBlob = this.common.param('blobGasPerBlob')
if (tx instanceof BlobEIP4844Transaction) {
if (tx instanceof Blob4844Tx) {
blobGasUsed += BigInt(tx.numBlobs()) * blobGasPerBlob
if (blobGasUsed > blobGasLimit) {
errs.push(
Expand Down Expand Up @@ -414,7 +410,7 @@ export class Block {
let blobGasPrice

for (const tx of this.transactions) {
if (tx instanceof BlobEIP4844Transaction) {
if (tx instanceof Blob4844Tx) {
blobGasPrice = blobGasPrice ?? this.header.getBlobGasPrice()
if (tx.maxFeePerBlobGas < blobGasPrice) {
throw new Error(
Expand Down
4 changes: 2 additions & 2 deletions packages/block/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RLP } from '@ethereumjs/rlp'
import { Trie } from '@ethereumjs/trie'
import { BlobEIP4844Transaction } from '@ethereumjs/tx'
import { Blob4844Tx } from '@ethereumjs/tx'
import { BIGINT_0, BIGINT_1, TypeOutput, isHexString, toType } from '@ethereumjs/util'

import type { BlockHeaderBytes, HeaderData } from './types.js'
Expand Down Expand Up @@ -96,7 +96,7 @@ export function getDifficulty(headerData: HeaderData): bigint | null {
export const getNumBlobs = (transactions: TypedTransaction[]) => {
let numBlobs = 0
for (const tx of transactions) {
if (tx instanceof BlobEIP4844Transaction) {
if (tx instanceof Blob4844Tx) {
numBlobs += tx.blobVersionedHashes.length
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/block/test/eip1559block.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
import { create1559FeeMarketTx } from '@ethereumjs/tx'
import { createFeeMarket1559Tx } from '@ethereumjs/tx'
import { hexToBytes } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

Expand Down Expand Up @@ -408,7 +408,7 @@ describe('EIP1559 tests', () => {
})

it('Header -> validateTransactions() -> tx', async () => {
const transaction = create1559FeeMarketTx(
const transaction = createFeeMarket1559Tx(
{
maxFeePerGas: BigInt(0),
maxPriorityFeePerGas: BigInt(0),
Expand Down
6 changes: 3 additions & 3 deletions packages/block/test/eip4844block.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Common, Hardfork, Mainnet, createCommonFromGethGenesis } from '@ethereumjs/common'
import { create4844BlobTx } from '@ethereumjs/tx'
import { createBlob4844Tx } from '@ethereumjs/tx'
import {
blobsToCommitments,
commitmentsToVersionedHashes,
Expand Down Expand Up @@ -176,7 +176,7 @@ describe('transaction validation tests', () => {
const commitments = blobsToCommitments(kzg, blobs)
const blobVersionedHashes = commitmentsToVersionedHashes(commitments)

const tx1 = create4844BlobTx(
const tx1 = createBlob4844Tx(
{
blobVersionedHashes,
blobs,
Expand All @@ -187,7 +187,7 @@ describe('transaction validation tests', () => {
},
{ common },
).sign(randomBytes(32))
const tx2 = create4844BlobTx(
const tx2 = createBlob4844Tx(
{
blobVersionedHashes,
blobs,
Expand Down
6 changes: 2 additions & 4 deletions packages/block/test/from-rpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import * as blockDataWithWithdrawals from './testdata/testdata-from-rpc-with-wit
import * as blockData from './testdata/testdata-from-rpc.json'

import type { JsonRpcBlock } from '../src/index.js'
import type { LegacyTransaction } from '@ethereumjs/tx'
import type { LegacyTx } from '@ethereumjs/tx'
import type { PrefixedHexString } from '@ethereumjs/util'

describe('[fromRPC]: block #2924874', () => {
Expand Down Expand Up @@ -69,9 +69,7 @@ describe('[fromRPC]:', () => {
{ common },
)
assert.equal(
(
createBlockFromTransactionGasPriceAsInteger.transactions[0] as LegacyTransaction
).gasPrice.toString(),
(createBlockFromTransactionGasPriceAsInteger.transactions[0] as LegacyTx).gasPrice.toString(),
gasPriceAsIntegerString,
)
})
Expand Down
10 changes: 5 additions & 5 deletions packages/client/src/miner/pendingBlock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Hardfork } from '@ethereumjs/common'
import { BlobEIP4844Transaction } from '@ethereumjs/tx'
import { Blob4844Tx } from '@ethereumjs/tx'
import {
BIGINT_1,
BIGINT_2,
Expand Down Expand Up @@ -322,7 +322,7 @@ export class PendingBlock {
switch (addTxResult) {
case AddTxResult.Success:
// Push the tx in blobTxs only after successful addTransaction
if (tx instanceof BlobEIP4844Transaction) blobTxs.push(tx)
if (tx instanceof Blob4844Tx) blobTxs.push(tx)
break

case AddTxResult.BlockFull:
Expand Down Expand Up @@ -382,10 +382,10 @@ export class PendingBlock {
/**
* An internal helper for storing the blob bundle associated with each transaction in an EIP4844 world
* @param payloadId the payload Id of the pending block
* @param txs an array of {@BlobEIP4844Transaction } transactions
* @param txs an array of {@Blob4844Tx } transactions
* @param blockHash the blockhash of the pending block (computed from the header data provided)
*/
private constructBlobsBundle = (payloadId: string, txs: BlobEIP4844Transaction[]) => {
private constructBlobsBundle = (payloadId: string, txs: Blob4844Tx[]) => {
let blobs: Uint8Array[] = []
let commitments: Uint8Array[] = []
let proofs: Uint8Array[] = []
Expand All @@ -397,7 +397,7 @@ export class PendingBlock {
}

for (let tx of txs) {
tx = tx as BlobEIP4844Transaction
tx = tx as Blob4844Tx
if (tx.blobs !== undefined && tx.blobs.length > 0) {
blobs = blobs.concat(tx.blobs)
commitments = commitments.concat(tx.kzgCommitments!)
Expand Down
24 changes: 10 additions & 14 deletions packages/client/src/net/protocol/ethprotocol.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { createBlockFromBytesArray, createBlockHeaderFromBytesArray } from '@ethereumjs/block'
import { RLP } from '@ethereumjs/rlp'
import {
BlobEIP4844Transaction,
create4844BlobTxFromSerializedNetworkWrapper,
Blob4844Tx,
createBlob4844TxFromSerializedNetworkWrapper,
createTxFromBlockBodyData,
createTxFromSerializedData,
isAccessListEIP2930Tx,
isBlobEIP4844Tx,
isEOACodeEIP7702Tx,
isFeeMarketEIP1559Tx,
isAccessList2930Tx,
isBlob4844Tx,
isEOACode7702Tx,
isFeeMarket1559Tx,
isLegacyTx,
} from '@ethereumjs/tx'
import {
Expand Down Expand Up @@ -117,7 +117,7 @@ export class EthProtocol extends Protocol {
const serializedTxs = []
for (const tx of txs) {
// Don't automatically broadcast blob transactions - they should only be announced using NewPooledTransactionHashes
if (tx instanceof BlobEIP4844Transaction) continue
if (tx instanceof Blob4844Tx) continue
serializedTxs.push(tx.serialize())
}
return serializedTxs
Expand Down Expand Up @@ -253,13 +253,9 @@ export class EthProtocol extends Protocol {
const serializedTxs = []
for (const tx of txs) {
// serialize txs as per type
if (isBlobEIP4844Tx(tx)) {
if (isBlob4844Tx(tx)) {
serializedTxs.push(tx.serializeNetworkWrapper())
} else if (
isFeeMarketEIP1559Tx(tx) ||
isAccessListEIP2930Tx(tx) ||
isEOACodeEIP7702Tx(tx)
) {
} else if (isFeeMarket1559Tx(tx) || isAccessList2930Tx(tx) || isEOACode7702Tx(tx)) {
serializedTxs.push(tx.serialize())
} else if (isLegacyTx(tx)) {
serializedTxs.push(tx.raw())
Expand Down Expand Up @@ -288,7 +284,7 @@ export class EthProtocol extends Protocol {
txs.map((txData) => {
// Blob transactions are deserialized with network wrapper
if (txData[0] === 3) {
return create4844BlobTxFromSerializedNetworkWrapper(txData, { common })
return createBlob4844TxFromSerializedNetworkWrapper(txData, { common })
} else {
return createTxFromBlockBodyData(txData, { common })
}
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/rpc/modules/engine/util/newPayload.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createBlockFromExecutionPayload } from '@ethereumjs/block'
import { BlobEIP4844Transaction } from '@ethereumjs/tx'
import { Blob4844Tx } from '@ethereumjs/tx'
import { equalsBytes, hexToBytes } from '@ethereumjs/util'

import { short } from '../../../../util/index.js'
Expand Down Expand Up @@ -59,7 +59,7 @@ export const validate4844BlobVersionedHashes = (
// Collect versioned hashes in the flat array `txVersionedHashes` to match with received
const txVersionedHashes = []
for (const tx of headBlock.transactions) {
if (tx instanceof BlobEIP4844Transaction) {
if (tx instanceof Blob4844Tx) {
for (const vHash of tx.blobVersionedHashes) {
txVersionedHashes.push(vHash)
}
Expand Down
34 changes: 15 additions & 19 deletions packages/client/src/rpc/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createBlock } from '@ethereumjs/block'
import { Hardfork } from '@ethereumjs/common'
import {
Capability,
create4844BlobTxFromSerializedNetworkWrapper,
createBlob4844TxFromSerializedNetworkWrapper,
createTxFromSerializedData,
createTxFromTxData,
} from '@ethereumjs/tx'
Expand Down Expand Up @@ -47,11 +47,7 @@ import type { RpcTx } from '../types.js'
import type { Block, JsonRpcBlock } from '@ethereumjs/block'
import type { Log } from '@ethereumjs/evm'
import type { Proof } from '@ethereumjs/statemanager'
import type {
FeeMarketEIP1559Transaction,
LegacyTransaction,
TypedTransaction,
} from '@ethereumjs/tx'
import type { FeeMarket1559Tx, LegacyTx, TypedTransaction } from '@ethereumjs/tx'
import type { Address, PrefixedHexString } from '@ethereumjs/util'

const EMPTY_SLOT = `0x${'00'.repeat(32)}`
Expand Down Expand Up @@ -965,13 +961,13 @@ export class Eth {
const { blobGasPrice, blobGasUsed } = runBlockResult.receipts[i] as EIP4844BlobTxReceipt
const effectiveGasPrice =
tx.supports(Capability.EIP1559FeeMarket) === true
? (tx as FeeMarketEIP1559Transaction).maxPriorityFeePerGas <
(tx as FeeMarketEIP1559Transaction).maxFeePerGas - block.header.baseFeePerGas!
? (tx as FeeMarketEIP1559Transaction).maxPriorityFeePerGas
: (tx as FeeMarketEIP1559Transaction).maxFeePerGas -
? (tx as FeeMarket1559Tx).maxPriorityFeePerGas <
(tx as FeeMarket1559Tx).maxFeePerGas - block.header.baseFeePerGas!
? (tx as FeeMarket1559Tx).maxPriorityFeePerGas
: (tx as FeeMarket1559Tx).maxFeePerGas -
block.header.baseFeePerGas! +
block.header.baseFeePerGas!
: (tx as LegacyTransaction).gasPrice
: (tx as LegacyTx).gasPrice

return jsonRpcReceipt(
r,
Expand Down Expand Up @@ -1016,13 +1012,13 @@ export class Eth {
const parentBlock = await this._chain.getBlock(block.header.parentHash)
const tx = block.transactions[txIndex]
const effectiveGasPrice = tx.supports(Capability.EIP1559FeeMarket)
? (tx as FeeMarketEIP1559Transaction).maxPriorityFeePerGas <
(tx as FeeMarketEIP1559Transaction).maxFeePerGas - block.header.baseFeePerGas!
? (tx as FeeMarketEIP1559Transaction).maxPriorityFeePerGas
: (tx as FeeMarketEIP1559Transaction).maxFeePerGas -
? (tx as FeeMarket1559Tx).maxPriorityFeePerGas <
(tx as FeeMarket1559Tx).maxFeePerGas - block.header.baseFeePerGas!
? (tx as FeeMarket1559Tx).maxPriorityFeePerGas
: (tx as FeeMarket1559Tx).maxFeePerGas -
block.header.baseFeePerGas! +
block.header.baseFeePerGas!
: (tx as LegacyTransaction).gasPrice
: (tx as LegacyTx).gasPrice

const vmCopy = await this._vm!.shallowCopy()
vmCopy.common.setHardfork(tx.common.hardfork())
Expand Down Expand Up @@ -1172,7 +1168,7 @@ export class Eth {
const txBuf = hexToBytes(serializedTx)
if (txBuf[0] === 0x03) {
// Blob Transactions sent over RPC are expected to be in Network Wrapper format
tx = create4844BlobTxFromSerializedNetworkWrapper(txBuf, { common })
tx = createBlob4844TxFromSerializedNetworkWrapper(txBuf, { common })

const blobGasLimit = tx.common.param('maxblobGasPerBlock')
const blobGasPerBlob = tx.common.param('blobGasPerBlob')
Expand Down Expand Up @@ -1341,7 +1337,7 @@ export class Eth {
let priorityFee = BIGINT_0
const block = await this._chain.getBlock(latest.number)
for (const tx of block.transactions) {
const maxPriorityFeePerGas = (tx as FeeMarketEIP1559Transaction).maxPriorityFeePerGas
const maxPriorityFeePerGas = (tx as FeeMarket1559Tx).maxPriorityFeePerGas
priorityFee += maxPriorityFeePerGas
}

Expand All @@ -1360,7 +1356,7 @@ export class Eth {
}

for (const tx of block.transactions) {
const txGasPrice = (tx as LegacyTransaction).gasPrice
const txGasPrice = (tx as LegacyTx).gasPrice
gasPrice += txGasPrice
txCount++
}
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/service/fullethereumservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { TxPool } from './txpool.js'
import type { Peer } from '../net/peer/peer.js'
import type { Protocol } from '../net/protocol/index.js'
import type { Block } from '@ethereumjs/block'
import type { BlobEIP4844Transaction } from '@ethereumjs/tx'
import type { Blob4844Tx } from '@ethereumjs/tx'

interface FullEthereumServiceOptions extends ServiceOptions {
/** Serve LES requests (default: false) */
Expand Down Expand Up @@ -175,7 +175,7 @@ export class FullEthereumService extends Service {
if (rawTx.type !== TransactionType.BlobEIP4844) {
txs[1].push(rawTx.serialize().byteLength)
} else {
txs[1].push((rawTx as BlobEIP4844Transaction).serializeNetworkWrapper().byteLength)
txs[1].push((rawTx as Blob4844Tx).serializeNetworkWrapper().byteLength)
}
txs[2].push(hexToBytes(`0x${tx.hash}`))
}
Expand Down
Loading

0 comments on commit 6a9c38a

Please sign in to comment.