Skip to content

Commit 0489ec8

Browse files
committed
Merge branch 'master' into vm/error-management-poc
2 parents 052687c + f4f34c8 commit 0489ec8

File tree

84 files changed

+1345
-919
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1345
-919
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ARG VERSION=latest
66
ENV VERSION=$VERSION
77
RUN npm install @ethereumjs/client@$VERSION
88

9-
FROM node:14-alpine
9+
FROM node:16-alpine
1010
WORKDIR /usr/app
1111
COPY --from=build /usr/app .
1212

docker/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ services:
88
volumes:
99
- ./datadir:/datadir
1010
command: >
11-
--datadir=/datadir --logFile
11+
--datadir=/datadir
1212
network_mode: host

packages/block/src/header.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ export class BlockHeader {
6565
return this.logsBloom
6666
}
6767

68+
/**
69+
* EIP-4399: Post-PoS merge, `mixHash` supplanted as `random`
70+
*/
71+
get random() {
72+
if (!this._common.isActivatedEIP(4399)) {
73+
const msg = this._errorMsg(
74+
'The random parameter can only be accessed when EIP-4399 is activated'
75+
)
76+
throw new Error(msg)
77+
}
78+
return this.mixHash
79+
}
80+
6881
/**
6982
* Static constructor to create a block header from a header data dictionary
7083
*
@@ -352,7 +365,7 @@ export class BlockHeader {
352365
transactionsTrie,
353366
receiptTrie,
354367
difficulty,
355-
// extraData,
368+
extraData,
356369
mixHash,
357370
nonce,
358371
} = this
@@ -397,7 +410,7 @@ export class BlockHeader {
397410
}
398411
}
399412

400-
// Check for constant values for PoS blocks
413+
// Validation for PoS blocks (EIP-3675)
401414
if (this._common.consensusType() === ConsensusType.ProofOfStake) {
402415
let error = false
403416
let errorMsg = ''
@@ -412,14 +425,10 @@ export class BlockHeader {
412425
errorMsg += `, difficulty: ${difficulty} (expected: 0)`
413426
error = true
414427
}
415-
// WIP from merge interop event:
416-
// extraData behavior pending consideration, for now allowed to be non-empty
417-
// if (!extraData.equals(Buffer.from([]))) {
418-
// errorMsg += `, extraData: ${extraData.toString('hex')} (expected: '')`
419-
// error = true
420-
// }
421-
if (!mixHash.equals(zeros(32))) {
422-
errorMsg += `, mixHash: ${mixHash.toString('hex')} (expected: ${zeros(32).toString('hex')})`
428+
if (extraData.length > 32) {
429+
errorMsg += `, extraData: ${extraData.toString(
430+
'hex'
431+
)} (cannot exceed 32 bytes length, received ${extraData.length} bytes)`
423432
error = true
424433
}
425434
if (!nonce.equals(zeros(8))) {

packages/block/test/mergeBlock.spec.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ function validateMergeHeader(st: tape.Test, header: BlockHeader) {
2222
st.ok(header.gasLimit.eq(new BN(Buffer.from('ffffffffffffff', 'hex'))), 'gasLimit')
2323
st.ok(header.gasUsed.isZero(), 'gasUsed')
2424
st.ok(header.timestamp.isZero(), 'timestamp')
25-
st.ok(header.extraData.equals(Buffer.from([])), 'extraData')
26-
st.ok(header.mixHash.equals(zeros(32)), 'mixHash')
25+
st.ok(header.extraData.length <= 32, 'extraData')
26+
st.ok(header.mixHash.length === 32, 'mixHash')
2727
st.ok(header.nonce.equals(zeros(8)), 'nonce')
2828
}
2929

@@ -60,26 +60,24 @@ tape('[Header]: Casper PoS / The Merge Functionality', function (t) {
6060
st.pass('should throw on wrong difficulty')
6161
}
6262

63-
// WIP from merge interop event:
64-
// extraData behavior pending consideration, for now allowed to be non-empty
65-
// try {
66-
// const headerData = {
67-
// extraData: Buffer.from('123abc', 'hex'),
68-
// }
69-
// BlockHeader.fromHeaderData(headerData, { common })
70-
// st.fail('should throw')
71-
// } catch (e: any) {
72-
// st.pass('should throw on wrong extraData')
73-
// }
63+
try {
64+
const headerData = {
65+
extraData: Buffer.alloc(33).fill(1),
66+
}
67+
BlockHeader.fromHeaderData(headerData, { common })
68+
st.fail('should throw')
69+
} catch (e: any) {
70+
st.pass('should throw on invalid extraData length')
71+
}
7472

7573
try {
7674
const headerData = {
77-
mixHash: Buffer.alloc(32).fill(1),
75+
mixHash: Buffer.alloc(30).fill(1),
7876
}
7977
BlockHeader.fromHeaderData(headerData, { common })
8078
st.fail('should throw')
8179
} catch (e: any) {
82-
st.pass('should throw on wrong mixHash')
80+
st.pass('should throw on invalid mixHash length')
8381
}
8482

8583
try {
@@ -106,4 +104,21 @@ tape('[Header]: Casper PoS / The Merge Functionality', function (t) {
106104
}
107105
st.end()
108106
})
107+
108+
t.test('EIP-4399: random should return mixHash value', function (st) {
109+
const mixHash = Buffer.alloc(32, 3)
110+
let block = Block.fromBlockData({ header: { mixHash } }, { common })
111+
st.ok(block.header.random.equals(mixHash), 'random should return mixHash value')
112+
113+
const commonLondon = common.copy()
114+
commonLondon.setHardfork(Hardfork.London)
115+
block = Block.fromBlockData({ header: { mixHash } }, { common: commonLondon })
116+
try {
117+
block.header.random
118+
st.fail('should have thrown')
119+
} catch (e: any) {
120+
st.pass('random should throw if EIP-4399 is not activated')
121+
}
122+
st.end()
123+
})
109124
})

packages/client/bin/cli.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,14 @@ function startRPCServers(client: EthereumClient) {
376376
)
377377
}
378378
if (ws) {
379-
server.websocket({ port: wsPort })
379+
const opts: any = { port: wsPort }
380+
if (rpcaddr === wsAddr && rpcport === wsPort) {
381+
// If http and ws are listening on the same port,
382+
// pass in the existing server to prevent a listening error
383+
delete opts.port
384+
opts.server = server
385+
}
386+
server.websocket(opts)
380387
config.logger.info(
381388
`Started JSON RPC Server address=ws://${wsAddr}:${wsPort} namespaces=${namespaces}`
382389
)
@@ -673,4 +680,4 @@ async function run() {
673680
})
674681
}
675682

676-
run().catch((err) => logger?.error(err) ?? console.error(err))
683+
run().catch((err) => logger?.error(err.message.toString()) ?? console.error(err))

packages/client/pithos/Dockerfile renamed to packages/client/kintsugi/Dockerfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
FROM node:14-alpine as build
1+
FROM node:16-alpine as build
22
WORKDIR /usr/app
3-
RUN apk update && apk add --no-cache g++ make python bash git && rm -rf /var/cache/apk/*
3+
RUN apk update && apk add --no-cache bash git && rm -rf /var/cache/apk/*
4+
5+
RUN git clone --depth 1 --branch merge-kintsugi https://github.com/ethereumjs/ethereumjs-monorepo.git
46

5-
WORKDIR /usr/app
6-
RUN git clone --depth 1 --branch merge-pithos https://github.com/ethereumjs/ethereumjs-monorepo.git
77
WORKDIR /usr/app/ethereumjs-monorepo
8-
RUN npm i -g npm@7
98
RUN npm i
109

11-
FROM node:14-alpine
10+
FROM node:16-alpine
1211
WORKDIR /usr/app
1312
COPY --from=build /usr/app .
1413

packages/client/kintsugi/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# merge-devnet-3 instructions
2+
3+
## Execution - EthereumJS Setup
4+
5+
Please ensure you have Node 12.x+ installed
6+
7+
1. `git clone --depth 1 --branch merge-kintsugi https://github.com/ethereumjs/ethereumjs-monorepo.git`
8+
1. `cd ethereumjs-monorepo`
9+
1. `npm i`
10+
1. `cd packages/client`
11+
12+
### Run client
13+
14+
1. `npm run client:start -- --datadir kintsugi/datadir --gethGenesis kintsugi/config/genesis.json --saveReceipts --rpc --ws --rpcEngine --rpcEnginePort=8545 --bootnodes=64.225.4.226:30303`
15+
16+
#### Docker
17+
18+
Or try it in Docker.
19+
20+
In `packages/client/kintsugi` run:
21+
22+
`docker-compose --file docker-compose.ethereumjs.yml up`
23+
24+
## Consensus
25+
26+
### Lodestar
27+
28+
#### Beacon
29+
30+
1. Use lodestar branch `master` and run `yarn && yarn build`
31+
1. Run cmd: `./lodestar beacon --rootDir kintsugi/temp --network=kintsugi --eth1.providerUrls=http://localhost:8545 --execution.urls=http://localhost:8545`
32+
33+
#### Validator
34+
35+
1. Run cmd: `./lodestar validator --rootDir=kintsugi/temp_validatordata --paramsFile=kintsugi/config/config.yaml --keystoresDir=kintsugi/keystores --secretsDir=kintsugi/secrets`
36+
37+
### Lighthouse
38+
39+
### Beacon
40+
41+
1. Use lighthouse branch `kintsugi` and run `make`
42+
1. Make dir `lighthouse/kintsugi` and copy in from this dir: `config.yaml`, `genesis.ssz`, `deploy_block.txt`, `deposit_contract.txt`, `deposit_contract_block.txt`
43+
1. Run cmd: `lighthouse --debug-level=info --datadir=kintsugi/datadir --testnet-dir=kintsugi beacon_node --disable-enr-auto-update --dummy-eth1 --boot-nodes="enr:-Iq4QKuNB_wHmWon7hv5HntHiSsyE1a6cUTK1aT7xDSU_hNTLW3R4mowUboCsqYoh1kN9v3ZoSu_WuvW9Aw0tQ0Dxv6GAXxQ7Nv5gmlkgnY0gmlwhLKAlv6Jc2VjcDI1NmsxoQK6S-Cii_KmfFdUJL2TANL3ksaKUnNXvTCv1tLwXs0QgIN1ZHCCIyk" --merge --http-allow-sync-stalled --metrics --disable-packet-filter --execution-endpoints=http://127.0.0.1:8545 --terminal-total-difficulty-override=5000000000`
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Extends the mainnet preset
2+
PRESET_BASE: 'mainnet'
3+
# Genesis
4+
# ---------------------------------------------------------------
5+
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT: 72100
6+
# Dec 16th, 2021, 13:00 UTC
7+
MIN_GENESIS_TIME: 1639659600
8+
# Gensis fork
9+
GENESIS_FORK_VERSION: 0x60000069
10+
# 300 seconds (5 min)
11+
GENESIS_DELAY: 300
12+
13+
14+
# Forking
15+
# ---------------------------------------------------------------
16+
# Some forks are disabled for now:
17+
# - These may be re-assigned to another fork-version later
18+
# - Temporarily set to max uint64 value: 2**64 - 1
19+
20+
# Altair
21+
ALTAIR_FORK_VERSION: 0x61000070
22+
ALTAIR_FORK_EPOCH: 10
23+
# Bellatrix
24+
BELLATRIX_FORK_VERSION: 0x62000071
25+
BELLATRIX_FORK_EPOCH: 20
26+
TERMINAL_TOTAL_DIFFICULTY: 5000000000
27+
TERMINAL_BLOCK_HASH: 0x0000000000000000000000000000000000000000000000000000000000000000
28+
TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: 18446744073709551615
29+
30+
# Sharding
31+
SHARDING_FORK_VERSION: 0x03000000
32+
SHARDING_FORK_EPOCH: 18446744073709551615
33+
34+
35+
# Time parameters
36+
# ---------------------------------------------------------------
37+
# 12 seconds
38+
SECONDS_PER_SLOT: 12
39+
# 14 (estimate from Eth1 mainnet)
40+
SECONDS_PER_ETH1_BLOCK: 14
41+
# 2**8 (= 256) epochs ~27 hours
42+
MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256
43+
# 2**8 (= 256) epochs ~27 hours
44+
SHARD_COMMITTEE_PERIOD: 256
45+
# 16 blocks is ~190s
46+
ETH1_FOLLOW_DISTANCE: 16
47+
48+
49+
# Validator cycle
50+
# ---------------------------------------------------------------
51+
# 2**2 (= 4)
52+
INACTIVITY_SCORE_BIAS: 4
53+
# 2**4 (= 16)
54+
INACTIVITY_SCORE_RECOVERY_RATE: 16
55+
# 2**4 * 10**9 (= 16,000,000,000) Gwei
56+
EJECTION_BALANCE: 16000000000
57+
# 2**2 (= 4)
58+
MIN_PER_EPOCH_CHURN_LIMIT: 4
59+
# 2**16 (= 65,536)
60+
CHURN_LIMIT_QUOTIENT: 65536
61+
62+
63+
# Deposit contract
64+
# ---------------------------------------------------------------
65+
# Custom Ethereum testnet
66+
DEPOSIT_CHAIN_ID: 1337702
67+
DEPOSIT_NETWORK_ID: 1337702
68+
DEPOSIT_CONTRACT_ADDRESS: 0x4242424242424242424242424242424242424242
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- enr:-Iq4QKuNB_wHmWon7hv5HntHiSsyE1a6cUTK1aT7xDSU_hNTLW3R4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rMaEDH7tt6r2IO9tq5vSfHJtdi1wTBb37n29yVaQ2iAZSE3qIc3luY25ldHMPg3RjcIIjKIN1ZHCCIyg
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
enr:-Iq4QKuNB_wHmWon7hv5HntHiSsyE1a6cUTK1aT7xDSU_hNTLW3R4mowUboCsqYoh1kN9v3ZoSu_WuvW9Aw0tQ0Dxv6GAXxQ7Nv5gmlkgnY0gmlwhLKAlv6Jc2VjcDI1NmsxoQK6S-Cii_KmfFdUJL2TANL3ksaKUnNXvTCv1tLwXs0QgIN1ZHCCIyk
2+
enr:-Ly4QOMHhGw2RIq9sHGHdSrhpjBJ421HplSN80sVyaNJkdUDSACc2_CXb1B-PJs9TR5yuV5xItUR4fcsaZZNHKCSC1QSh2F0dG5ldHOI__________-EZXRoMpDucelzYgAAcf__________gmlkgnY0gmlwhKXouc-Jc2VjcDI1NmsxoQO_Mk0rN4Q4vheqeFkz0bA9uWO8Cq51rNAxfq3rhNRKZIhzeW5jbmV0cw-DdGNwgiMog3VkcIIjKA
3+
enr:-L24QNzlHJhdNf8OXLMdc5qrCI9iwEoTOJHz66YxtVStBVmXEwOFzWqFitxNfc6_ckUhhBZKWT6J-BO5JmikXu3fcOWBk4dhdHRuZXRziP__________hGV0aDKQ7nHpc2IAAHH__________4JpZIJ2NIJpcIRA4QTfiXNlY3AyNTZrMaED4DY2_MH1Q66-9YRxcxhSO5hqaUd-IGqOsMXJfcCfnW2Ic3luY25ldHMPg3RjcIIjKIN1ZHCCIyg
4+
enr:-Ly4QCz_0NonV_RhGRbI8lezNtdzkK9gEvfQsvQdCiuZcqYGTuoCrRdhpKINp90_nClvi7of2Sq0AcNMk1-BMO91rqMOh2F0dG5ldHOI__________-EZXRoMpDucelzYgAAcf__________gmlkgnY0gmlwhKXosXmJc2VjcDI1NmsxoQJuQwF3fUjF432CpNvXqv5R6c4ZKr7jFX2Bzjdy9hW79IhzeW5jbmV0cw-DdGNwgiMog3VkcIIjKA
5+
enr:-L24QJu98clS2Xl1L80iDeSCr4D_VDFl7S-63fmuAcxTy3RwThEy1JrHy2dkCq_7RYZz_y4D04o8C4iOIHd0Bb86PQCBgYdhdHRuZXRziO309Lg2pfflhGV0aDKQ7nHpc2IAAHH__________4JpZIJ2NIJpcIShI0tOiXNlY3AyNTZrMaEDH7tt6r2IO9tq5vSfHJtdi1wTBb37n29yVaQ2iAZSE3qIc3luY25ldHMPg3RjcIIjKIN1ZHCCIyg

0 commit comments

Comments
 (0)