Skip to content

Commit

Permalink
client: preimageManager test
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrocheleau committed Nov 9, 2023
1 parent c9ed40a commit e0a4baf
Showing 1 changed file with 68 additions and 1 deletion.
69 changes: 68 additions & 1 deletion packages/client/test/miner/miner.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Block, BlockHeader } from '@ethereumjs/block'
import { Common, Chain as CommonChain, Hardfork } from '@ethereumjs/common'
import { keccak256 } from '@ethereumjs/devp2p'
import { DefaultStateManager } from '@ethereumjs/statemanager'
import { FeeMarketEIP1559Transaction, LegacyTransaction } from '@ethereumjs/tx'
import { Address, equalsBytes, hexToBytes } from '@ethereumjs/util'
import { AbstractLevel } from 'abstract-level'
import { keccak256 } from 'ethereum-cryptography/keccak'
import { assert, describe, it, vi } from 'vitest'

import { Chain } from '../../src/blockchain'
Expand Down Expand Up @@ -383,6 +383,73 @@ describe('[Miner]', async () => {
await wait(500)
})

it('assembleBlocks() -> with savePreimages', async () => {
const chain = new FakeChain() as any
const config = new Config({
accountCache: 10000,
storageCache: 1000,
accounts,
mine: true,
common: customCommon,
savePreimages: true,
})
const service = new FullEthereumService({
config,
chain,
metaDB: new AbstractLevel({
encodings: { utf8: true, buffer: true },
}),
})
const miner = new Miner({ config, service, skipHardForkValidation: true })
const { txPool } = service
const { vm, preimagesManager } = service.execution
txPool.start()
miner.start()

assert.ok(preimagesManager !== undefined, 'preimagesManager should be initialized')

await setBalance(vm, A.address, BigInt('400000000000001'))
await setBalance(vm, B.address, BigInt('400000000000001'))

const txs = [txA01, txA02, txA03, txB01]

// add txs
for (const tx of txs) {
await txPool.add(tx)
}

// disable consensus to skip PoA block signer validation
;(vm.blockchain as any)._validateConsensus = false

chain.putBlocks = async (blocks: Block[]) => {
const msg = 'txs in block should be properly ordered by gasPrice and nonce'
const expectedOrder = [txB01, txA01, txA02, txA03]
for (const [index, tx] of expectedOrder.entries()) {
const txHash = blocks[0].transactions[index]?.hash()
assert.ok(txHash !== undefined && equalsBytes(txHash, tx.hash()), msg)
}
miner.stop()
txPool.stop()
}

await (miner as any).queueNextAssembly(0)

// The two accounts (`sender` and `to` accounts) touched by the transactions should be in the preimagesManager
const touchedAddresses = txs.flatMap((tx) => [tx.getSenderAddress().bytes, tx.to!.bytes])
const touchedAddressesHashedKeys = touchedAddresses.map((address) => keccak256(address))

for (const [index, hashedKey] of touchedAddressesHashedKeys.entries()) {
const preimage = await preimagesManager!.getPreimage(hashedKey)
assert.ok(preimage !== null, 'preimage should be saved')
assert.ok(
equalsBytes(preimage!, touchedAddresses[index]),
'preimage should match touched address'
)
}

await wait(500)
})

it('assembleBlocks() -> should not include tx under the baseFee', async () => {
const customChainParams = { hardforks: [{ name: 'london', block: 0 }] }
const common = Common.custom(customChainParams, {
Expand Down

1 comment on commit e0a4baf

@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: e0a4baf Previous: 0b03c8a Ratio
Block 9422905 18545 ops/sec (±3.38%) 40283 ops/sec (±2.46%) 2.17
Block 9422906 17552 ops/sec (±5.68%) 39581 ops/sec (±1.79%) 2.26
Block 9422907 17856 ops/sec (±3.88%) 38817 ops/sec (±2.25%) 2.17
Block 9422910 17980 ops/sec (±3.48%) 37436 ops/sec (±1.99%) 2.08

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

Please sign in to comment.