Clippy cleanup for all targets and nighly rust (also support 1.44.0) (#10445)
* address warnings from 'rustup run beta cargo clippy --workspace' minor refactoring in: - cli/src/cli.rs - cli/src/offline/blockhash_query.rs - logger/src/lib.rs - runtime/src/accounts_db.rs expect some performance improvement AccountsDB::clean_accounts() * address warnings from 'rustup run beta cargo clippy --workspace --tests' * address warnings from 'rustup run nightly cargo clippy --workspace --all-targets' * rustfmt * fix warning stragglers * properly fix clippy warnings test_vote_subscribe() replace ref-to-arc with ref parameters where arc not cloned * Remove lock around JsonRpcRequestProcessor (#10417) automerge * make ancestors parameter optional to avoid forcing construction of empty hash maps Co-authored-by: Greg Fitzgerald <greg@solana.com>
This commit is contained in:
committed by
GitHub
parent
fa3a6c5584
commit
e23340d89e
@ -14,7 +14,7 @@ fn deposit_many(bank: &Bank, pubkeys: &mut Vec<Pubkey>, num: usize) {
|
||||
for t in 0..num {
|
||||
let pubkey = Pubkey::new_rand();
|
||||
let account = Account::new((t + 1) as u64, 0, &Account::default().owner);
|
||||
pubkeys.push(pubkey.clone());
|
||||
pubkeys.push(pubkey);
|
||||
assert!(bank.get_account(&pubkey).is_none());
|
||||
bank.deposit(&pubkey, (t + 1) as u64);
|
||||
assert_eq!(bank.get_account(&pubkey).unwrap(), account);
|
||||
@ -48,7 +48,7 @@ fn test_accounts_squash(bencher: &mut Bencher) {
|
||||
&[],
|
||||
));
|
||||
let mut pubkeys: Vec<Pubkey> = vec![];
|
||||
deposit_many(&bank1, &mut pubkeys, 250000);
|
||||
deposit_many(&bank1, &mut pubkeys, 250_000);
|
||||
bank1.freeze();
|
||||
|
||||
// Measures the performance of the squash operation.
|
||||
|
@ -10,18 +10,15 @@ use test::Bencher;
|
||||
#[bench]
|
||||
fn bench_accounts_index(bencher: &mut Bencher) {
|
||||
const NUM_PUBKEYS: usize = 10_000;
|
||||
let pubkeys: Vec<_> = (0..NUM_PUBKEYS)
|
||||
.into_iter()
|
||||
.map(|_| Pubkey::new_rand())
|
||||
.collect();
|
||||
let pubkeys: Vec<_> = (0..NUM_PUBKEYS).map(|_| Pubkey::new_rand()).collect();
|
||||
|
||||
const NUM_FORKS: u64 = 16;
|
||||
|
||||
let mut reclaims = vec![];
|
||||
let mut index = AccountsIndex::<AccountInfo>::default();
|
||||
for f in 0..NUM_FORKS {
|
||||
for _p in 0..NUM_PUBKEYS {
|
||||
index.insert(f, &pubkeys[_p], AccountInfo::default(), &mut reclaims);
|
||||
for pubkey in pubkeys.iter().take(NUM_PUBKEYS) {
|
||||
index.insert(f, pubkey, AccountInfo::default(), &mut reclaims);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,6 @@ fn append_vec_append(bencher: &mut Bencher) {
|
||||
|
||||
fn add_test_accounts(vec: &AppendVec, size: usize) -> Vec<(usize, usize)> {
|
||||
(0..size)
|
||||
.into_iter()
|
||||
.filter_map(|sample| {
|
||||
let (meta, account) = create_test_account(sample);
|
||||
vec.append_account(meta, &account, Hash::default())
|
||||
@ -92,7 +91,7 @@ fn append_vec_concurrent_append_read(bencher: &mut Bencher) {
|
||||
bencher.iter(|| {
|
||||
let len = indexes.lock().unwrap().len();
|
||||
let random_index: usize = thread_rng().gen_range(0, len);
|
||||
let (sample, pos) = indexes.lock().unwrap().get(random_index).unwrap().clone();
|
||||
let (sample, pos) = *indexes.lock().unwrap().get(random_index).unwrap();
|
||||
let (account, _next) = vec.get_account(pos).unwrap();
|
||||
let (_meta, test) = create_test_account(sample);
|
||||
assert_eq!(account.data, test.data.as_slice());
|
||||
@ -112,12 +111,7 @@ fn append_vec_concurrent_read_append(bencher: &mut Bencher) {
|
||||
continue;
|
||||
}
|
||||
let random_index: usize = thread_rng().gen_range(0, len + 1);
|
||||
let (sample, pos) = indexes1
|
||||
.lock()
|
||||
.unwrap()
|
||||
.get(random_index % len)
|
||||
.unwrap()
|
||||
.clone();
|
||||
let (sample, pos) = *indexes1.lock().unwrap().get(random_index % len).unwrap();
|
||||
let (account, _next) = vec1.get_account(pos).unwrap();
|
||||
let (_meta, test) = create_test_account(sample);
|
||||
assert_eq!(account.data, test.data.as_slice());
|
||||
|
@ -19,13 +19,13 @@ use std::{sync::Arc, thread::sleep, time::Duration};
|
||||
use test::Bencher;
|
||||
|
||||
const BUILTIN_PROGRAM_ID: [u8; 32] = [
|
||||
098, 117, 105, 108, 116, 105, 110, 095, 112, 114, 111, 103, 114, 097, 109, 095, 105, 100, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
98, 117, 105, 108, 116, 105, 110, 95, 112, 114, 111, 103, 114, 97, 109, 95, 105, 100, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
|
||||
const NOOP_PROGRAM_ID: [u8; 32] = [
|
||||
098, 117, 105, 108, 116, 105, 110, 095, 112, 114, 111, 103, 114, 097, 109, 095, 105, 100, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
|
||||
98, 117, 105, 108, 116, 105, 110, 95, 112, 114, 111, 103, 114, 97, 109, 95, 105, 100, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
|
||||
];
|
||||
|
||||
fn process_instruction(
|
||||
@ -43,13 +43,12 @@ pub fn create_builtin_transactions(
|
||||
let program_id = Pubkey::new(&BUILTIN_PROGRAM_ID);
|
||||
|
||||
(0..4096)
|
||||
.into_iter()
|
||||
.map(|_| {
|
||||
// Seed the signer account
|
||||
let rando0 = Keypair::new();
|
||||
bank_client
|
||||
.transfer(10_000, &mint_keypair, &rando0.pubkey())
|
||||
.expect(&format!("{}:{}", line!(), file!()));
|
||||
.unwrap_or_else(|_| panic!("{}:{}", line!(), file!()));
|
||||
|
||||
let instruction = create_invoke_instruction(rando0.pubkey(), program_id, &1u8);
|
||||
let (blockhash, _fee_calculator) = bank_client.get_recent_blockhash().unwrap();
|
||||
@ -65,13 +64,12 @@ pub fn create_native_loader_transactions(
|
||||
let program_id = Pubkey::new(&NOOP_PROGRAM_ID);
|
||||
|
||||
(0..4096)
|
||||
.into_iter()
|
||||
.map(|_| {
|
||||
// Seed the signer account©41
|
||||
let rando0 = Keypair::new();
|
||||
bank_client
|
||||
.transfer(10_000, &mint_keypair, &rando0.pubkey())
|
||||
.expect(&format!("{}:{}", line!(), file!()));
|
||||
.unwrap_or_else(|_| panic!("{}:{}", line!(), file!()));
|
||||
|
||||
let instruction = create_invoke_instruction(rando0.pubkey(), program_id, &1u8);
|
||||
let (blockhash, _fee_calculator) = bank_client.get_recent_blockhash().unwrap();
|
||||
@ -80,13 +78,13 @@ pub fn create_native_loader_transactions(
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn sync_bencher(bank: &Arc<Bank>, _bank_client: &BankClient, transactions: &Vec<Transaction>) {
|
||||
fn sync_bencher(bank: &Arc<Bank>, _bank_client: &BankClient, transactions: &[Transaction]) {
|
||||
let results = bank.process_transactions(&transactions);
|
||||
assert!(results.iter().all(Result::is_ok));
|
||||
}
|
||||
|
||||
fn async_bencher(bank: &Arc<Bank>, bank_client: &BankClient, transactions: &Vec<Transaction>) {
|
||||
for transaction in transactions.clone() {
|
||||
fn async_bencher(bank: &Arc<Bank>, bank_client: &BankClient, transactions: &[Transaction]) {
|
||||
for transaction in transactions.to_owned() {
|
||||
bank_client.async_send_transaction(transaction).unwrap();
|
||||
}
|
||||
for _ in 0..1_000_000_000_u64 {
|
||||
@ -98,23 +96,23 @@ fn async_bencher(bank: &Arc<Bank>, bank_client: &BankClient, transactions: &Vec<
|
||||
}
|
||||
sleep(Duration::from_nanos(1));
|
||||
}
|
||||
if !bank
|
||||
if bank
|
||||
.get_signature_status(&transactions.last().unwrap().signatures.get(0).unwrap())
|
||||
.unwrap()
|
||||
.is_ok()
|
||||
.is_err()
|
||||
{
|
||||
error!(
|
||||
"transaction failed: {:?}",
|
||||
bank.get_signature_status(&transactions.last().unwrap().signatures.get(0).unwrap())
|
||||
.unwrap()
|
||||
);
|
||||
assert!(false);
|
||||
panic!();
|
||||
}
|
||||
}
|
||||
|
||||
fn do_bench_transactions(
|
||||
bencher: &mut Bencher,
|
||||
bench_work: &dyn Fn(&Arc<Bank>, &BankClient, &Vec<Transaction>),
|
||||
bench_work: &dyn Fn(&Arc<Bank>, &BankClient, &[Transaction]),
|
||||
create_transactions: &dyn Fn(&BankClient, &Keypair) -> Vec<Transaction>,
|
||||
) {
|
||||
solana_logger::setup();
|
||||
|
@ -47,10 +47,7 @@ fn bench_sigs_bloom(bencher: &mut Bencher) {
|
||||
// https://hur.st/bloomfilter/?n=1000000&p=1.0E-8&m=&k=
|
||||
let blockhash = hash(Hash::default().as_ref());
|
||||
// info!("blockhash = {:?}", blockhash);
|
||||
let keys = (0..27)
|
||||
.into_iter()
|
||||
.map(|i| blockhash.hash_at_index(i))
|
||||
.collect();
|
||||
let keys = (0..27).map(|i| blockhash.hash_at_index(i)).collect();
|
||||
let mut sigs: Bloom<Signature> = Bloom::new(38_340_234, keys);
|
||||
|
||||
let mut id = blockhash;
|
||||
|
@ -30,6 +30,6 @@ fn test_statuscache_serialize(bencher: &mut Bencher) {
|
||||
}
|
||||
}
|
||||
bencher.iter(|| {
|
||||
let _ = serialize(&status_cache.slot_deltas(&vec![0])).unwrap();
|
||||
let _ = serialize(&status_cache.slot_deltas(&[0])).unwrap();
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user