Skip to content

Commit

Permalink
Merge branch 'master' into trie-find-path-simplification-new
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottyPoi authored Aug 31, 2023
2 parents c3c0d49 + 3c92910 commit 0243734
Show file tree
Hide file tree
Showing 33 changed files with 826 additions and 426 deletions.
27 changes: 10 additions & 17 deletions packages/block/src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,13 @@ export class BlockHeader {
*/
protected _consensusFormatValidation() {
const { nonce, uncleHash, difficulty, extraData, number } = this
const hardfork = this.common.hardfork()

// Consensus type dependent checks
if (this.common.consensusAlgorithm() === ConsensusAlgorithm.Ethash) {
// PoW/Ethash
if (
number > BigInt(0) &&
this.extraData.length > this.common.paramByHardfork('vm', 'maxExtraDataSize', hardfork)
this.extraData.length > this.common.param('vm', 'maxExtraDataSize')
) {
// Check length of data on all post-genesis blocks
const msg = this._errorMsg('invalid amount of extra data')
Expand Down Expand Up @@ -506,10 +505,8 @@ export class BlockHeader {
parentGasLimit = parentGasLimit * elasticity
}
const gasLimit = this.gasLimit
const hardfork = this.common.hardfork()

const a =
parentGasLimit / this.common.paramByHardfork('gasConfig', 'gasLimitBoundDivisor', hardfork)
const a = parentGasLimit / this.common.param('gasConfig', 'gasLimitBoundDivisor')
const maxGasLimit = parentGasLimit + a
const minGasLimit = parentGasLimit - a

Expand All @@ -523,10 +520,8 @@ export class BlockHeader {
throw new Error(msg)
}

if (gasLimit < this.common.paramByHardfork('gasConfig', 'minGasLimit', hardfork)) {
const msg = this._errorMsg(
`gas limit decreased below minimum gas limit for hardfork=${hardfork}`
)
if (gasLimit < this.common.param('gasConfig', 'minGasLimit')) {
const msg = this._errorMsg(`gas limit decreased below minimum gas limit`)
throw new Error(msg)
}
}
Expand Down Expand Up @@ -704,18 +699,16 @@ export class BlockHeader {
)
throw new Error(msg)
}
const hardfork = this.common.hardfork()
const blockTs = this.timestamp
const { timestamp: parentTs, difficulty: parentDif } = parentBlockHeader
const minimumDifficulty = this.common.paramByHardfork('pow', 'minimumDifficulty', hardfork)
const offset =
parentDif / this.common.paramByHardfork('pow', 'difficultyBoundDivisor', hardfork)
const minimumDifficulty = this.common.param('pow', 'minimumDifficulty')
const offset = parentDif / this.common.param('pow', 'difficultyBoundDivisor')
let num = this.number

// We use a ! here as TS cannot follow this hardfork-dependent logic, but it always gets assigned
let dif!: bigint

if (this.common.hardforkGteHardfork(hardfork, Hardfork.Byzantium) === true) {
if (this.common.gteHardfork(Hardfork.Byzantium) === true) {
// max((2 if len(parent.uncles) else 1) - ((timestamp - parent.timestamp) // 9), -99) (EIP100)
const uncleAddend = equalsBytes(parentBlockHeader.uncleHash, KECCAK256_RLP_ARRAY) ? 1 : 2
let a = BigInt(uncleAddend) - (blockTs - parentTs) / BigInt(9)
Expand All @@ -727,13 +720,13 @@ export class BlockHeader {
dif = parentDif + offset * a
}

if (this.common.hardforkGteHardfork(hardfork, Hardfork.Byzantium) === true) {
if (this.common.gteHardfork(Hardfork.Byzantium) === true) {
// Get delay as parameter from common
num = num - this.common.param('pow', 'difficultyBombDelay')
if (num < BigInt(0)) {
num = BigInt(0)
}
} else if (this.common.hardforkGteHardfork(hardfork, Hardfork.Homestead) === true) {
} else if (this.common.gteHardfork(Hardfork.Homestead) === true) {
// 1 - (block_timestamp - parent_timestamp) // 10
let a = BigInt(1) - (blockTs - parentTs) / BigInt(10)
const cutoff = BigInt(-99)
Expand All @@ -744,7 +737,7 @@ export class BlockHeader {
dif = parentDif + offset * a
} else {
// pre-homestead
if (parentTs + this.common.paramByHardfork('pow', 'durationLimit', hardfork) > blockTs) {
if (parentTs + this.common.param('pow', 'durationLimit') > blockTs) {
dif = offset + parentDif
} else {
dif = parentDif - offset
Expand Down
12 changes: 12 additions & 0 deletions packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,16 @@ const args: ClientOpts = yargs(hideBin(process.argv))
'To run client in single node configuration without need to discover the sync height from peer. Particularly useful in test configurations. This flag is automically activated in the "dev" mode',
boolean: true,
})
.option('vmProfileBlocks', {
describe: 'Report the VM profile after running each block',
boolean: true,
default: false,
})
.option('vmProfileTxs', {
describe: 'Report the VM profile after running each block',
boolean: true,
default: false,
})
.option('loadBlocksFromRlp', {
describe: 'path to a file of RLP encoded blocks',
string: true,
Expand Down Expand Up @@ -816,6 +826,8 @@ async function run() {
mine,
minerCoinbase: args.minerCoinbase,
isSingleNode,
vmProfileBlocks: args.vmProfileBlocks,
vmProfileTxs: args.vmProfileTxs,
minPeers: args.minPeers,
multiaddrs,
port: args.port,
Expand Down
21 changes: 20 additions & 1 deletion packages/client/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { Logger } from './logging'
import type { EventBusType, MultiaddrLike } from './types'
import type { BlockHeader } from '@ethereumjs/block'
import type { Address } from '@ethereumjs/util'
import type { VM } from '@ethereumjs/vm'
import type { VM, VMProfilerOpts } from '@ethereumjs/vm'
import type { Multiaddr } from 'multiaddr'

export enum DataDirectory {
Expand Down Expand Up @@ -251,6 +251,16 @@ export interface ConfigOptions {
*/
isSingleNode?: boolean

/**
* Whether to profile VM blocks
*/
vmProfileBlocks?: boolean

/**
* Whether to profile VM txs
*/
vmProfileTxs?: boolean

/**
* Unlocked accounts of form [address, privateKey]
* Currently only the first account is used to seal mined PoA blocks
Expand Down Expand Up @@ -376,6 +386,7 @@ export class Config {
public readonly isSingleNode: boolean
public readonly accounts: [address: Address, privKey: Uint8Array][]
public readonly minerCoinbase?: Address
public readonly vmProfilerOpts?: VMProfilerOpts

public readonly safeReorgDistance: number
public readonly skeletonFillCanonicalBackStep: number
Expand Down Expand Up @@ -434,6 +445,14 @@ export class Config {
this.debugCode = options.debugCode ?? Config.DEBUGCODE_DEFAULT
this.mine = options.mine ?? false
this.isSingleNode = options.isSingleNode ?? false

if (options.vmProfileBlocks !== undefined || options.vmProfileTxs !== undefined) {
this.vmProfilerOpts = {
reportAfterBlock: options.vmProfileBlocks !== false,
reportAfterTx: options.vmProfileTxs !== false,
}
}

this.accounts = options.accounts ?? []
this.minerCoinbase = options.minerCoinbase

Expand Down
1 change: 1 addition & 0 deletions packages/client/src/execution/vmexecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class VMExecution extends Execution {
common: this.config.execCommon,
blockchain: this.chain.blockchain,
stateManager,
profilerOpts: this.config.vmProfilerOpts,
})
} else {
this.vm = this.config.vm
Expand Down
2 changes: 2 additions & 0 deletions packages/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,7 @@ export interface ClientOpts {
txLookupLimit?: number
startBlock?: number
isSingleNode?: boolean
vmProfileBlocks?: boolean
vmProfileTxs?: boolean
loadBlocksFromRlp?: string
}
3 changes: 1 addition & 2 deletions packages/common/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,7 @@ export const chains: ChainsDict = {
{
name: 'cancun',
block: null,
timestamp: '2000000000',
forkHash: '0xffab2acd',
forkHash: null,
},
],
bootstrapNodes: [
Expand Down
Loading

0 comments on commit 0243734

Please sign in to comment.