Skip to content

Commit 83475fe

Browse files
authored
Merge of #5137
2 parents 53d9fae + 1947319 commit 83475fe

File tree

5 files changed

+62
-30
lines changed

5 files changed

+62
-30
lines changed

.github/workflows/test-suite.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ jobs:
309309
run: |
310310
make
311311
- name: Install lcli
312-
if: env.SELF_HOSTED_RUNNERS == 'false'
312+
# TODO: uncomment after the version of lcli in https://github.com/sigp/lighthouse/pull/5137
313+
# is installed on the runners
314+
# if: env.SELF_HOSTED_RUNNERS == 'false'
313315
run: make install-lcli
314316
- name: Run the doppelganger protection failure test script
315317
run: |

lcli/src/new_testnet.rs

+51-23
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ use ethereum_hashing::hash;
99
use ssz::Decode;
1010
use ssz::Encode;
1111
use state_processing::process_activations;
12-
use state_processing::upgrade::{upgrade_to_altair, upgrade_to_bellatrix};
12+
use state_processing::upgrade::{
13+
upgrade_to_altair, upgrade_to_bellatrix, upgrade_to_capella, upgrade_to_deneb,
14+
};
1315
use std::fs::File;
1416
use std::io::Read;
1517
use std::path::PathBuf;
@@ -19,8 +21,8 @@ use types::ExecutionBlockHash;
1921
use types::{
2022
test_utils::generate_deterministic_keypairs, Address, BeaconState, ChainSpec, Config, Epoch,
2123
Eth1Data, EthSpec, ExecutionPayloadHeader, ExecutionPayloadHeaderCapella,
22-
ExecutionPayloadHeaderDeneb, ExecutionPayloadHeaderMerge, ExecutionPayloadHeaderRefMut,
23-
ForkName, Hash256, Keypair, PublicKey, Validator,
24+
ExecutionPayloadHeaderDeneb, ExecutionPayloadHeaderMerge, ForkName, Hash256, Keypair,
25+
PublicKey, Validator,
2426
};
2527

2628
pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Result<(), String> {
@@ -302,26 +304,47 @@ fn initialize_state_with_validators<T: EthSpec>(
302304
state.fork_mut().previous_version = spec.bellatrix_fork_version;
303305

304306
// Override latest execution payload header.
305-
// See https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/merge/beacon-chain.md#testing
306-
307-
// Currently, we only support starting from a bellatrix state
308-
match state
309-
.latest_execution_payload_header_mut()
310-
.map_err(|e| format!("Failed to get execution payload header: {:?}", e))?
311-
{
312-
ExecutionPayloadHeaderRefMut::Merge(header_mut) => {
313-
if let ExecutionPayloadHeader::Merge(eph) = execution_payload_header {
314-
*header_mut = eph;
315-
} else {
316-
return Err("Execution payload header must be a bellatrix header".to_string());
317-
}
318-
}
319-
ExecutionPayloadHeaderRefMut::Capella(_) => {
320-
return Err("Cannot start genesis from a capella state".to_string())
321-
}
322-
ExecutionPayloadHeaderRefMut::Deneb(_) => {
323-
return Err("Cannot start genesis from a deneb state".to_string())
324-
}
307+
// See https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/bellatrix/beacon-chain.md#testing
308+
if let ExecutionPayloadHeader::Merge(ref header) = execution_payload_header {
309+
*state
310+
.latest_execution_payload_header_merge_mut()
311+
.or(Err("mismatched fork".to_string()))? = header.clone();
312+
}
313+
}
314+
315+
if spec
316+
.capella_fork_epoch
317+
.map_or(false, |fork_epoch| fork_epoch == T::genesis_epoch())
318+
{
319+
upgrade_to_capella(&mut state, spec).unwrap();
320+
321+
// Remove intermediate fork from `state.fork`.
322+
state.fork_mut().previous_version = spec.capella_fork_version;
323+
324+
// Override latest execution payload header.
325+
// See https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/bellatrix/beacon-chain.md#testing
326+
if let ExecutionPayloadHeader::Capella(ref header) = execution_payload_header {
327+
*state
328+
.latest_execution_payload_header_capella_mut()
329+
.or(Err("mismatched fork".to_string()))? = header.clone();
330+
}
331+
}
332+
333+
if spec
334+
.deneb_fork_epoch
335+
.map_or(false, |fork_epoch| fork_epoch == T::genesis_epoch())
336+
{
337+
upgrade_to_deneb(&mut state, spec).unwrap();
338+
339+
// Remove intermediate fork from `state.fork`.
340+
state.fork_mut().previous_version = spec.deneb_fork_version;
341+
342+
// Override latest execution payload header.
343+
// See https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/bellatrix/beacon-chain.md#testing
344+
if let ExecutionPayloadHeader::Deneb(ref header) = execution_payload_header {
345+
*state
346+
.latest_execution_payload_header_deneb_mut()
347+
.or(Err("mismatched fork".to_string()))? = header.clone();
325348
}
326349
}
327350

@@ -331,5 +354,10 @@ fn initialize_state_with_validators<T: EthSpec>(
331354
// Set genesis validators root for domain separation and chain versioning
332355
*state.genesis_validators_root_mut() = state.update_validators_tree_hash_cache().unwrap();
333356

357+
// Sanity check for state fork matching config fork.
358+
state
359+
.fork_name(spec)
360+
.map_err(|e| format!("state fork mismatch: {e:?}"))?;
361+
334362
Ok(state)
335363
}

scripts/local_testnet/geth.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ exec $GETH_BINARY \
5050
--bootnodes $EL_BOOTNODE_ENODE \
5151
--port $network_port \
5252
--http.port $http_port \
53-
--authrpc.port $auth_port
53+
--authrpc.port $auth_port \
54+
2>&1 | tee $data_dir/geth.log

scripts/tests/genesis.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"londonBlock": 0,
1414
"mergeForkBlock": 0,
1515
"shanghaiTime": 0,
16-
"shardingForkTime": 0,
16+
"cancunTime": 0,
1717
"terminalTotalDifficulty": 0,
1818
"terminalTotalDifficultyPassed": true
1919
},

scripts/tests/vars.env

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ DEPOSIT_CONTRACT_ADDRESS=4242424242424242424242424242424242424242
1616
GENESIS_FORK_VERSION=0x42424242
1717

1818
# Block hash generated from genesis.json in directory
19-
ETH1_BLOCK_HASH=add7865f8346031c72287e2edc4a4952fd34fc0a8642403e8c1bce67f215c92b
19+
ETH1_BLOCK_HASH=7a5c656343c3a66dcf75415958b500e8873f9dab0cd588e6cf0785b52a06dd34
2020

2121
VALIDATOR_COUNT=80
2222
GENESIS_VALIDATOR_COUNT=80
@@ -41,8 +41,8 @@ CHAIN_ID=4242
4141
# Hard fork configuration
4242
ALTAIR_FORK_EPOCH=0
4343
BELLATRIX_FORK_EPOCH=0
44-
CAPELLA_FORK_EPOCH=1
45-
DENEB_FORK_EPOCH=18446744073709551615
44+
CAPELLA_FORK_EPOCH=0
45+
DENEB_FORK_EPOCH=0
4646

4747
TTD=0
4848

@@ -62,4 +62,5 @@ PROPOSER_SCORE_BOOST=70
6262
BN_ARGS=""
6363

6464
# Enable doppelganger detection
65-
VC_ARGS=" --enable-doppelganger-protection "
65+
VC_ARGS=" --enable-doppelganger-protection "
66+

0 commit comments

Comments
 (0)