Improve single-node testnet support and Arc NetworkConfig/ChainSpec (#6396)

* Arc ChainSpec and NetworkConfig

* Fix release tests

* Fix lint

* Merge remote-tracking branch 'origin/unstable' into single-node-testnet
This commit is contained in:
Michael Sproul
2024-09-24 10:16:18 +10:00
committed by GitHub
parent d84df5799c
commit 1447eeb40b
66 changed files with 340 additions and 250 deletions

View File

@@ -43,7 +43,7 @@ impl Eth1GenesisService {
/// Creates a new service. Does not attempt to connect to the Eth1 node.
///
/// Modifies the given `config` to make it more suitable to the task of listening to genesis.
pub fn new(config: Eth1Config, log: Logger, spec: ChainSpec) -> Result<Self, String> {
pub fn new(config: Eth1Config, log: Logger, spec: Arc<ChainSpec>) -> Result<Self, String> {
let config = Eth1Config {
// Truncating the block cache makes searching for genesis more
// complicated.
@@ -100,9 +100,9 @@ impl Eth1GenesisService {
pub async fn wait_for_genesis_state<E: EthSpec>(
&self,
update_interval: Duration,
spec: ChainSpec,
) -> Result<BeaconState<E>, String> {
let eth1_service = &self.eth1_service;
let spec = eth1_service.chain_spec();
let log = &eth1_service.log;
let mut sync_blocks = false;
@@ -180,13 +180,13 @@ impl Eth1GenesisService {
// Scan the new eth1 blocks, searching for genesis.
if let Some(genesis_state) =
self.scan_new_blocks::<E>(&mut highest_processed_block, &spec)?
self.scan_new_blocks::<E>(&mut highest_processed_block, spec)?
{
info!(
log,
"Genesis ceremony complete";
"genesis_validators" => genesis_state
.get_active_validator_indices(E::genesis_epoch(), &spec)
.get_active_validator_indices(E::genesis_epoch(), spec)
.map_err(|e| format!("Genesis validators error: {:?}", e))?
.len(),
"genesis_time" => genesis_state.genesis_time(),
@@ -203,7 +203,7 @@ impl Eth1GenesisService {
let latest_timestamp = self.stats.latest_timestamp.load(Ordering::Relaxed);
// Perform some logging.
if timestamp_can_trigger_genesis(latest_timestamp, &spec)? {
if timestamp_can_trigger_genesis(latest_timestamp, spec)? {
// Indicate that we are awaiting adequate active validators.
if (active_validator_count as u64) < spec.min_genesis_active_validator_count {
info!(

View File

@@ -5,6 +5,7 @@ use eth1_test_rig::{AnvilEth1Instance, DelayThenDeposit, Middleware};
use genesis::{Eth1Config, Eth1GenesisService};
use sensitive_url::SensitiveUrl;
use state_processing::is_valid_genesis_state;
use std::sync::Arc;
use std::time::Duration;
use types::{
test_utils::generate_deterministic_keypair, FixedBytesExtended, Hash256, MinimalEthSpec,
@@ -24,7 +25,10 @@ pub fn new_env() -> Environment<MinimalEthSpec> {
fn basic() {
let env = new_env();
let log = env.core_context().log().clone();
let mut spec = env.eth2_config().spec.clone();
let mut spec = (*env.eth2_config().spec).clone();
spec.min_genesis_time = 0;
spec.min_genesis_active_validator_count = 8;
let spec = Arc::new(spec);
env.runtime().block_on(async {
let eth1 = AnvilEth1Instance::new(DEFAULT_CHAIN_ID.into())
@@ -60,9 +64,6 @@ fn basic() {
// you're experiencing failures, try increasing the update_interval.
let update_interval = Duration::from_millis(500);
spec.min_genesis_time = 0;
spec.min_genesis_active_validator_count = 8;
let deposits = (0..spec.min_genesis_active_validator_count + 2)
.map(|i| {
deposit_contract.deposit_helper::<MinimalEthSpec>(
@@ -79,8 +80,7 @@ fn basic() {
let deposit_future = deposit_contract.deposit_multiple(deposits);
let wait_future =
service.wait_for_genesis_state::<MinimalEthSpec>(update_interval, spec.clone());
let wait_future = service.wait_for_genesis_state::<MinimalEthSpec>(update_interval);
let state = futures::try_join!(deposit_future, wait_future)
.map(|(_, state)| state)