Skip to content

Commit

Permalink
Merge of #5520
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Apr 22, 2024
2 parents 5a9e973 + 42ef9f0 commit 6fb74d9
Show file tree
Hide file tree
Showing 18 changed files with 928 additions and 1,020 deletions.
58 changes: 10 additions & 48 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ jobs:
run: docker build --build-arg FEATURES=portable -t lighthouse:local .
- name: Test the built image
run: docker run -t lighthouse:local lighthouse --version
eth1-simulator-ubuntu:
name: eth1-simulator-ubuntu
basic-simulator-ubuntu:
name: basic-simulator-ubuntu
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -235,42 +235,10 @@ jobs:
with:
channel: stable
cache-target: release
- name: Install Foundry (anvil)
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly-ca67d15f4abd46394b324c50e21e66f306a1162d
- name: Run the beacon chain sim that starts from an eth1 contract
run: cargo run --release --bin simulator eth1-sim
merge-transition-ubuntu:
name: merge-transition-ubuntu
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get latest version of stable Rust
uses: moonrepo/setup-rust@v1
with:
channel: stable
cache-target: release
- name: Install Foundry (anvil)
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly-ca67d15f4abd46394b324c50e21e66f306a1162d
- name: Run the beacon chain sim and go through the merge transition
run: cargo run --release --bin simulator eth1-sim --post-merge
no-eth1-simulator-ubuntu:
name: no-eth1-simulator-ubuntu
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get latest version of stable Rust
uses: moonrepo/setup-rust@v1
with:
channel: stable
cache-target: release
- name: Run the beacon chain sim without an eth1 connection
run: cargo run --release --bin simulator no-eth1-sim
syncing-simulator-ubuntu:
name: syncing-simulator-ubuntu
- name: Run a basic beacon chain sim that starts from Bellatrix
run: cargo run --release --bin simulator basic-sim
fallback-simulator-ubuntu:
name: fallback-simulator-ubuntu
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -279,12 +247,8 @@ jobs:
with:
channel: stable
cache-target: release
- name: Install Foundry (anvil)
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly-ca67d15f4abd46394b324c50e21e66f306a1162d
- name: Run the syncing simulator
run: cargo run --release --bin simulator syncing-sim
- name: Run a beacon chain sim which tests VC fallback behaviour
run: cargo run --release --bin simulator fallback-sim
doppelganger-protection-test:
name: doppelganger-protection-test
runs-on: ${{ github.repository == 'sigp/lighthouse' && fromJson('["self-hosted", "linux", "CI", "small"]') || 'ubuntu-latest' }}
Expand Down Expand Up @@ -442,10 +406,8 @@ jobs:
'state-transition-vectors-ubuntu',
'ef-tests-ubuntu',
'dockerfile-ubuntu',
'eth1-simulator-ubuntu',
'merge-transition-ubuntu',
'no-eth1-simulator-ubuntu',
'syncing-simulator-ubuntu',
'basic-simulator-ubuntu',
'fallback-simulator-ubuntu',
'doppelganger-protection-test',
'execution-engine-integration-ubuntu',
'check-code',
Expand Down
6 changes: 5 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions beacon_node/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ execution_layer = { workspace = true }
beacon_processor = { workspace = true }
num_cpus = { workspace = true }
ethereum_ssz = { workspace = true }
tree_hash = { workspace = true }
16 changes: 16 additions & 0 deletions beacon_node/client/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use eth2::{
types::{BlockId, StateId},
BeaconNodeHttpClient, Error as ApiError, Timeouts,
};
use execution_layer::test_utils::generate_genesis_header;
use execution_layer::ExecutionLayer;
use futures::channel::mpsc::Receiver;
use genesis::{interop_genesis_state, Eth1GenesisService, DEFAULT_ETH1_BLOCK_HASH};
Expand Down Expand Up @@ -267,6 +268,21 @@ where
)?;
builder.genesis_state(genesis_state).map(|v| (v, None))?
}
ClientGenesis::InteropMerge {
validator_count,
genesis_time,
} => {
let execution_payload_header = generate_genesis_header(&spec, true);
let keypairs = generate_deterministic_keypairs(validator_count);
let genesis_state = interop_genesis_state(
&keypairs,
genesis_time,
Hash256::from_slice(DEFAULT_ETH1_BLOCK_HASH),
execution_payload_header,
&spec,
)?;
builder.genesis_state(genesis_state).map(|v| (v, None))?
}
ClientGenesis::GenesisState => {
info!(
context.log(),
Expand Down
5 changes: 5 additions & 0 deletions beacon_node/client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ pub enum ClientGenesis {
validator_count: usize,
genesis_time: u64,
},
// Creates a genesis state similar to the 2019 Canada specs, but starting post-Merge.
InteropMerge {
validator_count: usize,
genesis_time: u64,
},
/// Reads the genesis state and other persisted data from the `Store`.
FromStore,
/// Connects to an eth1 node and waits until it can create the genesis state from the deposit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,14 @@ impl<E: EthSpec> Block<E> {
pub fn as_execution_block_with_tx(&self) -> Option<ExecutionBlockWithTransactions<E>> {
match self {
Block::PoS(payload) => Some(payload.clone().try_into().unwrap()),
Block::PoW(_) => None,
Block::PoW(block) => Some(
ExecutionPayload::Merge(ExecutionPayloadMerge {
block_hash: block.block_hash,
..Default::default()
})
.try_into()
.unwrap(),
),
}
}
}
Expand Down Expand Up @@ -190,6 +197,19 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
.map(|block| block.as_execution_block(self.terminal_total_difficulty))
}

