Skip to content

Commit

Permalink
Block: rename createBlockFromValuesArray
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottyPoi committed Aug 14, 2024
1 parent af630f1 commit 0e62524
Show file tree
Hide file tree
Showing 19 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions packages/block/src/block/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
type createBlockFromJsonRpcProvider,
type createBlockFromRLPSerializedBlock,
type createBlockFromRPC,
type createBlockFromValuesArray,
type createBlockFromBytesArray,
} from '../index.js'
/* eslint-enable */
import type { BlockBytes, BlockOptions, ExecutionPayload, JsonBlock } from '../types.js'
Expand Down Expand Up @@ -57,7 +57,7 @@ import type {
* (separate from the Block class to allow for tree shaking):
*
* - {@link createBlock }
* - {@link createBlockFromValuesArray }
* - {@link createBlockFromBytesArray }
* - {@link createBlockFromRLPSerializedBlock }
* - {@link createBlockFromRPC }
* - {@link createBlockFromJsonRpcProvider }
Expand Down
4 changes: 2 additions & 2 deletions packages/block/src/block/constructors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function createBlock(blockData: BlockData = {}, opts?: BlockOptions) {
* @param values
* @param opts
*/
export function createBlockFromValuesArray(values: BlockBytes, opts?: BlockOptions) {
export function createBlockFromBytesArray(values: BlockBytes, opts?: BlockOptions) {
if (values.length > 5) {
throw new Error(`invalid More values=${values.length} than expected were received (at most 5)`)
}
Expand Down Expand Up @@ -279,7 +279,7 @@ export function createBlockFromRLPSerializedBlock(serialized: Uint8Array, opts?:
throw new Error('Invalid serialized block input. Must be array')
}

return createBlockFromValuesArray(values, opts)
return createBlockFromBytesArray(values, opts)
}

/**
Expand Down
14 changes: 7 additions & 7 deletions packages/block/test/block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
createBlock,
createBlockFromRLPSerializedBlock,
createBlockFromRPC,
createBlockFromValuesArray,
createBlockFromBytesArray,
paramsBlock,
} from '../src/index.js'

Expand Down Expand Up @@ -84,10 +84,10 @@ describe('[Block]: block functions', () => {

const valuesArray = <BlockBytes>[headerArray, [], []]

block = createBlockFromValuesArray(valuesArray, { common })
block = createBlockFromBytesArray(valuesArray, { common })
assert.ok(Object.isFrozen(block), 'block should be frozen by default')

block = createBlockFromValuesArray(valuesArray, { common, freeze: false })
block = createBlockFromBytesArray(valuesArray, { common, freeze: false })
assert.ok(
!Object.isFrozen(block),
'block should not be frozen when freeze deactivated in options',
Expand Down Expand Up @@ -356,7 +356,7 @@ describe('[Block]: block functions', () => {
)
assert.throws(
() => {
createBlockFromValuesArray([1, 2, 3, 4] as any)
createBlockFromBytesArray([1, 2, 3, 4] as any)
},
undefined,
undefined,
Expand All @@ -372,7 +372,7 @@ describe('[Block]: block functions', () => {
common,
},
)
const createBlockFromRaw = createBlockFromValuesArray(block.raw(), { common })
const createBlockFromRaw = createBlockFromBytesArray(block.raw(), { common })
assert.ok(equalsBytes(block.hash(), createBlockFromRaw.hash()))
})

Expand All @@ -397,7 +397,7 @@ describe('[Block]: block functions', () => {
const common = new Common({ chain: Mainnet, hardfork: Hardfork.Dao })
assert.throws(
function () {
createBlockFromValuesArray(blockData as BlockBytes, { common })
createBlockFromBytesArray(blockData as BlockBytes, { common })
},
/extraData should be 'dao-hard-fork/,
undefined,
Expand All @@ -408,7 +408,7 @@ describe('[Block]: block functions', () => {
blockData[0][12] = hexToBytes('0x64616f2d686172642d666f726b')

assert.doesNotThrow(function () {
createBlockFromValuesArray(blockData as BlockBytes, { common })
createBlockFromBytesArray(blockData as BlockBytes, { common })
}, 'should not throw on DAO HF block with correct extra data')
})

Expand Down
8 changes: 4 additions & 4 deletions packages/block/test/eip7685block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
Block,
createBlock,
createBlockFromRPC,
createBlockFromValuesArray,
createBlockFromBytesArray,
createBlockHeader,
} from '../src/index.js'

Expand Down Expand Up @@ -111,7 +111,7 @@ describe('7685 tests', () => {

describe('fromValuesArray tests', () => {
it('should construct a block with empty requests root', () => {
const block = createBlockFromValuesArray(
const block = createBlockFromBytesArray(
[createBlockHeader({}, { common }).raw(), [], [], [], []],
{
common,
Expand All @@ -127,7 +127,7 @@ describe('fromValuesArray tests', () => {
const requestsRoot = await genRequestsTrieRoot(requests)
const serializedRequests = [request1.serialize(), request2.serialize(), request3.serialize()]

const block = createBlockFromValuesArray(
const block = createBlockFromBytesArray(
[createBlockHeader({ requestsRoot }, { common }).raw(), [], [], [], serializedRequests],
{
common,
Expand All @@ -147,7 +147,7 @@ describe('fromRPC tests', () => {
const requestsRoot = await genRequestsTrieRoot(requests)
const serializedRequests = [request1.serialize(), request2.serialize(), request3.serialize()]

const block = createBlockFromValuesArray(
const block = createBlockFromBytesArray(
[createBlockHeader({ requestsRoot }, { common }).raw(), [], [], [], serializedRequests],
{
common,
Expand Down
4 changes: 2 additions & 2 deletions packages/blockchain/src/db/manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createBlockFromValuesArray, createBlockHeaderFromValuesArray } from '@ethereumjs/block'
import { createBlockFromBytesArray, createBlockHeaderFromValuesArray } from '@ethereumjs/block'
import { RLP } from '@ethereumjs/rlp'
import {
KECCAK256_RLP,
Expand Down Expand Up @@ -141,7 +141,7 @@ export class DBManager {

const blockData = [header.raw(), ...body] as BlockBytes
const opts: BlockOptions = { common: this.common, setHardfork: true }
return createBlockFromValuesArray(blockData, opts)
return createBlockFromBytesArray(blockData, opts)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import { createBlockFromValuesArray } from '@ethereumjs/block'
import { createBlockFromBytesArray } from '@ethereumjs/block'
import { CliqueConsensus, createBlockchain } from '@ethereumjs/blockchain'
import {
Chain,
Expand Down Expand Up @@ -685,7 +685,7 @@ async function startClient(
let buf = RLP.decode(blockRlp, true)
while (buf.data?.length > 0 || buf.remainder?.length > 0) {
try {
const block = createBlockFromValuesArray(buf.data as BlockBytes, {
const block = createBlockFromBytesArray(buf.data as BlockBytes, {
common: config.chainCommon,
setHardfork: true,
})
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/blockchain/chain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createBlockFromValuesArray, createBlockHeaderFromValuesArray } from '@ethereumjs/block'
import { createBlockFromBytesArray, createBlockHeaderFromValuesArray } from '@ethereumjs/block'
import { CliqueConsensus, createBlockchain } from '@ethereumjs/blockchain'
import { ConsensusAlgorithm, Hardfork } from '@ethereumjs/common'
import { BIGINT_0, equalsBytes } from '@ethereumjs/util'
Expand Down Expand Up @@ -418,7 +418,7 @@ export class Chain {
await this.blockchain.consensus?.setup({ blockchain: this.blockchain })
}

const block = createBlockFromValuesArray(b.raw(), {
const block = createBlockFromBytesArray(b.raw(), {
common: this.config.chainCommon,
setHardfork: true,
})
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/net/protocol/ethprotocol.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createBlockFromValuesArray, createBlockHeaderFromValuesArray } from '@ethereumjs/block'
import { createBlockFromBytesArray, createBlockHeaderFromValuesArray } from '@ethereumjs/block'
import { RLP } from '@ethereumjs/rlp'
import {
BlobEIP4844Transaction,
Expand Down Expand Up @@ -200,7 +200,7 @@ export class EthProtocol extends Protocol {
code: 0x07,
encode: ([block, td]: [Block, bigint]) => [block.raw(), bigIntToUnpaddedBytes(td)],
decode: ([block, td]: [BlockBytes, Uint8Array]) => [
createBlockFromValuesArray(block, {
createBlockFromBytesArray(block, {
common: this.config.chainCommon,
setHardfork: true,
}),
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/sync/fetcher/blockfetcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createBlockFromValuesArray } from '@ethereumjs/block'
import { createBlockFromBytesArray } from '@ethereumjs/block'
import { KECCAK256_RLP, KECCAK256_RLP_ARRAY, equalsBytes } from '@ethereumjs/util'

import { Event } from '../../types.js'
Expand Down Expand Up @@ -91,7 +91,7 @@ export class BlockFetcher extends BlockFetcherBase<Block[], Block> {
values.push(withdrawalsData)
}
// Supply the common from the corresponding block header already set on correct fork
const block = createBlockFromValuesArray(values, { common: headers[i].common })
const block = createBlockFromBytesArray(values, { common: headers[i].common })
// Only validate the data integrity
// Upon putting blocks into blockchain (for BlockFetcher), `validateData` is called again
// In ReverseBlockFetcher we do not need to validate the entire block, since CL
Expand Down
4 changes: 2 additions & 2 deletions packages/devp2p/examples/peer-communication-les.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createBlockFromValuesArray, createBlockHeaderFromValuesArray } from '@ethereumjs/block'
import { createBlockFromBytesArray, createBlockHeaderFromValuesArray } from '@ethereumjs/block'
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
import * as devp2p from '@ethereumjs/devp2p'
import { bytesToHex, bytesToInt, hexToBytes, intToBytes, randomBytes } from '@ethereumjs/util'
Expand Down Expand Up @@ -132,7 +132,7 @@ rlpx.events.on('peer:added', (peer) => {
const header2 = requests.bodies.shift()
const txs = payload[2][0][0]
const uncleHeaders = payload[2][0][1]
const block = createBlockFromValuesArray([header2.raw(), txs, uncleHeaders], { common })
const block = createBlockFromBytesArray([header2.raw(), txs, uncleHeaders], { common })
const isValid = await isValidBlock(block)
let isValidPayload = false
if (isValid) {
Expand Down
6 changes: 3 additions & 3 deletions packages/devp2p/examples/peer-communication.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlockHeader, createBlockFromValuesArray } from '@ethereumjs/block'
import { BlockHeader, createBlockFromBytesArray } from '@ethereumjs/block'
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
import * as devp2p from '@ethereumjs/devp2p'
import { RLP } from '@ethereumjs/rlp'
Expand Down Expand Up @@ -238,7 +238,7 @@ rlpx.events.on('peer:added', (peer) => {
const header = requests.bodies.shift()
const txs = payload[1][0][0]
const uncleHeaders = payload[1][0][1]
const block = createBlockFromValuesArray([header.raw(), txs, uncleHeaders], { common })
const block = createBlockFromBytesArray([header.raw(), txs, uncleHeaders], { common })
const isValid = await isValidBlock(block)
if (isValid) {
isValidPayload = true
Expand All @@ -257,7 +257,7 @@ rlpx.events.on('peer:added', (peer) => {
case devp2p.ETH.MESSAGE_CODES.NEW_BLOCK: {
if (!forkVerified) break

const newBlock = createBlockFromValuesArray(payload[0], { common })
const newBlock = createBlockFromBytesArray(payload[0], { common })
const isValidNewBlock = await isValidBlock(newBlock)
if (isValidNewBlock) onNewBlock(newBlock, peer)

Expand Down
4 changes: 2 additions & 2 deletions packages/ethash/test/block.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
createBlock,
createBlockFromRLPSerializedBlock,
createBlockFromValuesArray,
createBlockFromBytesArray,
} from '@ethereumjs/block'
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
import { RLP } from '@ethereumjs/rlp'
Expand Down Expand Up @@ -35,7 +35,7 @@ describe('Verify POW for valid and invalid blocks', () => {
// Put correct amount of extraData in block extraData field so block can be deserialized
const values = RLP.decode(Uint8Array.from(invalidRlp)) as BlockBytes
values[0][12] = new Uint8Array(32)
const invalidBlock = createBlockFromValuesArray(values, { common })
const invalidBlock = createBlockFromBytesArray(values, { common })
const invalidBlockResult = await e.verifyPOW(invalidBlock)
assert.ok(!invalidBlockResult, 'should be invalid')

Expand Down
2 changes: 1 addition & 1 deletion packages/tx/src/1559/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class FeeMarketEIP1559Transaction extends BaseTransaction<TransactionType
* accessList, signatureYParity, signatureR, signatureS]`
*
* Use {@link FeeMarketEIP1559Transaction.serialize} to add a transaction to a block
* with {@link createBlockFromValuesArray}.
* with {@link createBlockFromBytesArray}.
*
* For an unsigned tx this method uses the empty Bytes values for the
* signature parameters `v`, `r` and `s` for encoding. For an EIP-155 compliant
Expand Down
2 changes: 1 addition & 1 deletion packages/tx/src/2930/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class AccessListEIP2930Transaction extends BaseTransaction<TransactionTyp
* signatureYParity (v), signatureR (r), signatureS (s)]`
*
* Use {@link AccessListEIP2930Transaction.serialize} to add a transaction to a block
* with {@link createBlockFromValuesArray}.
* with {@link createBlockFromBytesArray}.
*
* For an unsigned tx this method uses the empty Bytes values for the
* signature parameters `v`, `r` and `s` for encoding. For an EIP-155 compliant
Expand Down
2 changes: 1 addition & 1 deletion packages/tx/src/4844/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class BlobEIP4844Transaction extends BaseTransaction<TransactionType.Blob
* access_list, max_fee_per_data_gas, blob_versioned_hashes, y_parity, r, s]`.
*
* Use {@link BlobEIP4844Transaction.serialize} to add a transaction to a block
* with {@link createBlockFromValuesArray}.
* with {@link createBlockFromBytesArray}.
*
* For an unsigned tx this method uses the empty Bytes values for the
* signature parameters `v`, `r` and `s` for encoding. For an EIP-155 compliant
Expand Down
2 changes: 1 addition & 1 deletion packages/tx/src/7702/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class EOACodeEIP7702Transaction extends BaseTransaction<TransactionType.E
* accessList, authorizationList, signatureYParity, signatureR, signatureS]`
*
* Use {@link EOACodeEIP7702Transaction.serialize} to add a transaction to a block
* with {@link createBlockFromValuesArray}.
* with {@link createBlockFromBytesArray}.
*
* For an unsigned tx this method uses the empty Bytes values for the
* signature parameters `v`, `r` and `s` for encoding. For an EIP-155 compliant
Expand Down
2 changes: 1 addition & 1 deletion packages/tx/src/baseTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export abstract class BaseTransaction<T extends TransactionType>
* Returns a Uint8Array Array of the raw Bytes of this transaction, in order.
*
* Use {@link BaseTransaction.serialize} to add a transaction to a block
* with {@link createBlockFromValuesArray}.
* with {@link createBlockFromBytesArray}.
*
* For an unsigned tx this method uses the empty Bytes values for the
* signature parameters `v`, `r` and `s` for encoding. For an EIP-155 compliant
Expand Down
2 changes: 1 addition & 1 deletion packages/tx/src/legacy/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class LegacyTransaction extends BaseTransaction<TransactionType.Legacy> {
* Format: `[nonce, gasPrice, gasLimit, to, value, data, v, r, s]`
*
* For legacy txs this is also the correct format to add transactions
* to a block with {@link createBlockFromValuesArray} (use the `serialize()` method
* to a block with {@link createBlockFromBytesArray} (use the `serialize()` method
* for typed txs).
*
* For an unsigned tx this method returns the empty Bytes values
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/test/api/runBlock.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
createBlock,
createBlockFromRLPSerializedBlock,
createBlockFromValuesArray,
createBlockFromBytesArray,
createSealedCliqueBlock,
} from '@ethereumjs/block'
import { Common, Goerli, Hardfork, Mainnet, createCustomCommon } from '@ethereumjs/common'
Expand Down Expand Up @@ -317,7 +317,7 @@ describe('runBlock() -> runtime behavior', async () => {
) as NestedUint8Array
// edit extra data of this block to "dao-hard-fork"
block1[0][12] = utf8ToBytes('dao-hard-fork')
const block = createBlockFromValuesArray(block1 as BlockBytes, { common })
const block = createBlockFromBytesArray(block1 as BlockBytes, { common })
await setupPreConditions(vm.stateManager, testData)

// fill two original DAO child-contracts with funds and the recovery account with funds in order to verify that the balance gets summed correctly
Expand Down

0 comments on commit 0e62524

Please sign in to comment.