Make bad_bank_hash test faster (#13206)
This commit is contained in:
parent
032a7d36ff
commit
d5e439037b
|
@ -4441,35 +4441,59 @@ pub mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_bad_bank_hash() {
|
fn test_bad_bank_hash() {
|
||||||
|
solana_logger::setup();
|
||||||
use solana_sdk::signature::{Keypair, Signer};
|
use solana_sdk::signature::{Keypair, Signer};
|
||||||
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
let db = AccountsDB::new(Vec::new(), &ClusterType::Development);
|
||||||
|
|
||||||
let some_slot: Slot = 0;
|
let some_slot: Slot = 0;
|
||||||
let ancestors: Ancestors = [(some_slot, 0)].iter().copied().collect();
|
let ancestors: Ancestors = [(some_slot, 0)].iter().copied().collect();
|
||||||
|
|
||||||
for _ in 0..10_000 {
|
let max_accounts = 200;
|
||||||
|
let mut accounts_keys: Vec<_> = (0..max_accounts)
|
||||||
|
.into_par_iter()
|
||||||
|
.map(|_| {
|
||||||
|
let key = Keypair::new().pubkey();
|
||||||
|
let lamports = thread_rng().gen_range(0, 100);
|
||||||
|
let some_data_len = thread_rng().gen_range(0, 1000);
|
||||||
|
let account = Account::new(lamports, some_data_len, &key);
|
||||||
|
(key, account)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let mut existing = HashSet::new();
|
||||||
|
let mut last_print = Instant::now();
|
||||||
|
for i in 0..5_000 {
|
||||||
|
if last_print.elapsed().as_millis() > 5000 {
|
||||||
|
info!("i: {}", i);
|
||||||
|
last_print = Instant::now();
|
||||||
|
}
|
||||||
let num_accounts = thread_rng().gen_range(0, 100);
|
let num_accounts = thread_rng().gen_range(0, 100);
|
||||||
let accounts_keys: Vec<_> = (0..num_accounts)
|
(0..num_accounts).into_iter().for_each(|_| {
|
||||||
.map(|_| {
|
let mut idx;
|
||||||
let key = Keypair::new().pubkey();
|
loop {
|
||||||
let lamports = thread_rng().gen_range(0, 100);
|
idx = thread_rng().gen_range(0, max_accounts);
|
||||||
let some_data_len = thread_rng().gen_range(0, 1000);
|
if existing.contains(&idx) {
|
||||||
let account = Account::new(lamports, some_data_len, &key);
|
continue;
|
||||||
(key, account)
|
}
|
||||||
})
|
existing.insert(idx);
|
||||||
.collect();
|
break;
|
||||||
let account_refs: Vec<_> = accounts_keys
|
}
|
||||||
|
accounts_keys[idx].1.lamports = thread_rng().gen_range(0, 1000);
|
||||||
|
});
|
||||||
|
|
||||||
|
let account_refs: Vec<_> = existing
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(key, account)| (key, account))
|
.map(|idx| (&accounts_keys[*idx].0, &accounts_keys[*idx].1))
|
||||||
.collect();
|
.collect();
|
||||||
db.store(some_slot, &account_refs);
|
db.store(some_slot, &account_refs);
|
||||||
|
|
||||||
for (key, account) in &accounts_keys {
|
for (key, account) in &account_refs {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
db.load_account_hash(&ancestors, key),
|
db.load_account_hash(&ancestors, &key),
|
||||||
AccountsDB::hash_account(some_slot, &account, &key, &ClusterType::Development)
|
AccountsDB::hash_account(some_slot, &account, &key, &ClusterType::Development)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
existing.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue