mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Update Simulator tests (#5520)
* Rewrite Simulator * Add fallback simulator * Try Sean's test fix * More fixes * Cleanup * Merge branch 'unstable' into update-simulator * Update cli.rs * Add sync sim to basic sim * Formatting * Add fixes and new block production check * Merge branch 'unstable' of https://github.com/sigp/lighthouse into update-simulator * fix compile
This commit is contained in:
@@ -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(),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()?;
|
||||
@@ -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)
|
||||
@@ -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()))
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user