Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions beacon_node/client/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ 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,
DEFAULT_EXECUTION_PAYLOAD_TRANSACTIONS_ROOT,
};
use genesis::{interop_genesis_state, Eth1GenesisService, DEFAULT_ETH1_BLOCK_HASH};
use lighthouse_network::{prometheus_client::registry::Registry, NetworkGlobals};
use monitoring_api::{MonitoringHttpClient, ProcessType};
use network::{NetworkConfig, NetworkSenders, NetworkService};
Expand All @@ -41,15 +39,14 @@ use slog::{debug, info, warn, Logger};
use ssz::Decode;
use std::net::TcpListener;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;
use std::time::{SystemTime, UNIX_EPOCH};
use timer::spawn_timer;
use tokio::sync::oneshot;
use types::{
test_utils::generate_deterministic_keypairs, BeaconState, BlobSidecarList, ChainSpec, EthSpec,
ExecutionBlockHash, ExecutionPayloadHeaderMerge, Hash256, SignedBeaconBlock,
ExecutionBlockHash, Hash256, SignedBeaconBlock,
};

/// Interval between polling the eth1 node for genesis information.
Expand Down Expand Up @@ -275,19 +272,13 @@ where
validator_count,
genesis_time,
} => {
let execution_payload_header = ExecutionPayloadHeaderMerge {
transactions_root: Hash256::from_str(
DEFAULT_EXECUTION_PAYLOAD_TRANSACTIONS_ROOT,
)
.unwrap(),
..Default::default()
};
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),
Some(execution_payload_header.into()),
execution_payload_header,
&spec,
)?;
builder.genesis_state(genesis_state).map(|v| (v, None))?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use serde::{Deserialize, Serialize};
use ssz::Decode;
use ssz_types::VariableList;
use std::collections::HashMap;
use std::str::FromStr;
use std::sync::Arc;
use tree_hash::TreeHash;
use tree_hash_derive::TreeHash;
Expand All @@ -27,6 +28,8 @@ use types::{
};

use super::DEFAULT_TERMINAL_BLOCK;
pub const DEFAULT_EXECUTION_PAYLOAD_TRANSACTIONS_ROOT: &str =
"0x7ffe241ea60187fdb0187bfa22de35d1f9bed7ab061d9401fd47e34a54fbede1";

const TEST_BLOB_BUNDLE: &[u8] = include_bytes!("fixtures/mainnet/test_blobs_bundle.ssz");

Expand Down Expand Up @@ -91,7 +94,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 @@ -176,23 +186,11 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
rng: make_rng(),
};

//gen.insert_pow_block(0).unwrap();
// Merge from genesis
gen.insert_genesis_pos_block().unwrap();
gen.insert_pow_block(0).unwrap();

gen
}

pub fn insert_genesis_pos_block(&mut self) -> Result<(), String> {
// Insert block into block tree.
self.insert_block(Block::PoS(ExecutionPayloadMerge::default().into()))?;

// Set block has head.
self.head_block = Some(Block::PoS(ExecutionPayloadMerge::default().into()));

Ok(())
}

pub fn latest_block(&self) -> Option<Block<E>> {
self.head_block.clone()
}
Expand Down Expand Up @@ -797,6 +795,8 @@ pub fn generate_genesis_header<E: EthSpec>(
if post_transition_merge {
let mut header = ExecutionPayloadHeader::Merge(<_>::default());
*header.block_hash_mut() = genesis_block_hash.unwrap_or_default();
*header.transactions_root_mut() =
Hash256::from_str(DEFAULT_EXECUTION_PAYLOAD_TRANSACTIONS_ROOT).unwrap();
Some(header)
} else {
Some(ExecutionPayloadHeader::<E>::Merge(<_>::default()))
Expand All @@ -805,16 +805,22 @@ 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() =
Hash256::from_str(DEFAULT_EXECUTION_PAYLOAD_TRANSACTIONS_ROOT).unwrap();
Some(header)
}
ForkName::Deneb => {
let mut header = ExecutionPayloadHeader::Deneb(<_>::default());
*header.block_hash_mut() = genesis_block_hash.unwrap_or_default();
*header.transactions_root_mut() =
Hash256::from_str(DEFAULT_EXECUTION_PAYLOAD_TRANSACTIONS_ROOT).unwrap();
Some(header)
}
ForkName::Electra => {
let mut header = ExecutionPayloadHeader::Electra(<_>::default());
*header.block_hash_mut() = genesis_block_hash.unwrap_or_default();
*header.transactions_root_mut() =
Hash256::from_str(DEFAULT_EXECUTION_PAYLOAD_TRANSACTIONS_ROOT).unwrap();
Some(header)
}
}
Expand Down
3 changes: 0 additions & 3 deletions beacon_node/genesis/src/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ use types::{

pub const DEFAULT_ETH1_BLOCK_HASH: &[u8] = &[0x42; 32];

pub const DEFAULT_EXECUTION_PAYLOAD_TRANSACTIONS_ROOT: &str =
"0x7ffe241ea60187fdb0187bfa22de35d1f9bed7ab061d9401fd47e34a54fbede1";

pub fn bls_withdrawal_credentials(pubkey: &PublicKey, spec: &ChainSpec) -> Hash256 {
let mut credentials = hash(&pubkey.as_ssz_bytes());
credentials[0] = spec.bls_withdrawal_prefix_byte;
Expand Down
1 change: 0 additions & 1 deletion beacon_node/genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ pub use eth1_genesis_service::{Eth1GenesisService, Statistics};
pub use interop::{
bls_withdrawal_credentials, interop_genesis_state, interop_genesis_state_with_eth1,
interop_genesis_state_with_withdrawal_credentials, DEFAULT_ETH1_BLOCK_HASH,
DEFAULT_EXECUTION_PAYLOAD_TRANSACTIONS_ROOT,
};
pub use types::test_utils::generate_deterministic_keypairs;