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();
|
||||
});
|
||||
}
|
||||
|
@ -153,12 +153,12 @@ impl Accounts {
|
||||
}
|
||||
let (account, rent) =
|
||||
AccountsDB::load(storage, ancestors, accounts_index, key)
|
||||
.and_then(|(mut account, _)| {
|
||||
.map(|(mut account, _)| {
|
||||
if message.is_writable(i) && !account.executable {
|
||||
let rent_due = rent_collector.update(&key, &mut account);
|
||||
Some((account, rent_due))
|
||||
(account, rent_due)
|
||||
} else {
|
||||
Some((account, 0))
|
||||
(account, 0)
|
||||
}
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
@ -617,7 +617,6 @@ impl AccountsDB {
|
||||
pub fn clean_accounts(&self) {
|
||||
self.report_store_stats();
|
||||
|
||||
let no_ancestors = HashMap::new();
|
||||
let mut accounts_scan = Measure::start("accounts_scan");
|
||||
let accounts_index = self.accounts_index.read().unwrap();
|
||||
let pubkeys: Vec<Pubkey> = accounts_index.account_maps.keys().cloned().collect();
|
||||
@ -628,7 +627,7 @@ impl AccountsDB {
|
||||
let mut purges_in_root = Vec::new();
|
||||
let mut purges = HashMap::new();
|
||||
for pubkey in pubkeys {
|
||||
if let Some((list, index)) = accounts_index.get(pubkey, &no_ancestors) {
|
||||
if let Some((list, index)) = accounts_index.get(pubkey, None) {
|
||||
let (slot, account_info) = &list[index];
|
||||
if account_info.lamports == 0 {
|
||||
purges.insert(*pubkey, accounts_index.would_purge(pubkey));
|
||||
@ -641,16 +640,11 @@ impl AccountsDB {
|
||||
})
|
||||
.reduce(
|
||||
|| (HashMap::new(), Vec::new()),
|
||||
|m1, m2| {
|
||||
|mut m1, m2| {
|
||||
// Collapse down the hashmaps/vecs into one.
|
||||
let x = m2.0.iter().fold(m1.0, |mut acc, (k, vs)| {
|
||||
acc.insert(k.clone(), vs.clone());
|
||||
acc
|
||||
});
|
||||
let mut y = vec![];
|
||||
y.extend(m1.1);
|
||||
y.extend(m2.1);
|
||||
(x, y)
|
||||
m1.0.extend(m2.0);
|
||||
m1.1.extend(m2.1);
|
||||
m1
|
||||
},
|
||||
);
|
||||
|
||||
@ -806,7 +800,6 @@ impl AccountsDB {
|
||||
}
|
||||
|
||||
let alive_accounts: Vec<_> = {
|
||||
let no_ancestors = HashMap::new();
|
||||
let accounts_index = self.accounts_index.read().unwrap();
|
||||
stored_accounts
|
||||
.iter()
|
||||
@ -819,7 +812,7 @@ impl AccountsDB {
|
||||
(store_id, offset),
|
||||
_write_version,
|
||||
)| {
|
||||
if let Some((list, _)) = accounts_index.get(pubkey, &no_ancestors) {
|
||||
if let Some((list, _)) = accounts_index.get(pubkey, None) {
|
||||
list.iter()
|
||||
.any(|(_slot, i)| i.store_id == *store_id && i.offset == *offset)
|
||||
} else {
|
||||
@ -927,7 +920,7 @@ impl AccountsDB {
|
||||
|
||||
pub fn scan_accounts<F, A>(&self, ancestors: &Ancestors, scan_func: F) -> A
|
||||
where
|
||||
F: Fn(&mut A, Option<(&Pubkey, Account, Slot)>) -> (),
|
||||
F: Fn(&mut A, Option<(&Pubkey, Account, Slot)>),
|
||||
A: Default,
|
||||
{
|
||||
let mut collector = A::default();
|
||||
@ -946,7 +939,7 @@ impl AccountsDB {
|
||||
|
||||
pub fn range_scan_accounts<F, A, R>(&self, ancestors: &Ancestors, range: R, scan_func: F) -> A
|
||||
where
|
||||
F: Fn(&mut A, Option<(&Pubkey, Account, Slot)>) -> (),
|
||||
F: Fn(&mut A, Option<(&Pubkey, Account, Slot)>),
|
||||
A: Default,
|
||||
R: RangeBounds<Pubkey>,
|
||||
{
|
||||
@ -968,7 +961,7 @@ impl AccountsDB {
|
||||
// PERF: Sequentially read each storage entry in parallel
|
||||
pub fn scan_account_storage<F, B>(&self, slot: Slot, scan_func: F) -> Vec<B>
|
||||
where
|
||||
F: Fn(&StoredAccount, AppendVecId, &mut B) -> () + Send + Sync,
|
||||
F: Fn(&StoredAccount, AppendVecId, &mut B) + Send + Sync,
|
||||
B: Send + Default,
|
||||
{
|
||||
let storage_maps: Vec<Arc<AccountStorageEntry>> = self
|
||||
@ -1020,7 +1013,7 @@ impl AccountsDB {
|
||||
accounts_index: &AccountsIndex<AccountInfo>,
|
||||
pubkey: &Pubkey,
|
||||
) -> Option<(Account, Slot)> {
|
||||
let (lock, index) = accounts_index.get(pubkey, ancestors)?;
|
||||
let (lock, index) = accounts_index.get(pubkey, Some(ancestors))?;
|
||||
let slot = lock[index].0;
|
||||
//TODO: thread this as a ref
|
||||
if let Some(slot_storage) = storage.0.get(&slot) {
|
||||
@ -1037,7 +1030,7 @@ impl AccountsDB {
|
||||
#[cfg(test)]
|
||||
fn load_account_hash(&self, ancestors: &Ancestors, pubkey: &Pubkey) -> Hash {
|
||||
let accounts_index = self.accounts_index.read().unwrap();
|
||||
let (lock, index) = accounts_index.get(pubkey, ancestors).unwrap();
|
||||
let (lock, index) = accounts_index.get(pubkey, Some(ancestors)).unwrap();
|
||||
let slot = lock[index].0;
|
||||
let storage = self.storage.read().unwrap();
|
||||
let slot_storage = storage.0.get(&slot).unwrap();
|
||||
@ -1449,7 +1442,7 @@ impl AccountsDB {
|
||||
let hashes: Vec<_> = keys
|
||||
.par_iter()
|
||||
.filter_map(|pubkey| {
|
||||
if let Some((list, index)) = accounts_index.get(pubkey, ancestors) {
|
||||
if let Some((list, index)) = accounts_index.get(pubkey, Some(ancestors)) {
|
||||
let (slot, account_info) = &list[index];
|
||||
if account_info.lamports != 0 {
|
||||
storage
|
||||
@ -1839,7 +1832,7 @@ impl AccountsDB {
|
||||
};
|
||||
let entry = accum
|
||||
.entry(stored_account.meta.pubkey)
|
||||
.or_insert_with(|| vec![]);
|
||||
.or_insert_with(Vec::new);
|
||||
entry.push((stored_account.meta.write_version, account_info));
|
||||
},
|
||||
);
|
||||
@ -1847,7 +1840,7 @@ impl AccountsDB {
|
||||
let mut accounts_map: HashMap<Pubkey, Vec<(u64, AccountInfo)>> = HashMap::new();
|
||||
for accumulator_entry in accumulator.iter() {
|
||||
for (pubkey, storage_entry) in accumulator_entry {
|
||||
let entry = accounts_map.entry(*pubkey).or_insert_with(|| vec![]);
|
||||
let entry = accounts_map.entry(*pubkey).or_insert_with(Vec::new);
|
||||
entry.extend(storage_entry.iter().cloned());
|
||||
}
|
||||
}
|
||||
@ -2118,7 +2111,7 @@ pub mod tests {
|
||||
.accounts_index
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(&key, &ancestors)
|
||||
.get(&key, Some(&ancestors))
|
||||
.is_some());
|
||||
assert_load_account(&db, unrooted_slot, key, 1);
|
||||
|
||||
@ -2139,7 +2132,7 @@ pub mod tests {
|
||||
.accounts_index
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(&key, &ancestors)
|
||||
.get(&key, Some(&ancestors))
|
||||
.is_none());
|
||||
|
||||
// Test we can store for the same slot again and get the right information
|
||||
@ -2188,14 +2181,14 @@ pub mod tests {
|
||||
for t in 0..num {
|
||||
let pubkey = Pubkey::new_rand();
|
||||
let account = Account::new((t + 1) as u64, space, &Account::default().owner);
|
||||
pubkeys.push(pubkey.clone());
|
||||
pubkeys.push(pubkey);
|
||||
assert!(accounts.load_slow(&ancestors, &pubkey).is_none());
|
||||
accounts.store(slot, &[(&pubkey, &account)]);
|
||||
}
|
||||
for t in 0..num_vote {
|
||||
let pubkey = Pubkey::new_rand();
|
||||
let account = Account::new((num + t + 1) as u64, space, &solana_vote_program::id());
|
||||
pubkeys.push(pubkey.clone());
|
||||
pubkeys.push(pubkey);
|
||||
let ancestors = vec![(slot, 0)].into_iter().collect();
|
||||
assert!(accounts.load_slow(&ancestors, &pubkey).is_none());
|
||||
accounts.store(slot, &[(&pubkey, &account)]);
|
||||
@ -2435,7 +2428,7 @@ pub mod tests {
|
||||
let ancestors = vec![(0, 0)].into_iter().collect();
|
||||
let id = {
|
||||
let index = accounts.accounts_index.read().unwrap();
|
||||
let (list, idx) = index.get(&pubkey, &ancestors).unwrap();
|
||||
let (list, idx) = index.get(&pubkey, Some(&ancestors)).unwrap();
|
||||
list[idx].1.store_id
|
||||
};
|
||||
accounts.add_root(1);
|
||||
|
@ -24,29 +24,29 @@ pub struct AccountsIndex<T> {
|
||||
impl<'a, T: 'a + Clone> AccountsIndex<T> {
|
||||
fn do_scan_accounts<F, I>(&self, ancestors: &Ancestors, mut func: F, iter: I)
|
||||
where
|
||||
F: FnMut(&Pubkey, (&T, Slot)) -> (),
|
||||
F: FnMut(&Pubkey, (&T, Slot)),
|
||||
I: Iterator<Item = (&'a Pubkey, &'a AccountMapEntry<T>)>,
|
||||
{
|
||||
for (pubkey, list) in iter {
|
||||
let list_r = &list.1.read().unwrap();
|
||||
if let Some(index) = self.latest_slot(ancestors, &list_r) {
|
||||
if let Some(index) = self.latest_slot(Some(ancestors), &list_r) {
|
||||
func(pubkey, (&list_r[index].1, list_r[index].0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// call func with every pubkey and index visible from a given set of ancestors
|
||||
pub fn scan_accounts<F>(&self, ancestors: &Ancestors, func: F)
|
||||
pub(crate) fn scan_accounts<F>(&self, ancestors: &Ancestors, func: F)
|
||||
where
|
||||
F: FnMut(&Pubkey, (&T, Slot)) -> (),
|
||||
F: FnMut(&Pubkey, (&T, Slot)),
|
||||
{
|
||||
self.do_scan_accounts(ancestors, func, self.account_maps.iter());
|
||||
}
|
||||
|
||||
/// call func with every pubkey and index visible from a given set of ancestors with range
|
||||
pub fn range_scan_accounts<F, R>(&self, ancestors: &Ancestors, range: R, func: F)
|
||||
pub(crate) fn range_scan_accounts<F, R>(&self, ancestors: &Ancestors, range: R, func: F)
|
||||
where
|
||||
F: FnMut(&Pubkey, (&T, Slot)) -> (),
|
||||
F: FnMut(&Pubkey, (&T, Slot)),
|
||||
R: RangeBounds<Pubkey>,
|
||||
{
|
||||
self.do_scan_accounts(ancestors, func, self.account_maps.range(range));
|
||||
@ -76,11 +76,14 @@ impl<'a, T: 'a + Clone> AccountsIndex<T> {
|
||||
|
||||
// find the latest slot and T in a slice for a given ancestor
|
||||
// returns index into 'slice' if found, None if not.
|
||||
fn latest_slot(&self, ancestors: &Ancestors, slice: SlotSlice<T>) -> Option<usize> {
|
||||
fn latest_slot(&self, ancestors: Option<&Ancestors>, slice: SlotSlice<T>) -> Option<usize> {
|
||||
let mut max = 0;
|
||||
let mut rv = None;
|
||||
for (i, (slot, _t)) in slice.iter().rev().enumerate() {
|
||||
if *slot >= max && (ancestors.contains_key(slot) || self.is_root(*slot)) {
|
||||
if *slot >= max
|
||||
&& (ancestors.map_or(false, |ancestors| ancestors.contains_key(slot))
|
||||
|| self.is_root(*slot))
|
||||
{
|
||||
rv = Some((slice.len() - 1) - i);
|
||||
max = *slot;
|
||||
}
|
||||
@ -90,10 +93,10 @@ impl<'a, T: 'a + Clone> AccountsIndex<T> {
|
||||
|
||||
/// Get an account
|
||||
/// The latest account that appears in `ancestors` or `roots` is returned.
|
||||
pub fn get(
|
||||
pub(crate) fn get(
|
||||
&self,
|
||||
pubkey: &Pubkey,
|
||||
ancestors: &Ancestors,
|
||||
ancestors: Option<&Ancestors>,
|
||||
) -> Option<(RwLockReadGuard<SlotList<T>>, usize)> {
|
||||
self.account_maps.get(pubkey).and_then(|list| {
|
||||
let list_r = list.1.read().unwrap();
|
||||
@ -245,7 +248,8 @@ mod tests {
|
||||
let key = Keypair::new();
|
||||
let index = AccountsIndex::<bool>::default();
|
||||
let ancestors = HashMap::new();
|
||||
assert!(index.get(&key.pubkey(), &ancestors).is_none());
|
||||
assert!(index.get(&key.pubkey(), Some(&ancestors)).is_none());
|
||||
assert!(index.get(&key.pubkey(), None).is_none());
|
||||
|
||||
let mut num = 0;
|
||||
index.scan_accounts(&ancestors, |_pubkey, _index| num += 1);
|
||||
@ -261,7 +265,8 @@ mod tests {
|
||||
assert!(gc.is_empty());
|
||||
|
||||
let ancestors = HashMap::new();
|
||||
assert!(index.get(&key.pubkey(), &ancestors).is_none());
|
||||
assert!(index.get(&key.pubkey(), Some(&ancestors)).is_none());
|
||||
assert!(index.get(&key.pubkey(), None).is_none());
|
||||
|
||||
let mut num = 0;
|
||||
index.scan_accounts(&ancestors, |_pubkey, _index| num += 1);
|
||||
@ -277,7 +282,7 @@ mod tests {
|
||||
assert!(gc.is_empty());
|
||||
|
||||
let ancestors = vec![(1, 1)].into_iter().collect();
|
||||
assert!(index.get(&key.pubkey(), &ancestors).is_none());
|
||||
assert!(index.get(&key.pubkey(), Some(&ancestors)).is_none());
|
||||
|
||||
let mut num = 0;
|
||||
index.scan_accounts(&ancestors, |_pubkey, _index| num += 1);
|
||||
@ -293,7 +298,7 @@ mod tests {
|
||||
assert!(gc.is_empty());
|
||||
|
||||
let ancestors = vec![(0, 0)].into_iter().collect();
|
||||
let (list, idx) = index.get(&key.pubkey(), &ancestors).unwrap();
|
||||
let (list, idx) = index.get(&key.pubkey(), Some(&ancestors)).unwrap();
|
||||
assert_eq!(list[idx], (0, true));
|
||||
|
||||
let mut num = 0;
|
||||
@ -324,9 +329,8 @@ mod tests {
|
||||
index.insert(0, &key.pubkey(), true, &mut gc);
|
||||
assert!(gc.is_empty());
|
||||
|
||||
let ancestors = vec![].into_iter().collect();
|
||||
index.add_root(0);
|
||||
let (list, idx) = index.get(&key.pubkey(), &ancestors).unwrap();
|
||||
let (list, idx) = index.get(&key.pubkey(), None).unwrap();
|
||||
assert_eq!(list[idx], (0, true));
|
||||
}
|
||||
|
||||
@ -369,14 +373,14 @@ mod tests {
|
||||
let mut gc = Vec::new();
|
||||
index.insert(0, &key.pubkey(), true, &mut gc);
|
||||
assert!(gc.is_empty());
|
||||
let (list, idx) = index.get(&key.pubkey(), &ancestors).unwrap();
|
||||
let (list, idx) = index.get(&key.pubkey(), Some(&ancestors)).unwrap();
|
||||
assert_eq!(list[idx], (0, true));
|
||||
drop(list);
|
||||
|
||||
let mut gc = Vec::new();
|
||||
index.insert(0, &key.pubkey(), false, &mut gc);
|
||||
assert_eq!(gc, vec![(0, true)]);
|
||||
let (list, idx) = index.get(&key.pubkey(), &ancestors).unwrap();
|
||||
let (list, idx) = index.get(&key.pubkey(), Some(&ancestors)).unwrap();
|
||||
assert_eq!(list[idx], (0, false));
|
||||
}
|
||||
|
||||
@ -391,10 +395,10 @@ mod tests {
|
||||
assert!(gc.is_empty());
|
||||
index.insert(1, &key.pubkey(), false, &mut gc);
|
||||
assert!(gc.is_empty());
|
||||
let (list, idx) = index.get(&key.pubkey(), &ancestors).unwrap();
|
||||
let (list, idx) = index.get(&key.pubkey(), Some(&ancestors)).unwrap();
|
||||
assert_eq!(list[idx], (0, true));
|
||||
let ancestors = vec![(1, 0)].into_iter().collect();
|
||||
let (list, idx) = index.get(&key.pubkey(), &ancestors).unwrap();
|
||||
let (list, idx) = index.get(&key.pubkey(), Some(&ancestors)).unwrap();
|
||||
assert_eq!(list[idx], (1, false));
|
||||
}
|
||||
|
||||
@ -413,13 +417,12 @@ mod tests {
|
||||
index.add_root(3);
|
||||
index.insert(4, &key.pubkey(), true, &mut gc);
|
||||
assert_eq!(gc, vec![(0, true), (1, false), (2, true)]);
|
||||
let ancestors = vec![].into_iter().collect();
|
||||
let (list, idx) = index.get(&key.pubkey(), &ancestors).unwrap();
|
||||
let (list, idx) = index.get(&key.pubkey(), None).unwrap();
|
||||
assert_eq!(list[idx], (3, true));
|
||||
|
||||
let mut num = 0;
|
||||
let mut found_key = false;
|
||||
index.scan_accounts(&ancestors, |pubkey, _index| {
|
||||
index.scan_accounts(&Ancestors::new(), |pubkey, _index| {
|
||||
if pubkey == &key.pubkey() {
|
||||
found_key = true;
|
||||
assert_eq!(_index, (&true, 3));
|
||||
|
@ -150,7 +150,7 @@ impl StatusCacheRc {
|
||||
}
|
||||
}
|
||||
|
||||
pub type EnteredEpochCallback = Box<dyn Fn(&mut Bank) -> () + Sync + Send>;
|
||||
pub type EnteredEpochCallback = Box<dyn Fn(&mut Bank) + Sync + Send>;
|
||||
|
||||
pub type TransactionProcessResult = (Result<()>, Option<HashAgeKind>);
|
||||
pub struct TransactionResults {
|
||||
@ -3854,7 +3854,7 @@ mod tests {
|
||||
impl Bank {
|
||||
fn slots_by_pubkey(&self, pubkey: &Pubkey, ancestors: &Ancestors) -> Vec<Slot> {
|
||||
let accounts_index = self.rc.accounts.accounts_db.accounts_index.read().unwrap();
|
||||
let (accounts, _) = accounts_index.get(&pubkey, &ancestors).unwrap();
|
||||
let (accounts, _) = accounts_index.get(&pubkey, Some(&ancestors)).unwrap();
|
||||
accounts
|
||||
.iter()
|
||||
.map(|(slot, _)| *slot)
|
||||
@ -4988,7 +4988,7 @@ mod tests {
|
||||
let (genesis_config, mint_keypair) = create_genesis_config(2_000);
|
||||
let bank0 = Arc::new(Bank::new(&genesis_config));
|
||||
let initial_state = bank0.hash_internal_state();
|
||||
let bank1 = Bank::new_from_parent(&bank0.clone(), &Pubkey::default(), 1);
|
||||
let bank1 = Bank::new_from_parent(&bank0, &Pubkey::default(), 1);
|
||||
assert_ne!(bank1.hash_internal_state(), initial_state);
|
||||
|
||||
info!("transfer bank1");
|
||||
|
@ -42,15 +42,20 @@ impl<T: BloomHashIndex> Bloom<T> {
|
||||
let keys: Vec<u64> = (0..num_keys).map(|_| rand::thread_rng().gen()).collect();
|
||||
Self::new(num_bits, keys)
|
||||
}
|
||||
pub fn num_bits(num_items: f64, false_rate: f64) -> f64 {
|
||||
fn num_bits(num_items: f64, false_rate: f64) -> f64 {
|
||||
let n = num_items;
|
||||
let p = false_rate;
|
||||
((n * p.ln()) / (1f64 / 2f64.powf(2f64.ln())).ln()).ceil()
|
||||
}
|
||||
pub fn num_keys(num_bits: f64, num_items: f64) -> f64 {
|
||||
fn num_keys(num_bits: f64, num_items: f64) -> f64 {
|
||||
let n = num_items;
|
||||
let m = num_bits;
|
||||
1f64.max(((m / n) * 2f64.ln()).round())
|
||||
// infinity as usize is zero in rust 1.43 but 2^64-1 in rust 1.45; ensure it's zero here
|
||||
if n == 0.0 {
|
||||
0.0
|
||||
} else {
|
||||
1f64.max(((m / n) * 2f64.ln()).round())
|
||||
}
|
||||
}
|
||||
fn pos(&self, key: &T, k: u64) -> u64 {
|
||||
key.hash_at_index(k) % self.bits.len()
|
||||
|
@ -930,7 +930,7 @@ mod tests {
|
||||
|
||||
fn with_create_zero_lamport<F>(callback: F)
|
||||
where
|
||||
F: Fn(&Bank) -> (),
|
||||
F: Fn(&Bank),
|
||||
{
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -206,7 +206,7 @@ mod tests {
|
||||
fn verify_nonce_ok() {
|
||||
with_test_keyed_account(42, true, |nonce_account| {
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(nonce_account.signer_key().unwrap().clone());
|
||||
signers.insert(nonce_account.signer_key().unwrap());
|
||||
let state: State = nonce_account.state().unwrap();
|
||||
// New is in Uninitialzed state
|
||||
assert_eq!(state, State::Uninitialized);
|
||||
@ -236,7 +236,7 @@ mod tests {
|
||||
fn verify_nonce_bad_query_hash_fail() {
|
||||
with_test_keyed_account(42, true, |nonce_account| {
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(nonce_account.signer_key().unwrap().clone());
|
||||
signers.insert(nonce_account.signer_key().unwrap());
|
||||
let state: State = nonce_account.state().unwrap();
|
||||
// New is in Uninitialzed state
|
||||
assert_eq!(state, State::Uninitialized);
|
||||
|
@ -48,11 +48,16 @@ impl RentCollector {
|
||||
.map(|epoch| self.epoch_schedule.get_slots_in_epoch(epoch + 1))
|
||||
.sum();
|
||||
|
||||
let (rent_due, exempt) = self.rent.due(
|
||||
account.lamports,
|
||||
account.data.len(),
|
||||
slots_elapsed as f64 / self.slots_per_year,
|
||||
);
|
||||
// avoid infinite rent in rust 1.45
|
||||
let years_elapsed = if self.slots_per_year != 0.0 {
|
||||
slots_elapsed as f64 / self.slots_per_year
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
|
||||
let (rent_due, exempt) =
|
||||
self.rent
|
||||
.due(account.lamports, account.data.len(), years_elapsed);
|
||||
|
||||
if exempt || rent_due != 0 {
|
||||
if account.lamports > rent_due {
|
||||
|
@ -271,7 +271,7 @@ impl<T: Serialize + Clone> StatusCache<T> {
|
||||
.or_insert((slot, sig_index, HashMap::new()));
|
||||
sig_map.0 = std::cmp::max(slot, sig_map.0);
|
||||
|
||||
let sig_forks = sig_map.2.entry(sig_slice).or_insert_with(|| vec![]);
|
||||
let sig_forks = sig_map.2.entry(sig_slice).or_insert_with(Vec::new);
|
||||
sig_forks.push((slot, res.clone()));
|
||||
let slot_deltas = self.slot_deltas.entry(slot).or_default();
|
||||
let mut fork_entry = slot_deltas.lock().unwrap();
|
||||
|
@ -933,7 +933,7 @@ mod tests {
|
||||
|
||||
fn with_create_zero_lamport<F>(callback: F)
|
||||
where
|
||||
F: Fn(&Bank) -> (),
|
||||
F: Fn(&Bank),
|
||||
{
|
||||
solana_logger::setup();
|
||||
|
||||
|
Reference in New Issue
Block a user