This commit is contained in:
Michael Vines
2020-12-13 17:26:34 -08:00
parent 0d139d7ef3
commit 7143aaa89b
102 changed files with 543 additions and 499 deletions

View File

@@ -118,8 +118,10 @@ impl Accounts {
}
fn construct_instructions_account(message: &Message) -> Account {
let mut account = Account::default();
account.data = message.serialize_instructions();
let mut account = Account {
data: message.serialize_instructions(),
..Account::default()
};
// add room for current instruction index.
account.data.resize(account.data.len() + 2, 0);

View File

@@ -188,7 +188,7 @@ impl ABSRequestHandler {
})
}
pub fn handle_pruned_banks<'a>(&'a self, bank: &Bank) -> usize {
pub fn handle_pruned_banks(&self, bank: &Bank) -> usize {
let mut count = 0;
for pruned_slot in self.pruned_banks_receiver.try_iter() {
count += 1;

View File

@@ -44,7 +44,6 @@ use std::{
collections::{HashMap, HashSet},
convert::TryInto,
io::{Error as IOError, Result as IOResult},
iter::FromIterator,
ops::RangeBounds,
path::{Path, PathBuf},
sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering},
@@ -901,10 +900,7 @@ impl AccountsDB {
let pubkey_to_slot_set: Vec<_> = purges
.into_iter()
.map(|(key, (slots_list, _ref_count))| {
(
key,
HashSet::from_iter(slots_list.into_iter().map(|(slot, _)| slot)),
)
(key, slots_list.into_iter().map(|(slot, _)| slot).collect())
})
.collect();
@@ -2875,6 +2871,7 @@ impl AccountsDB {
pub fn generate_index(&self) {
let mut slots = self.storage.all_slots();
#[allow(clippy::stable_sort_primitive)]
slots.sort();
let mut last_log_update = Instant::now();
@@ -2982,6 +2979,7 @@ impl AccountsDB {
fn print_index(&self, label: &str) {
let mut roots: Vec<_> = self.accounts_index.all_roots();
#[allow(clippy::stable_sort_primitive)]
roots.sort();
info!("{}: accounts_index roots: {:?}", label, roots,);
for (pubkey, account_entry) in self.accounts_index.account_maps.read().unwrap().iter() {
@@ -2995,12 +2993,14 @@ impl AccountsDB {
fn print_count_and_status(&self, label: &str) {
let mut slots: Vec<_> = self.storage.all_slots();
#[allow(clippy::stable_sort_primitive)]
slots.sort();
info!("{}: count_and status for {} slots:", label, slots.len());
for slot in &slots {
let slot_stores = self.storage.get_slot_stores(*slot).unwrap();
let r_slot_stores = slot_stores.read().unwrap();
let mut ids: Vec<_> = r_slot_stores.keys().cloned().collect();
#[allow(clippy::stable_sort_primitive)]
ids.sort();
for id in &ids {
let entry = r_slot_stores.get(id).unwrap();
@@ -3033,7 +3033,7 @@ pub mod tests {
use assert_matches::assert_matches;
use rand::{thread_rng, Rng};
use solana_sdk::{account::Account, hash::HASH_BYTES};
use std::{fs, str::FromStr};
use std::{fs, iter::FromIterator, str::FromStr};
fn linear_ancestors(end_slot: u64) -> Ancestors {
let mut ancestors: Ancestors = vec![(0, 0)].into_iter().collect();
@@ -3155,8 +3155,10 @@ pub mod tests {
let idx = thread_rng().gen_range(0, 99);
let ancestors = vec![(0, 0)].into_iter().collect();
let account = db.load_slow(&ancestors, &pubkeys[idx]).unwrap();
let mut default_account = Account::default();
default_account.lamports = (idx + 1) as u64;
let default_account = Account {
lamports: (idx + 1) as u64,
..Account::default()
};
assert_eq!((default_account, 0), account);
}
@@ -3169,8 +3171,10 @@ pub mod tests {
let account0 = db.load_slow(&ancestors, &pubkeys[idx]).unwrap();
let ancestors = vec![(1, 1)].into_iter().collect();
let account1 = db.load_slow(&ancestors, &pubkeys[idx]).unwrap();
let mut default_account = Account::default();
default_account.lamports = (idx + 1) as u64;
let default_account = Account {
lamports: (idx + 1) as u64,
..Account::default()
};
assert_eq!(&default_account, &account0.0);
assert_eq!(&default_account, &account1.0);
}
@@ -3361,8 +3365,10 @@ pub mod tests {
let ancestors = vec![(slot, 0)].into_iter().collect();
assert!(accounts.load_slow(&ancestors, &pubkeys[idx]).is_none());
} else {
let mut default_account = Account::default();
default_account.lamports = account.lamports;
let default_account = Account {
lamports: account.lamports,
..Account::default()
};
assert_eq!(default_account, account);
}
}
@@ -3443,8 +3449,10 @@ pub mod tests {
create_account(&db, &mut pubkeys, 0, 1, 0, 0);
let ancestors = vec![(0, 0)].into_iter().collect();
let account = db.load_slow(&ancestors, &pubkeys[0]).unwrap();
let mut default_account = Account::default();
default_account.lamports = 1;
let default_account = Account {
lamports: 1,
..Account::default()
};
assert_eq!((default_account, 0), account);
}
@@ -4434,7 +4442,7 @@ pub mod tests {
db.print_accounts_stats("pre");
let slots: HashSet<Slot> = HashSet::from_iter(vec![1].into_iter());
let slots: HashSet<Slot> = vec![1].into_iter().collect();
let purge_keys = vec![(key1, slots)];
let (_reclaims, dead_keys) = db.purge_keys_exact(purge_keys);
@@ -5242,7 +5250,7 @@ pub mod tests {
accounts.reset_uncleaned_roots();
let mut actual_slots = accounts.shrink_candidate_slots.lock().unwrap().clone();
actual_slots.sort();
actual_slots.sort_unstable();
assert_eq!(actual_slots, vec![0, 1, 2]);
accounts.accounts_index.clear_roots();
@@ -5435,7 +5443,7 @@ pub mod tests {
store_counts.insert(3, (1, HashSet::from_iter(vec![key2])));
AccountsDB::calc_delete_dependencies(&purges, &mut store_counts);
let mut stores: Vec<_> = store_counts.keys().cloned().collect();
stores.sort();
stores.sort_unstable();
for store in &stores {
info!(
"store: {:?} : {:?}",

View File

@@ -196,12 +196,8 @@ impl<T: 'static + Clone> AccountsIndex<T> {
AccountsIndexIterator::new(&self.account_maps, range)
}
fn do_checked_scan_accounts<'a, F, R>(
&'a self,
ancestors: &Ancestors,
func: F,
range: Option<R>,
) where
fn do_checked_scan_accounts<F, R>(&self, ancestors: &Ancestors, func: F, range: Option<R>)
where
F: FnMut(&Pubkey, (&T, Slot)),
R: RangeBounds<Pubkey>,
{
@@ -349,12 +345,8 @@ impl<T: 'static + Clone> AccountsIndex<T> {
}
}
fn do_unchecked_scan_accounts<'a, F, R>(
&'a self,
ancestors: &Ancestors,
func: F,
range: Option<R>,
) where
fn do_unchecked_scan_accounts<F, R>(&self, ancestors: &Ancestors, func: F, range: Option<R>)
where
F: FnMut(&Pubkey, (&T, Slot)),
R: RangeBounds<Pubkey>,
{
@@ -364,8 +356,8 @@ impl<T: 'static + Clone> AccountsIndex<T> {
// Scan accounts and return latest version of each account that is either:
// 1) rooted or
// 2) present in ancestors
fn do_scan_accounts<'a, F, R>(
&'a self,
fn do_scan_accounts<F, R>(
&self,
ancestors: &Ancestors,
mut func: F,
range: Option<R>,
@@ -922,7 +914,7 @@ mod tests {
run_test_range_indexes(
&index,
&pubkeys,
Some(ITER_BATCH_SIZE - 1 as usize),
Some(ITER_BATCH_SIZE - 1_usize),
Some(2 * ITER_BATCH_SIZE as usize + 1),
);
}

View File

@@ -397,7 +397,7 @@ impl AppendVec {
self.path.clone()
}
pub fn accounts<'a>(&'a self, mut start: usize) -> Vec<StoredAccount<'a>> {
pub fn accounts(&self, mut start: usize) -> Vec<StoredAccount> {
let mut accounts = vec![];
while let Some((account, next)) = self.get_account(start) {
accounts.push(account);
@@ -685,7 +685,7 @@ pub mod tests {
let pubkey = solana_sdk::pubkey::new_rand();
let owner = Pubkey::default();
let data_len = 3 as u64;
let data_len = 3_u64;
let mut account = Account::new(0, data_len as usize, &owner);
account.data = b"abc".to_vec();
let stored_meta = StoredMeta {

View File

@@ -832,6 +832,7 @@ pub struct Bank {
bpf_compute_budget: Option<BpfComputeBudget>,
/// Builtin programs activated dynamically by feature
#[allow(clippy::rc_buffer)]
feature_builtins: Arc<Vec<(Builtin, Pubkey, ActivationType)>>,
/// Last time when the cluster info vote listener has synced with this bank
@@ -887,9 +888,9 @@ impl Bank {
additional_builtins: Option<&Builtins>,
) -> Self {
let mut bank = Self::default();
bank.ancestors.insert(bank.slot(), 0);
bank.transaction_debug_keys = debug_keys;
bank.cluster_type = Some(genesis_config.cluster_type);
bank.ancestors.insert(bank.slot(), 0);
bank.rc.accounts = Arc::new(Accounts::new(paths, &genesis_config.cluster_type));
bank.process_genesis_config(genesis_config);
@@ -1257,6 +1258,7 @@ impl Bank {
}
let mut ancestors: Vec<_> = roots.into_iter().collect();
#[allow(clippy::stable_sort_primitive)]
ancestors.sort();
ancestors
}
@@ -4940,13 +4942,13 @@ pub(crate) mod tests {
impl Bank {
fn epoch_stake_keys(&self) -> Vec<Epoch> {
let mut keys: Vec<Epoch> = self.epoch_stakes.keys().copied().collect();
keys.sort();
keys.sort_unstable();
keys
}
fn epoch_stake_key_info(&self) -> (Epoch, Epoch, usize) {
let mut keys: Vec<Epoch> = self.epoch_stakes.keys().copied().collect();
keys.sort();
keys.sort_unstable();
(*keys.first().unwrap(), *keys.last().unwrap(), keys.len())
}
}
@@ -9521,6 +9523,7 @@ pub(crate) mod tests {
let (genesis_config, mint_keypair) = create_genesis_config(500);
let mut bank = Bank::new(&genesis_config);
#[allow(clippy::unnecessary_wraps)]
fn mock_process_instruction(
_program_id: &Pubkey,
_keyed_accounts: &[KeyedAccount],
@@ -9704,6 +9707,7 @@ pub(crate) mod tests {
assert_eq!(result, Err(TransactionError::SanitizeFailure));
}
#[allow(clippy::unnecessary_wraps)]
fn mock_ok_vote_processor(
_pubkey: &Pubkey,
_ka: &[KeyedAccount],
@@ -10035,7 +10039,7 @@ pub(crate) mod tests {
let mut consumed_budgets = (0..3)
.map(|_| bank.process_stale_slot_with_budget(0, force_to_return_alive_account))
.collect::<Vec<_>>();
consumed_budgets.sort();
consumed_budgets.sort_unstable();
// consumed_budgets represents the count of alive accounts in the three slots 0,1,2
assert_eq!(consumed_budgets, vec![0, 1, 9]);
}
@@ -10136,6 +10140,7 @@ pub(crate) mod tests {
fn test_add_builtin_no_overwrite() {
let (genesis_config, _mint_keypair) = create_genesis_config(100_000);
#[allow(clippy::unnecessary_wraps)]
fn mock_ix_processor(
_pubkey: &Pubkey,
_ka: &[KeyedAccount],
@@ -10181,6 +10186,7 @@ pub(crate) mod tests {
fn test_add_builtin_loader_no_overwrite() {
let (genesis_config, _mint_keypair) = create_genesis_config(100_000);
#[allow(clippy::unnecessary_wraps)]
fn mock_ix_processor(
_pubkey: &Pubkey,
_ka: &[KeyedAccount],

View File

@@ -254,8 +254,8 @@ mod test {
fn test_random() {
let mut b1: Bloom<Hash> = Bloom::random(10, 0.1, 100);
let mut b2: Bloom<Hash> = Bloom::random(10, 0.1, 100);
b1.keys.sort();
b2.keys.sort();
b1.keys.sort_unstable();
b2.keys.sort_unstable();
assert_ne!(b1.keys, b2.keys);
}
// Bloom filter math in python

View File

@@ -255,6 +255,7 @@ fn unpack_genesis<A: Read, P: AsRef<Path>>(
fn is_valid_genesis_archive_entry(parts: &[&str], kind: tar::EntryType) -> bool {
trace!("validating: {:?} {:?}", parts, kind);
#[allow(clippy::match_like_matches_macro)]
match (parts, kind) {
(["genesis.bin"], GNUSparse) => true,
(["genesis.bin"], Regular) => true,

View File

@@ -422,7 +422,7 @@ impl MessageProcessor {
instruction: &'a CompiledInstruction,
executable_accounts: &'a [(Pubkey, RefCell<Account>)],
accounts: &'a [Rc<RefCell<Account>>],
) -> Result<Vec<KeyedAccount<'a>>, InstructionError> {
) -> Vec<KeyedAccount<'a>> {
let mut keyed_accounts = create_keyed_readonly_accounts(&executable_accounts);
let mut keyed_accounts2: Vec<_> = instruction
.accounts
@@ -440,7 +440,7 @@ impl MessageProcessor {
})
.collect();
keyed_accounts.append(&mut keyed_accounts2);
Ok(keyed_accounts)
keyed_accounts
}
/// Process an instruction
@@ -604,7 +604,7 @@ impl MessageProcessor {
// Construct keyed accounts
let keyed_accounts =
Self::create_keyed_accounts(message, instruction, executable_accounts, accounts)?;
Self::create_keyed_accounts(message, instruction, executable_accounts, accounts);
// Invoke callee
invoke_context.push(instruction.program_id(&message.account_keys))?;
@@ -794,7 +794,7 @@ impl MessageProcessor {
feature_set,
);
let keyed_accounts =
Self::create_keyed_accounts(message, instruction, executable_accounts, accounts)?;
Self::create_keyed_accounts(message, instruction, executable_accounts, accounts);
self.process_instruction(&keyed_accounts, &instruction.data, &mut invoke_context)?;
Self::verify(
message,
@@ -854,7 +854,6 @@ mod tests {
message::Message,
native_loader::create_loadable_account,
};
use std::iter::FromIterator;
#[test]
fn test_invoke_context() {
@@ -920,8 +919,7 @@ mod tests {
// modify account owned by the program
accounts[owned_index].borrow_mut().data[0] = (MAX_DEPTH + owned_index) as u8;
let mut these_accounts =
Vec::from_iter(accounts[not_owned_index..owned_index + 1].iter().cloned());
let mut these_accounts = accounts[not_owned_index..owned_index + 1].to_vec();
these_accounts.push(Rc::new(RefCell::new(Account::new(
1,
1,
@@ -1805,6 +1803,7 @@ mod tests {
#[test]
fn test_debug() {
let mut message_processor = MessageProcessor::default();
#[allow(clippy::unnecessary_wraps)]
fn mock_process_instruction(
_program_id: &Pubkey,
_keyed_accounts: &[KeyedAccount],
@@ -1813,6 +1812,7 @@ mod tests {
) -> Result<(), InstructionError> {
Ok(())
}
#[allow(clippy::unnecessary_wraps)]
fn mock_ix_processor(
_pubkey: &Pubkey,
_ka: &[KeyedAccount],

View File

@@ -127,9 +127,11 @@ mod tests {
let new_epoch = 3;
let (mut created_account, mut existing_account) = {
let mut account = Account::default();
account.lamports = old_lamports;
account.rent_epoch = old_epoch;
let account = Account {
lamports: old_lamports,
rent_epoch: old_epoch,
..Account::default()
};
(account.clone(), account)
};

View File

@@ -261,7 +261,7 @@ mod test_bank_serialize {
// These some what long test harness is required to freeze the ABI of
// Bank's serialization due to versioned nature
#[frozen_abi(digest = "8bNY87hccyDYCRar1gM3NSvpvtiUM3W3rGeJLJayz42e")]
#[frozen_abi(digest = "5NHt6PLRJPWJH9FUcweSsUWgN5hXMfXj1BduDrDHH73w")]
#[derive(Serialize, AbiExample)]
pub struct BankAbiTestWrapperFuture {
#[serde(serialize_with = "wrapper_future")]

View File

@@ -272,7 +272,7 @@ pub mod tests {
)
}
// add stake to a vote_pubkey ( stake )
// add stake to a vote_pubkey ( stake )
pub fn create_warming_stake_account(
stake: u64,
epoch: Epoch,
@@ -295,8 +295,10 @@ pub mod tests {
#[test]
fn test_stakes_basic() {
for i in 0..4 {
let mut stakes = Stakes::default();
stakes.epoch = i;
let mut stakes = Stakes {
epoch: i,
..Stakes::default()
};
let ((vote_pubkey, vote_account), (stake_pubkey, mut stake_account)) =
create_staked_node_accounts(10);
@@ -372,8 +374,10 @@ pub mod tests {
#[test]
fn test_stakes_vote_account_disappear_reappear() {
let mut stakes = Stakes::default();
stakes.epoch = 4;
let mut stakes = Stakes {
epoch: 4,
..Stakes::default()
};
let ((vote_pubkey, mut vote_account), (stake_pubkey, stake_account)) =
create_staked_node_accounts(10);
@@ -406,8 +410,10 @@ pub mod tests {
#[test]
fn test_stakes_change_delegate() {
let mut stakes = Stakes::default();
stakes.epoch = 4;
let mut stakes = Stakes {
epoch: 4,
..Stakes::default()
};
let ((vote_pubkey, vote_account), (stake_pubkey, stake_account)) =
create_staked_node_accounts(10);
@@ -450,8 +456,10 @@ pub mod tests {
}
#[test]
fn test_stakes_multiple_stakers() {
let mut stakes = Stakes::default();
stakes.epoch = 4;
let mut stakes = Stakes {
epoch: 4,
..Stakes::default()
};
let ((vote_pubkey, vote_account), (stake_pubkey, stake_account)) =
create_staked_node_accounts(10);
@@ -500,8 +508,10 @@ pub mod tests {
#[test]
fn test_stakes_not_delegate() {
let mut stakes = Stakes::default();
stakes.epoch = 4;
let mut stakes = Stakes {
epoch: 4,
..Stakes::default()
};
let ((vote_pubkey, vote_account), (stake_pubkey, stake_account)) =
create_staked_node_accounts(10);

View File

@@ -226,7 +226,7 @@ impl<T: Serialize + Clone> StatusCache<T> {
(
*slot,
self.roots.contains(slot),
self.slot_deltas.get(slot).unwrap_or_else(|| &empty).clone(),
self.slot_deltas.get(slot).unwrap_or(&empty).clone(),
)
})
.collect()