mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-02 16:21:42 +00:00
Reduce number of blobs used in tests to speed up CI (#8194)
`beacon-chain-tests` is now regularly taking 1h+ on CI since Fulu fork was added.
This PR attemtpts to reduce the test time by bringing down the number of blobs generated in tests - instead of generating 0..max_blobs, the generator now generates 0..1 blobs by default, and this can be modified by setting `harness.execution_block_generator.set_min_blob_count(n)`.
Note: The blobs are pre-generated and doesn't require too much CPU to generate however processing a larger number of them on the beacon chain does take a lot of time.
This PR also include a few other small improvements
- Our slowest test (`chain_segment_varying_chunk_size`) runs 3x faster in Fulu just by reusing chain segments
- Avoid re-running fork specific tests on all forks
- Fix a bunch of tests that depends on the harness's existing random blob generation, which is fragile
beacon chain test time on test machine is **~2x** faster:
### `unstable`
```
Summary [ 751.586s] 291 tests run: 291 passed (13 slow), 0 skipped
```
### this branch
```
Summary [ 373.792s] 291 tests run: 291 passed (2 slow), 0 skipped
```
The next set of tests to optimise is the ones that use [`get_chain_segment`](77a9af96de/beacon_node/beacon_chain/tests/block_verification.rs (L45)), as it by default build 320 blocks with supernode - an easy optimisation would be to build these blocks with cgc = 8 for tests that only require fullnodes.
Co-Authored-By: Jimmy Chen <jchen.tc@gmail.com>
Co-Authored-By: Jimmy Chen <jimmy@sigmaprime.io>
This commit is contained in:
@@ -1479,8 +1479,7 @@ mod test {
|
||||
|
||||
impl Tester {
|
||||
pub fn new(with_auth: bool) -> Self {
|
||||
let spec = Arc::new(MainnetEthSpec::default_spec());
|
||||
let server = MockServer::unit_testing(spec);
|
||||
let server = MockServer::unit_testing();
|
||||
|
||||
let rpc_url = SensitiveUrl::parse(&server.url()).unwrap();
|
||||
let echo_url = SensitiveUrl::parse(&format!("{}/echo", server.url())).unwrap();
|
||||
|
||||
@@ -13,6 +13,7 @@ use rand::{Rng, SeedableRng, rngs::StdRng};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz::Decode;
|
||||
use ssz_types::VariableList;
|
||||
use std::cmp::max;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use tree_hash::TreeHash;
|
||||
@@ -157,7 +158,6 @@ pub struct ExecutionBlockGenerator<E: EthSpec> {
|
||||
pub blobs_bundles: HashMap<PayloadId, BlobsBundle<E>>,
|
||||
pub kzg: Option<Arc<Kzg>>,
|
||||
rng: Arc<Mutex<StdRng>>,
|
||||
spec: Arc<ChainSpec>,
|
||||
}
|
||||
|
||||
fn make_rng() -> Arc<Mutex<StdRng>> {
|
||||
@@ -177,7 +177,6 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
|
||||
prague_time: Option<u64>,
|
||||
osaka_time: Option<u64>,
|
||||
amsterdam_time: Option<u64>,
|
||||
spec: Arc<ChainSpec>,
|
||||
kzg: Option<Arc<Kzg>>,
|
||||
) -> Self {
|
||||
let mut generator = Self {
|
||||
@@ -200,7 +199,6 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
|
||||
blobs_bundles: <_>::default(),
|
||||
kzg,
|
||||
rng: make_rng(),
|
||||
spec,
|
||||
};
|
||||
|
||||
generator.insert_pow_block(0).unwrap();
|
||||
@@ -732,11 +730,10 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
|
||||
|
||||
let fork_name = execution_payload.fork_name();
|
||||
if fork_name.deneb_enabled() {
|
||||
// get random number between 0 and Max Blobs
|
||||
// get random number between 0 and 1 blobs by default
|
||||
// For tests that need higher blob count, consider adding a `set_max_blob_count` method
|
||||
let mut rng = self.rng.lock();
|
||||
// TODO(EIP-7892): see FIXME below
|
||||
// FIXME: this will break with BPO forks. This function needs to calculate the epoch based on block timestamp..
|
||||
let max_blobs = self.spec.max_blobs_per_block_within_fork(fork_name) as usize;
|
||||
let max_blobs = max(1, self.min_blobs_count);
|
||||
let num_blobs = rng.random_range(self.min_blobs_count..=max_blobs);
|
||||
let (bundle, transactions) = generate_blobs(num_blobs, fork_name)?;
|
||||
for tx in Vec::from(transactions) {
|
||||
@@ -978,7 +975,6 @@ mod test {
|
||||
const TERMINAL_DIFFICULTY: u64 = 10;
|
||||
const TERMINAL_BLOCK: u64 = 10;
|
||||
const DIFFICULTY_INCREMENT: u64 = 1;
|
||||
let spec = Arc::new(MainnetEthSpec::default_spec());
|
||||
|
||||
let mut generator: ExecutionBlockGenerator<MainnetEthSpec> = ExecutionBlockGenerator::new(
|
||||
Uint256::from(TERMINAL_DIFFICULTY),
|
||||
@@ -989,7 +985,6 @@ mod test {
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
spec,
|
||||
None,
|
||||
);
|
||||
|
||||
|
||||
@@ -63,7 +63,6 @@ impl<E: EthSpec> MockExecutionLayer<E> {
|
||||
prague_time,
|
||||
osaka_time,
|
||||
amsterdam_time,
|
||||
spec.clone(),
|
||||
kzg,
|
||||
);
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
|
||||
use std::sync::{Arc, LazyLock};
|
||||
use tokio::{runtime, sync::oneshot};
|
||||
use tracing::info;
|
||||
use types::{ChainSpec, EthSpec, ExecutionBlockHash, Uint256};
|
||||
use types::{EthSpec, ExecutionBlockHash, Uint256};
|
||||
use warp::{Filter, Rejection, http::StatusCode};
|
||||
|
||||
use crate::EngineCapabilities;
|
||||
@@ -114,7 +114,7 @@ pub struct MockServer<E: EthSpec> {
|
||||
}
|
||||
|
||||
impl<E: EthSpec> MockServer<E> {
|
||||
pub fn unit_testing(chain_spec: Arc<ChainSpec>) -> Self {
|
||||
pub fn unit_testing() -> Self {
|
||||
Self::new(
|
||||
&runtime::Handle::current(),
|
||||
JwtKey::from_slice(&DEFAULT_JWT_SECRET).unwrap(),
|
||||
@@ -126,7 +126,6 @@ impl<E: EthSpec> MockServer<E> {
|
||||
None, // FIXME(electra): should this be the default?
|
||||
None, // FIXME(fulu): should this be the default?
|
||||
None, // FIXME(gloas): should this be the default?
|
||||
chain_spec,
|
||||
None,
|
||||
)
|
||||
}
|
||||
@@ -134,7 +133,6 @@ impl<E: EthSpec> MockServer<E> {
|
||||
pub fn new_with_config(
|
||||
handle: &runtime::Handle,
|
||||
config: MockExecutionConfig,
|
||||
spec: Arc<ChainSpec>,
|
||||
kzg: Option<Arc<Kzg>>,
|
||||
) -> Self {
|
||||
create_test_tracing_subscriber();
|
||||
@@ -161,7 +159,6 @@ impl<E: EthSpec> MockServer<E> {
|
||||
prague_time,
|
||||
osaka_time,
|
||||
amsterdam_time,
|
||||
spec,
|
||||
kzg,
|
||||
);
|
||||
|
||||
@@ -226,7 +223,6 @@ impl<E: EthSpec> MockServer<E> {
|
||||
prague_time: Option<u64>,
|
||||
osaka_time: Option<u64>,
|
||||
amsterdam_time: Option<u64>,
|
||||
spec: Arc<ChainSpec>,
|
||||
kzg: Option<Arc<Kzg>>,
|
||||
) -> Self {
|
||||
Self::new_with_config(
|
||||
@@ -243,7 +239,6 @@ impl<E: EthSpec> MockServer<E> {
|
||||
osaka_time,
|
||||
amsterdam_time,
|
||||
},
|
||||
spec,
|
||||
kzg,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user