Skip to content

Commit

Permalink
Merge branch 'master' into trie/issue-3333
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrocheleau committed Apr 27, 2024
2 parents 7fbf55a + ae08197 commit 26b51a4
Show file tree
Hide file tree
Showing 188 changed files with 1,049 additions and 911 deletions.
5 changes: 2 additions & 3 deletions Dockerfile
Expand Up @@ -14,13 +14,12 @@ WORKDIR /usr/app
COPY --from=build /usr/app .

# Sanity check
#RUN node /usr/app/packages/client/dist/bin/cli.js --help
RUN node /usr/app/node_modules/.bin/ethereumjs --help
RUN node /usr/app/packages/client/dist/esm/bin/cli.js --help


# NodeJS applications have a default memory limit of 2.5GB.
# This limit is bit tight, it is recommended to raise the limit
# since memory may spike during certain network conditions.
ENV NODE_OPTIONS=--max_old_space_size=6144

ENTRYPOINT ["node", "/usr/app/node_modules/.bin/ethereumjs"]
ENTRYPOINT ["node", "/usr/app/packages/client/dist/esm/bin/cli.js"]
48 changes: 13 additions & 35 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions packages/block/src/block.ts
Expand Up @@ -559,7 +559,7 @@ export class Block {
// eslint-disable-next-line prefer-const
for (let [i, tx] of this.transactions.entries()) {
const errs = tx.getValidationErrors()
if (this.common.isActivatedEIP(1559) === true) {
if (this.common.isActivatedEIP(1559)) {
if (tx.supports(Capability.EIP1559FeeMarket)) {
tx = tx as FeeMarketEIP1559Transaction
if (tx.maxFeePerGas < this.header.baseFeePerGas!) {
Expand All @@ -572,7 +572,7 @@ export class Block {
}
}
}
if (this.common.isActivatedEIP(4844) === true) {
if (this.common.isActivatedEIP(4844)) {
if (tx instanceof BlobEIP4844Transaction) {
blobGasUsed += BigInt(tx.numBlobs()) * blobGasPerBlob
if (blobGasUsed > blobGasLimit) {
Expand All @@ -587,7 +587,7 @@ export class Block {
}
}

if (this.common.isActivatedEIP(4844) === true) {
if (this.common.isActivatedEIP(4844)) {
if (blobGasUsed !== this.header.blobGasUsed) {
errors.push(`invalid blobGasUsed expected=${this.header.blobGasUsed} actual=${blobGasUsed}`)
}
Expand Down
26 changes: 13 additions & 13 deletions packages/block/src/header.ts
Expand Up @@ -76,7 +76,7 @@ export class BlockHeader {
* EIP-4399: After merge to PoS, `mixHash` supplanted as `prevRandao`
*/
get prevRandao() {
if (this.common.isActivatedEIP(4399) === false) {
if (!this.common.isActivatedEIP(4399)) {
const msg = this._errorMsg(
'The prevRandao parameter can only be accessed when EIP-4399 is activated'
)
Expand Down Expand Up @@ -361,7 +361,7 @@ export class BlockHeader {
}

// Validation for EIP-1559 blocks
if (this.common.isActivatedEIP(1559) === true) {
if (this.common.isActivatedEIP(1559)) {
if (typeof this.baseFeePerGas !== 'bigint') {
const msg = this._errorMsg('EIP1559 block has no base fee field')
throw new Error(msg)
Expand All @@ -380,7 +380,7 @@ export class BlockHeader {
}
}

if (this.common.isActivatedEIP(4895) === true) {
if (this.common.isActivatedEIP(4895)) {
if (this.withdrawalsRoot === undefined) {
const msg = this._errorMsg('EIP4895 block has no withdrawalsRoot field')
throw new Error(msg)
Expand All @@ -393,7 +393,7 @@ export class BlockHeader {
}
}

if (this.common.isActivatedEIP(4788) === true) {
if (this.common.isActivatedEIP(4788)) {
if (this.parentBeaconBlockRoot === undefined) {
const msg = this._errorMsg('EIP4788 block has no parentBeaconBlockRoot field')
throw new Error(msg)
Expand Down Expand Up @@ -550,7 +550,7 @@ export class BlockHeader {
* Calculates the base fee for a potential next block
*/
public calcNextBaseFee(): bigint {
if (this.common.isActivatedEIP(1559) === false) {
if (!this.common.isActivatedEIP(1559)) {
const msg = this._errorMsg(
'calcNextBaseFee() can only be called with EIP1559 being activated'
)
Expand Down Expand Up @@ -671,26 +671,26 @@ export class BlockHeader {
this.nonce,
]

if (this.common.isActivatedEIP(1559) === true) {
if (this.common.isActivatedEIP(1559)) {
rawItems.push(bigIntToUnpaddedBytes(this.baseFeePerGas!))
}

if (this.common.isActivatedEIP(4895) === true) {
if (this.common.isActivatedEIP(4895)) {
rawItems.push(this.withdrawalsRoot!)
}

// in kaunstinen 2 verkle is scheduled after withdrawals, will eventually be post deneb hopefully
if (this.common.isActivatedEIP(6800) === true) {
if (this.common.isActivatedEIP(6800)) {
// execution witness is not mandatory part of the the block so nothing to push here
// but keep this comment segment for clarity regarding the same and move it according as per the
// HF sequence eventually planned
}

if (this.common.isActivatedEIP(4844) === true) {
if (this.common.isActivatedEIP(4844)) {
rawItems.push(bigIntToUnpaddedBytes(this.blobGasUsed!))
rawItems.push(bigIntToUnpaddedBytes(this.excessBlobGas!))
}
if (this.common.isActivatedEIP(4788) === true) {
if (this.common.isActivatedEIP(4788)) {
rawItems.push(this.parentBeaconBlockRoot!)
}

Expand Down Expand Up @@ -950,14 +950,14 @@ export class BlockHeader {
mixHash: bytesToHex(this.mixHash),
nonce: bytesToHex(this.nonce),
}
if (this.common.isActivatedEIP(1559) === true) {
if (this.common.isActivatedEIP(1559)) {
jsonDict.baseFeePerGas = bigIntToHex(this.baseFeePerGas!)
}
if (this.common.isActivatedEIP(4844) === true) {
if (this.common.isActivatedEIP(4844)) {
jsonDict.blobGasUsed = bigIntToHex(this.blobGasUsed!)
jsonDict.excessBlobGas = bigIntToHex(this.excessBlobGas!)
}
if (this.common.isActivatedEIP(4788) === true) {
if (this.common.isActivatedEIP(4788)) {
jsonDict.parentBeaconBlockRoot = bytesToHex(this.parentBeaconBlockRoot!)
}
return jsonDict
Expand Down
4 changes: 2 additions & 2 deletions packages/blockchain/src/blockchain.ts
Expand Up @@ -662,7 +662,7 @@ export class Blockchain implements BlockchainInterface {
}

// check blockchain dependent EIP1559 values
if (header.common.isActivatedEIP(1559) === true) {
if (header.common.isActivatedEIP(1559)) {
// check if the base fee is correct
let expectedBaseFee
const londonHfBlock = this.common.hardforkBlock(Hardfork.London)
Expand All @@ -678,7 +678,7 @@ export class Blockchain implements BlockchainInterface {
}
}

if (header.common.isActivatedEIP(4844) === true) {
if (header.common.isActivatedEIP(4844)) {
const expectedExcessBlobGas = parentHeader.calcNextExcessBlobGas()
if (header.excessBlobGas !== expectedExcessBlobGas) {
throw new Error(`expected blob gas: ${expectedExcessBlobGas}, got: ${header.excessBlobGas}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/client/archive/libp2p/index.ts
Expand Up @@ -8,9 +8,9 @@ import { Config } from '../src/config'
import { LevelDB } from '../src/execution/level'
import { parseMultiaddrs } from '../src/util'

import { getLogger } from './logging'
import { getLogger } from './logging.js'
// Blockchain
export * from '../src/blockchain/chain'
export * from '../src/blockchain/chain/index.js'

// Peer
export * from '../src/net/peer/libp2ppeer'
Expand Down
54 changes: 31 additions & 23 deletions packages/client/bin/cli.ts
Expand Up @@ -28,11 +28,9 @@ import {
} from '@polkadot/wasm-crypto'
import { keccak256 } from 'ethereum-cryptography/keccak'
import { ecdsaRecover, ecdsaSign } from 'ethereum-cryptography/secp256k1-compat'
import { sha256 } from 'ethereum-cryptography/sha256'
import { existsSync, writeFileSync } from 'fs'
import { ensureDirSync, readFileSync, removeSync } from 'fs-extra'
import { sha256 } from 'ethereum-cryptography/sha256.js'
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'fs'
import * as http from 'http'
import { Server as RPCServer } from 'jayson/promise'
import { loadKZG } from 'kzg-wasm'
import { Level } from 'level'
import { homedir } from 'os'
Expand All @@ -43,24 +41,25 @@ import * as url from 'url'
import * as yargs from 'yargs'
import { hideBin } from 'yargs/helpers'

import { EthereumClient } from '../src/client'
import { Config, DataDirectory, SyncMode } from '../src/config'
import { LevelDB } from '../src/execution/level'
import { getLogger } from '../src/logging'
import { Event } from '../src/types'
import { parseMultiaddrs } from '../src/util'
import { setupMetrics } from '../src/util/metrics'
import { EthereumClient } from '../src/client.js'
import { Config, DataDirectory, SyncMode } from '../src/config.js'
import { LevelDB } from '../src/execution/level.js'
import { getLogger } from '../src/logging.js'
import { Event } from '../src/types.js'
import { parseMultiaddrs } from '../src/util/index.js'
import { setupMetrics } from '../src/util/metrics.js'

import { helprpc, startRPCServers } from './startRpc'
import { helprpc, startRPCServers } from './startRpc.js'

import type { Logger } from '../src/logging'
import type { FullEthereumService } from '../src/service'
import type { ClientOpts } from '../src/types'
import type { RPCArgs } from './startRpc'
import type { Logger } from '../src/logging.js'
import type { FullEthereumService } from '../src/service/index.js'
import type { ClientOpts } from '../src/types.js'
import type { RPCArgs } from './startRpc.js'
import type { BlockBytes } from '@ethereumjs/block'
import type { CustomCrypto } from '@ethereumjs/common'
import type { GenesisState, PrefixedHexString } from '@ethereumjs/util'
import type { AbstractLevel } from 'abstract-level'
import type { Server as RPCServer } from 'jayson/promise/index.js'

type Account = [address: Address, privateKey: Uint8Array]

Expand Down Expand Up @@ -488,17 +487,23 @@ function initDBs(config: Config): {
} {
// Chain DB
const chainDataDir = config.getDataDirectory(DataDirectory.Chain)
ensureDirSync(chainDataDir)
mkdirSync(chainDataDir, {
recursive: true,
})
const chainDB = new Level<string | Uint8Array, string | Uint8Array>(chainDataDir)

// State DB
const stateDataDir = config.getDataDirectory(DataDirectory.State)
ensureDirSync(stateDataDir)
mkdirSync(stateDataDir, {
recursive: true,
})
const stateDB = new Level<string | Uint8Array, string | Uint8Array>(stateDataDir)

// Meta DB (receipts, logs, indexes, skeleton chain)
const metaDataDir = config.getDataDirectory(DataDirectory.Meta)
ensureDirSync(metaDataDir)
mkdirSync(metaDataDir, {
recursive: true,
})
const metaDB = new Level<string | Uint8Array, string | Uint8Array>(metaDataDir)

return { chainDB, stateDB, metaDB }
Expand Down Expand Up @@ -582,7 +587,7 @@ async function startExecutionFrom(client: EthereumClient) {
})

if (
client.config.execCommon.hardforkGteHardfork(startExecutionHardfork, Hardfork.Prague) &&
client.config.execCommon.hardforkGteHardfork(startExecutionHardfork, Hardfork.Osaka) &&
client.config.statelessVerkle
) {
// for stateless verkle sync execution witnesses are available and hence we can blindly set the vmHead
Expand Down Expand Up @@ -870,7 +875,8 @@ const stopClient = async (
config.logger.info('Shutting down the client and the servers...')
const { client, servers } = clientHandle
for (const s of servers) {
s instanceof RPCServer ? (s as RPCServer).http().close() : (s as http.Server).close()
// @ts-expect-error jayson.Server type doesn't play well with ESM for some reason
s['http'] !== undefined ? (s as RPCServer).http().close() : (s as http.Server).close()
}
await client.stop()
config.logger.info('Exiting.')
Expand Down Expand Up @@ -963,7 +969,7 @@ async function run() {
args.discDns = false
if (accounts.length === 0) {
// If generating new keys delete old chain data to prevent genesis block mismatch
removeSync(`${args.dataDir}/devnet`)
rmSync(`${args.dataDir}/devnet`, { recursive: true, force: true })
// Create new account
accounts.push(generateAccount())
}
Expand Down Expand Up @@ -1009,7 +1015,9 @@ async function run() {
const datadir = args.dataDir ?? Config.DATADIR_DEFAULT
const networkDir = `${datadir}/${common.chainName()}`
const configDirectory = `${networkDir}/config`
ensureDirSync(configDirectory)
mkdirSync(configDirectory, {
recursive: true,
})
const key = await Config.getClientKey(datadir, common)

// logFile is either filename or boolean true or false to enable (with default) or disable
Expand Down

0 comments on commit 26b51a4

Please sign in to comment.