pub fn genesis_block(&self) -> Option<Block<E>> {
if let Some(genesis_block_hash) = self.block_hashes.get(&0) {
self.blocks.get(genesis_block_hash.first()?).cloned()
} else {
None
}
}

pub fn genesis_execution_block(&self) -> Option<ExecutionBlock> {
self.genesis_block()
.map(|block| block.as_execution_block(self.terminal_total_difficulty))
}

pub fn block_by_number(&self, number: u64) -> Option<Block<E>> {
// Get the latest canonical head block
let mut latest_block = self.latest_block()?;
Expand Down Expand Up @@ -502,13 +522,6 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
let id = match payload_attributes {
None => None,
Some(attributes) => {
if !self.blocks.iter().any(|(_, block)| {
block.block_hash() == self.terminal_block_hash
|| block.block_number() == self.terminal_block_number
}) {
return Err("refusing to create payload id before terminal block".to_string());
}

let parent = self
.blocks
.get(&head_block_hash)
Expand Down Expand Up @@ -766,12 +779,14 @@ pub fn generate_genesis_header<E: EthSpec>(
generate_genesis_block(spec.terminal_total_difficulty, DEFAULT_TERMINAL_BLOCK)
.ok()
.map(|block| block.block_hash);
let empty_transactions_root = Transactions::<E>::empty().tree_hash_root();
match genesis_fork {
ForkName::Base | ForkName::Altair => None,
ForkName::Merge => {
if post_transition_merge {
let mut header = ExecutionPayloadHeader::Merge(<_>::default());
*header.block_hash_mut() = genesis_block_hash.unwrap_or_default();
*header.transactions_root_mut() = empty_transactions_root;
Some(header)
} else {
Some(ExecutionPayloadHeader::<E>::Merge(<_>::default()))
Expand All @@ -780,16 +795,19 @@ pub fn generate_genesis_header<E: EthSpec>(
ForkName::Capella => {
let mut header = ExecutionPayloadHeader::Capella(<_>::default());
*header.block_hash_mut() = genesis_block_hash.unwrap_or_default();
*header.transactions_root_mut() = empty_transactions_root;
Some(header)
}
ForkName::Deneb => {
let mut header = ExecutionPayloadHeader::Deneb(<_>::default());
*header.block_hash_mut() = genesis_block_hash.unwrap_or_default();
*header.transactions_root_mut() = empty_transactions_root;
Some(header)
}
ForkName::Electra => {
let mut header = ExecutionPayloadHeader::Electra(<_>::default());
*header.block_hash_mut() = genesis_block_hash.unwrap_or_default();
*header.transactions_root_mut() = empty_transactions_root;
Some(header)
}
}
Expand Down
6 changes: 6 additions & 0 deletions beacon_node/execution_layer/src/test_utils/handle_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ pub async fn handle_rpc<E: EthSpec>(
.latest_execution_block(),
)
.unwrap()),
"0x0" => Ok(serde_json::to_value(
ctx.execution_block_generator
.read()
.genesis_execution_block(),
)
.unwrap()),
other => Err((
format!("The tag {} is not supported", other),
BAD_PARAMS_ERROR_CODE,
Expand Down
1 change: 1 addition & 0 deletions beacon_node/execution_layer/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ mod mock_builder;
mod mock_execution_layer;

/// Configuration for the MockExecutionLayer.
#[derive(Clone)]
pub struct MockExecutionConfig {
pub server_config: Config,
pub jwt_key: JwtKey,
Expand Down
5 changes: 4 additions & 1 deletion testing/simulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ types = { workspace = true }
parking_lot = { workspace = true }
futures = { workspace = true }
tokio = { workspace = true }
eth1_test_rig = { workspace = true }
env_logger = { workspace = true }
clap = { workspace = true }
rayon = { workspace = true }
sensitive_url = { path = "../../common/sensitive_url" }
ssz_types = { workspace = true }
ethereum-types = { workspace = true }
eth2_network_config = { workspace = true }
serde_json = { workspace = true }
Loading

0 comments on commit 6fb74d9

Please sign in to comment.