From 3fcc517993a4688c5c482a38636fb016b671ee5d Mon Sep 17 00:00:00 2001 From: blacktemplar Date: Wed, 16 Dec 2020 05:37:38 +0000 Subject: [PATCH] Fix Syncing Simulator (#2049) ## Issue Addressed NA ## Proposed Changes Fixes problems with slot times below 1 second which got revealed by running the syncing simulator with the default speedup time. --- .github/workflows/test-suite.yml | 10 ++++++++++ .../behaviour/gossipsub_scoring_parameters.rs | 2 +- testing/simulator/src/eth1_sim.rs | 3 +++ testing/simulator/src/no_eth1_sim.rs | 3 +++ testing/simulator/src/sync_sim.rs | 19 ++++++++++++++----- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index 54ae6e3c7..1862f97f1 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -146,6 +146,16 @@ jobs: run: sudo npm install -g ganache-cli - 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 + runs-on: ubuntu-latest + needs: cargo-fmt + steps: + - uses: actions/checkout@v1 + - name: Install ganache-cli + run: sudo npm install -g ganache-cli + - name: Run the syncing simulator + run: cargo run --release --bin simulator syncing-sim check-benchmarks: name: check-benchmarks runs-on: ubuntu-latest diff --git a/beacon_node/eth2_libp2p/src/behaviour/gossipsub_scoring_parameters.rs b/beacon_node/eth2_libp2p/src/behaviour/gossipsub_scoring_parameters.rs index ea4527033..fe516cab5 100644 --- a/beacon_node/eth2_libp2p/src/behaviour/gossipsub_scoring_parameters.rs +++ b/beacon_node/eth2_libp2p/src/behaviour/gossipsub_scoring_parameters.rs @@ -56,7 +56,7 @@ impl PeerScoreSettings { epoch: slot * TSpec::slots_per_epoch() as u32, beacon_attestation_subnet_weight, max_positive_score, - decay_interval: slot, + decay_interval: max(Duration::from_secs(1), slot), decay_to_zero: 0.01, mesh_n: gs_config.mesh_n(), max_committees_per_slot: chain_spec.max_committees_per_slot, diff --git a/testing/simulator/src/eth1_sim.rs b/testing/simulator/src/eth1_sim.rs index 92eb52c17..acabc11d2 100644 --- a/testing/simulator/src/eth1_sim.rs +++ b/testing/simulator/src/eth1_sim.rs @@ -9,6 +9,7 @@ use node_test_rig::{ ClientGenesis, ValidatorFiles, }; use rayon::prelude::*; +use std::cmp::max; use std::net::{IpAddr, Ipv4Addr}; use std::time::Duration; use types::{Epoch, EthSpec, MainnetEthSpec}; @@ -57,6 +58,8 @@ pub fn run_eth1_sim(matches: &ArgMatches) -> Result<(), String> { let total_validator_count = validators_per_node * node_count; spec.milliseconds_per_slot /= speed_up_factor; + //currently lighthouse only supports slot lengths that are multiples of seconds + spec.milliseconds_per_slot = max(1000, spec.milliseconds_per_slot / 1000 * 1000); spec.eth1_follow_distance = 16; spec.genesis_delay = eth1_block_time.as_secs() * spec.eth1_follow_distance * 2; spec.min_genesis_time = 0; diff --git a/testing/simulator/src/no_eth1_sim.rs b/testing/simulator/src/no_eth1_sim.rs index cccf413ed..56296ed8d 100644 --- a/testing/simulator/src/no_eth1_sim.rs +++ b/testing/simulator/src/no_eth1_sim.rs @@ -6,6 +6,7 @@ use node_test_rig::{ ClientGenesis, ValidatorFiles, }; use rayon::prelude::*; +use std::cmp::max; use std::net::{IpAddr, Ipv4Addr}; use std::time::{Duration, SystemTime, UNIX_EPOCH}; use tokio::time::{sleep_until, Instant}; @@ -55,6 +56,8 @@ pub fn run_no_eth1_sim(matches: &ArgMatches) -> Result<(), String> { let total_validator_count = validators_per_node * node_count; spec.milliseconds_per_slot /= speed_up_factor; + //currently lighthouse only supports slot lengths that are multiples of seconds + spec.milliseconds_per_slot = max(1000, spec.milliseconds_per_slot / 1000 * 1000); spec.eth1_follow_distance = 16; spec.genesis_delay = eth1_block_time.as_secs() * spec.eth1_follow_distance * 2; spec.min_genesis_time = 0; diff --git a/testing/simulator/src/sync_sim.rs b/testing/simulator/src/sync_sim.rs index 47272f626..22ac0432d 100644 --- a/testing/simulator/src/sync_sim.rs +++ b/testing/simulator/src/sync_sim.rs @@ -2,11 +2,11 @@ use crate::checks::{epoch_delay, verify_all_finalized_at}; use crate::local_network::LocalNetwork; use clap::ArgMatches; use futures::prelude::*; -use node_test_rig::ClientConfig; use node_test_rig::{ - environment::EnvironmentBuilder, testing_client_config, ClientGenesis, ValidatorConfig, - ValidatorFiles, + environment::EnvironmentBuilder, testing_client_config, ClientGenesis, ValidatorFiles, }; +use node_test_rig::{testing_validator_config, ClientConfig}; +use std::cmp::max; use std::net::{IpAddr, Ipv4Addr}; use std::time::{Duration, SystemTime, UNIX_EPOCH}; use types::{Epoch, EthSpec}; @@ -54,6 +54,8 @@ fn syncing_sim( let eth1_block_time = Duration::from_millis(15_000 / speed_up_factor); spec.milliseconds_per_slot /= speed_up_factor; + //currently lighthouse only supports slot lengths that are multiples of seconds + spec.milliseconds_per_slot = max(1000, spec.milliseconds_per_slot / 1000 * 1000); spec.eth1_follow_distance = 16; spec.genesis_delay = eth1_block_time.as_secs() * spec.eth1_follow_distance * 2; spec.min_genesis_time = 0; @@ -92,7 +94,7 @@ fn syncing_sim( * Add a validator client which handles all validators from the genesis state. */ network - .add_validator_client(ValidatorConfig::default(), 0, validator_files) + .add_validator_client(testing_validator_config(), 0, validator_files) .await?; // Check all syncing strategies one after other. @@ -129,7 +131,14 @@ fn syncing_sim( Ok::<(), String>(()) }; - env.runtime().block_on(main_future) + env.runtime() + .block_on(tokio_compat_02::FutureExt::compat(main_future)) + .unwrap(); + + env.fire_signal(); + env.shutdown_on_idle(); + + Ok(()) } pub async fn pick_strategy(