mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 01:05:47 +00:00
Reduce slow test runtimes to under 60s (#9012)
Co-Authored-By: Mark Liu <mark@prove.com.au> Co-Authored-By: Michael Sproul <michaelsproul@users.noreply.github.com>
This commit is contained in:
@@ -3087,6 +3087,9 @@ mod tests {
|
|||||||
const MAX_TEST_PEERS: usize = 300;
|
const MAX_TEST_PEERS: usize = 300;
|
||||||
|
|
||||||
proptest! {
|
proptest! {
|
||||||
|
// 64 cases (down from default 256) keeps this test under 10s while
|
||||||
|
// still providing good random coverage of the pruning logic.
|
||||||
|
#![proptest_config(ProptestConfig::with_cases(64))]
|
||||||
#[test]
|
#[test]
|
||||||
fn prune_excess_peers(peer_conditions in proptest::collection::vec(peer_condition_strategy(), DEFAULT_TARGET_PEERS..=MAX_TEST_PEERS)) {
|
fn prune_excess_peers(peer_conditions in proptest::collection::vec(peer_condition_strategy(), DEFAULT_TARGET_PEERS..=MAX_TEST_PEERS)) {
|
||||||
let target_peer_count = DEFAULT_TARGET_PEERS;
|
let target_peer_count = DEFAULT_TARGET_PEERS;
|
||||||
|
|||||||
@@ -1088,9 +1088,11 @@ mod tests {
|
|||||||
let mut block: BeaconBlockBellatrix<_, FullPayload<Spec>> =
|
let mut block: BeaconBlockBellatrix<_, FullPayload<Spec>> =
|
||||||
BeaconBlockBellatrix::empty(spec);
|
BeaconBlockBellatrix::empty(spec);
|
||||||
|
|
||||||
|
// 11,000 × 1KB ≈ 11MB, just above the 10MB max_payload_size.
|
||||||
|
// Previously used 100,000 txs (~100MB) which made this test take >60s.
|
||||||
let tx = VariableList::try_from(vec![0; 1024]).unwrap();
|
let tx = VariableList::try_from(vec![0; 1024]).unwrap();
|
||||||
let txs =
|
let txs =
|
||||||
VariableList::try_from(std::iter::repeat_n(tx, 100000).collect::<Vec<_>>()).unwrap();
|
VariableList::try_from(std::iter::repeat_n(tx, 11000).collect::<Vec<_>>()).unwrap();
|
||||||
|
|
||||||
block.body.execution_payload.execution_payload.transactions = txs;
|
block.body.execution_payload.execution_payload.transactions = txs;
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,10 @@ fn bellatrix_block_small(spec: &ChainSpec) -> BeaconBlock<E> {
|
|||||||
/// Hence, we generate a bellatrix block just greater than `MAX_RPC_SIZE` to test rejection on the rpc layer.
|
/// Hence, we generate a bellatrix block just greater than `MAX_RPC_SIZE` to test rejection on the rpc layer.
|
||||||
fn bellatrix_block_large(spec: &ChainSpec) -> BeaconBlock<E> {
|
fn bellatrix_block_large(spec: &ChainSpec) -> BeaconBlock<E> {
|
||||||
let mut block = BeaconBlockBellatrix::<E>::empty(spec);
|
let mut block = BeaconBlockBellatrix::<E>::empty(spec);
|
||||||
|
// 11,000 × 1KB ≈ 11MB, just above the 10MB max_payload_size.
|
||||||
|
// Previously used 100,000 txs (~100MB) which caused hangs and timeouts.
|
||||||
let tx = VariableList::try_from(vec![0; 1024]).unwrap();
|
let tx = VariableList::try_from(vec![0; 1024]).unwrap();
|
||||||
let txs = VariableList::try_from(std::iter::repeat_n(tx, 100000).collect::<Vec<_>>()).unwrap();
|
let txs = VariableList::try_from(std::iter::repeat_n(tx, 11000).collect::<Vec<_>>()).unwrap();
|
||||||
|
|
||||||
block.body.execution_payload.execution_payload.transactions = txs;
|
block.body.execution_payload.execution_payload.transactions = txs;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use account_utils::write_file_via_temporary;
|
use account_utils::write_file_via_temporary;
|
||||||
use bls::{Keypair, PublicKey};
|
use bls::{Keypair, PublicKey};
|
||||||
use eth2_keystore::json_keystore::{
|
use eth2_keystore::json_keystore::{
|
||||||
Aes128Ctr, ChecksumModule, Cipher, CipherModule, Crypto, EmptyMap, EmptyString, KdfModule,
|
Aes128Ctr, ChecksumModule, Cipher, CipherModule, Crypto, EmptyMap, EmptyString, Kdf, KdfModule,
|
||||||
Sha256Checksum,
|
Sha256Checksum,
|
||||||
};
|
};
|
||||||
use eth2_keystore::{
|
use eth2_keystore::{
|
||||||
@@ -65,10 +65,14 @@ impl KeyCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_crypto() -> Crypto {
|
pub fn init_crypto() -> Crypto {
|
||||||
|
Self::build_crypto(default_kdf)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_crypto(kdf_fn: fn(Vec<u8>) -> Kdf) -> Crypto {
|
||||||
let salt = rand::rng().random::<[u8; SALT_SIZE]>();
|
let salt = rand::rng().random::<[u8; SALT_SIZE]>();
|
||||||
let iv = rand::rng().random::<[u8; IV_SIZE]>().to_vec().into();
|
let iv = rand::rng().random::<[u8; IV_SIZE]>().to_vec().into();
|
||||||
|
|
||||||
let kdf = default_kdf(salt.to_vec());
|
let kdf = kdf_fn(salt.to_vec());
|
||||||
let cipher = Cipher::Aes128Ctr(Aes128Ctr { iv });
|
let cipher = Cipher::Aes128Ctr(Aes128Ctr { iv });
|
||||||
|
|
||||||
Crypto {
|
Crypto {
|
||||||
@@ -116,7 +120,11 @@ impl KeyCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn encrypt(&mut self) -> Result<(), Error> {
|
fn encrypt(&mut self) -> Result<(), Error> {
|
||||||
self.crypto = Self::init_crypto();
|
self.encrypt_with(default_kdf)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encrypt_with(&mut self, kdf_fn: fn(Vec<u8>) -> Kdf) -> Result<(), Error> {
|
||||||
|
self.crypto = Self::build_crypto(kdf_fn);
|
||||||
let secret_map: SerializedKeyMap = self
|
let secret_map: SerializedKeyMap = self
|
||||||
.pairs
|
.pairs
|
||||||
.iter()
|
.iter()
|
||||||
@@ -268,7 +276,19 @@ pub enum Error {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use eth2_keystore::json_keystore::HexBytes;
|
use eth2_keystore::json_keystore::{HexBytes, Scrypt};
|
||||||
|
|
||||||
|
/// Scrypt with minimal cost (n=1024) for fast test execution.
|
||||||
|
/// Production uses n=262144 which takes ~45s per derivation.
|
||||||
|
fn insecure_kdf(salt: Vec<u8>) -> Kdf {
|
||||||
|
Kdf::Scrypt(Scrypt {
|
||||||
|
dklen: 32,
|
||||||
|
n: 1024,
|
||||||
|
p: 1,
|
||||||
|
r: 8,
|
||||||
|
salt: salt.into(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_serialization() {
|
async fn test_serialization() {
|
||||||
@@ -302,7 +322,7 @@ mod tests {
|
|||||||
key_cache.add(keypair.clone(), uuid, password.clone());
|
key_cache.add(keypair.clone(), uuid, password.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
key_cache.encrypt().unwrap();
|
key_cache.encrypt_with(insecure_kdf).unwrap();
|
||||||
key_cache.state = State::DecryptedAndSaved;
|
key_cache.state = State::DecryptedAndSaved;
|
||||||
|
|
||||||
assert_eq!(&key_cache.uuids, &uuids);
|
assert_eq!(&key_cache.uuids, &uuids);
|
||||||
|
|||||||
Reference in New Issue
Block a user