Cleanup runtime use syntax (#8002)

This commit is contained in:
Jack May 2020-01-28 17:03:20 -08:00 committed by GitHub
parent 4a074133f7
commit 83718a3b3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 201 additions and 184 deletions

View File

@ -2,11 +2,11 @@
extern crate test;
use solana_runtime::accounts::{create_test_accounts, Accounts};
use solana_runtime::bank::*;
use solana_sdk::account::Account;
use solana_sdk::genesis_config::create_genesis_config;
use solana_sdk::pubkey::Pubkey;
use solana_runtime::{
accounts::{create_test_accounts, Accounts},
bank::*,
};
use solana_sdk::{account::Account, genesis_config::create_genesis_config, pubkey::Pubkey};
use std::{path::PathBuf, sync::Arc};
use test::Bencher;

View File

@ -3,8 +3,7 @@
extern crate test;
use rand::{thread_rng, Rng};
use solana_runtime::accounts_db::AccountInfo;
use solana_runtime::accounts_index::AccountsIndex;
use solana_runtime::{accounts_db::AccountInfo, accounts_index::AccountsIndex};
use solana_sdk::pubkey::Pubkey;
use test::Bencher;

View File

@ -2,13 +2,17 @@
extern crate test;
use rand::{thread_rng, Rng};
use solana_runtime::append_vec::test_utils::{create_test_account, get_append_vec_path};
use solana_runtime::append_vec::AppendVec;
use solana_runtime::append_vec::{
test_utils::{create_test_account, get_append_vec_path},
AppendVec,
};
use solana_sdk::hash::Hash;
use std::sync::{Arc, Mutex};
use std::thread::sleep;
use std::thread::spawn;
use std::time::Duration;
use std::{
sync::{Arc, Mutex},
thread::sleep,
thread::spawn,
time::Duration,
};
use test::Bencher;
#[bench]

View File

@ -3,21 +3,19 @@
extern crate test;
use log::*;
use solana_runtime::bank::*;
use solana_runtime::bank_client::BankClient;
use solana_runtime::loader_utils::create_invoke_instruction;
use solana_sdk::account::KeyedAccount;
use solana_sdk::client::AsyncClient;
use solana_sdk::client::SyncClient;
use solana_sdk::clock::MAX_RECENT_BLOCKHASHES;
use solana_sdk::genesis_config::create_genesis_config;
use solana_sdk::instruction::InstructionError;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::transaction::Transaction;
use std::sync::Arc;
use std::thread::sleep;
use std::time::Duration;
use solana_runtime::{bank::*, bank_client::BankClient, loader_utils::create_invoke_instruction};
use solana_sdk::{
account::KeyedAccount,
client::AsyncClient,
client::SyncClient,
clock::MAX_RECENT_BLOCKHASHES,
genesis_config::create_genesis_config,
instruction::InstructionError,
pubkey::Pubkey,
signature::{Keypair, KeypairUtil},
transaction::Transaction,
};
use std::{sync::Arc, thread::sleep, time::Duration};
use test::Bencher;
const BUILTIN_PROGRAM_ID: [u8; 32] = [

View File

@ -4,8 +4,10 @@ extern crate test;
use bv::BitVec;
use fnv::FnvHasher;
use solana_runtime::bloom::{Bloom, BloomHashIndex};
use solana_sdk::hash::{hash, Hash};
use solana_sdk::signature::Signature;
use solana_sdk::{
hash::{hash, Hash},
signature::Signature,
};
use std::collections::HashSet;
use std::hash::Hasher;
use test::Bencher;

View File

@ -4,8 +4,10 @@ extern crate test;
use bincode::serialize;
use solana_runtime::status_cache::*;
use solana_sdk::hash::{hash, Hash};
use solana_sdk::signature::Signature;
use solana_sdk::{
hash::{hash, Hash},
signature::Signature,
};
use test::Bencher;
type BankStatusCache = StatusCache<()>;

View File

@ -2,8 +2,7 @@
extern crate test;
use rand::seq::SliceRandom;
use rand::thread_rng;
use rand::{seq::SliceRandom, thread_rng};
use solana_runtime::transaction_utils::OrderedIterator;
use test::Bencher;

View File

@ -1,30 +1,35 @@
use crate::accounts_db::{
AccountInfo, AccountStorage, AccountsDB, AppendVecId, BankHashInfo, ErrorCounters,
use crate::{
accounts_db::{
AccountInfo, AccountStorage, AccountsDB, AppendVecId, BankHashInfo, ErrorCounters,
},
accounts_index::AccountsIndex,
append_vec::StoredAccount,
bank::{HashAgeKind, TransactionProcessResult},
blockhash_queue::BlockhashQueue,
nonce_utils::prepare_if_nonce_account,
rent_collector::RentCollector,
system_instruction_processor::{get_system_account_kind, SystemAccountKind},
transaction_utils::OrderedIterator,
};
use crate::accounts_index::AccountsIndex;
use crate::append_vec::StoredAccount;
use crate::bank::{HashAgeKind, TransactionProcessResult};
use crate::blockhash_queue::BlockhashQueue;
use crate::nonce_utils::prepare_if_nonce_account;
use crate::rent_collector::RentCollector;
use crate::system_instruction_processor::{get_system_account_kind, SystemAccountKind};
use log::*;
use rayon::slice::ParallelSliceMut;
use solana_sdk::account::Account;
use solana_sdk::bank_hash::BankHash;
use solana_sdk::clock::Slot;
use solana_sdk::hash::Hash;
use solana_sdk::native_loader;
use solana_sdk::nonce_state::NonceState;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::transaction::Result;
use solana_sdk::transaction::{Transaction, TransactionError};
use std::collections::{HashMap, HashSet};
use std::io::{BufReader, Error as IOError, Read};
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex, RwLock};
use crate::transaction_utils::OrderedIterator;
use solana_sdk::{
account::Account,
bank_hash::BankHash,
clock::Slot,
hash::Hash,
native_loader,
nonce_state::NonceState,
pubkey::Pubkey,
transaction::Result,
transaction::{Transaction, TransactionError},
};
use std::{
collections::{HashMap, HashSet},
io::{BufReader, Error as IOError, Read},
path::{Path, PathBuf},
sync::{Arc, Mutex, RwLock},
};
#[derive(Default, Debug)]
struct ReadonlyLock {
@ -648,26 +653,34 @@ mod tests {
// TODO: all the bank tests are bank specific, issue: 2194
use super::*;
use crate::accounts_db::tests::copy_append_vecs;
use crate::accounts_db::{get_temp_accounts_paths, AccountsDBSerialize};
use crate::bank::HashAgeKind;
use crate::rent_collector::RentCollector;
use crate::{
accounts_db::{
tests::copy_append_vecs,
{get_temp_accounts_paths, AccountsDBSerialize},
},
bank::HashAgeKind,
rent_collector::RentCollector,
};
use bincode::serialize_into;
use rand::{thread_rng, Rng};
use solana_sdk::account::Account;
use solana_sdk::epoch_schedule::EpochSchedule;
use solana_sdk::fee_calculator::FeeCalculator;
use solana_sdk::hash::Hash;
use solana_sdk::instruction::CompiledInstruction;
use solana_sdk::message::Message;
use solana_sdk::nonce_state;
use solana_sdk::rent::Rent;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::system_program;
use solana_sdk::transaction::Transaction;
use std::io::Cursor;
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
use std::{thread, time};
use solana_sdk::{
account::Account,
epoch_schedule::EpochSchedule,
fee_calculator::FeeCalculator,
hash::Hash,
instruction::CompiledInstruction,
message::Message,
nonce_state,
rent::Rent,
signature::{Keypair, KeypairUtil},
system_program,
transaction::Transaction,
};
use std::{
io::Cursor,
sync::atomic::{AtomicBool, AtomicU64, Ordering},
{thread, time},
};
use tempfile::TempDir;
fn load_accounts_with_fee_and_rent(

View File

@ -18,33 +18,39 @@
//! tracks the number of commits to the entire data store. So the latest
//! commit for each slot entry would be indexed.
use crate::accounts_index::AccountsIndex;
use crate::append_vec::{AppendVec, StoredAccount, StoredMeta};
use crate::bank::deserialize_from_snapshot;
use crate::{
accounts_index::AccountsIndex,
append_vec::{AppendVec, StoredAccount, StoredMeta},
bank::deserialize_from_snapshot,
};
use bincode::{deserialize_from, serialize_into};
use byteorder::{ByteOrder, LittleEndian};
use fs_extra::dir::CopyOptions;
use log::*;
use rand::{thread_rng, Rng};
use rayon::prelude::*;
use rayon::ThreadPool;
use serde::de::{MapAccess, Visitor};
use serde::ser::{SerializeMap, Serializer};
use serde::{Deserialize, Serialize};
use rayon::{prelude::*, ThreadPool};
use serde::{
de::{MapAccess, Visitor},
ser::{SerializeMap, Serializer},
Deserialize, Serialize,
};
use solana_measure::measure::Measure;
use solana_rayon_threadlimit::get_thread_count;
use solana_sdk::account::Account;
use solana_sdk::bank_hash::BankHash;
use solana_sdk::clock::{Epoch, Slot};
use solana_sdk::hash::{Hash, Hasher};
use solana_sdk::pubkey::Pubkey;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::io::{BufReader, Cursor, Error as IOError, ErrorKind, Read, Result as IOResult};
use std::path::Path;
use std::path::PathBuf;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, RwLock};
use solana_sdk::{
account::Account,
bank_hash::BankHash,
clock::{Epoch, Slot},
hash::{Hash, Hasher},
pubkey::Pubkey,
};
use std::{
collections::{HashMap, HashSet},
fmt,
io::{BufReader, Cursor, Error as IOError, ErrorKind, Read, Result as IOResult},
path::{Path, PathBuf},
sync::atomic::{AtomicUsize, Ordering},
sync::{Arc, RwLock},
};
use tempfile::TempDir;
pub const DEFAULT_FILE_SIZE: u64 = 4 * 1024 * 1024;
@ -1320,10 +1326,8 @@ pub mod tests {
use assert_matches::assert_matches;
use bincode::serialize_into;
use rand::{thread_rng, Rng};
use solana_sdk::account::Account;
use solana_sdk::hash::HASH_BYTES;
use std::fs;
use std::str::FromStr;
use solana_sdk::{account::Account, hash::HASH_BYTES};
use std::{fs, str::FromStr};
use tempfile::TempDir;
#[test]

View File

@ -1,6 +1,8 @@
use solana_sdk::pubkey::Pubkey;
use std::collections::{HashMap, HashSet};
use std::sync::{RwLock, RwLockReadGuard};
use std::{
collections::{HashMap, HashSet},
sync::{RwLock, RwLockReadGuard},
};
pub type Slot = u64;
type SlotList<T> = Vec<(Slot, T)>;

View File

@ -2188,29 +2188,27 @@ impl From<LegacyBank0223> for Bank {
mod tests {
use super::*;
use crate::{
accounts_db::get_temp_accounts_paths,
accounts_db::tests::copy_append_vecs,
accounts_db::{get_temp_accounts_paths, tests::copy_append_vecs},
genesis_utils::{
create_genesis_config_with_leader, GenesisConfigInfo, BOOTSTRAP_VALIDATOR_LAMPORTS,
},
status_cache::MAX_CACHE_ENTRIES,
};
use bincode::{serialize_into, serialized_size};
use solana_sdk::instruction::AccountMeta;
use solana_sdk::system_program::solana_system_program;
use solana_sdk::{
account::KeyedAccount,
account_utils::StateMut,
clock::DEFAULT_TICKS_PER_SLOT,
epoch_schedule::MINIMUM_SLOTS_PER_EPOCH,
genesis_config::create_genesis_config,
instruction::{CompiledInstruction, Instruction, InstructionError},
instruction::{AccountMeta, CompiledInstruction, Instruction, InstructionError},
message::{Message, MessageHeader},
nonce_state,
poh_config::PohConfig,
rent::Rent,
signature::{Keypair, KeypairUtil},
system_instruction, system_program,
system_instruction,
system_program::{self, solana_system_program},
sysvar::{fees::Fees, rewards::Rewards},
timing::duration_as_s,
};

View File

@ -274,8 +274,7 @@ impl BankClient {
#[cfg(test)]
mod tests {
use super::*;
use solana_sdk::genesis_config::create_genesis_config;
use solana_sdk::instruction::AccountMeta;
use solana_sdk::{genesis_config::create_genesis_config, instruction::AccountMeta};
#[test]
fn test_bank_client_new_with_keypairs() {

View File

@ -1,7 +1,5 @@
use serde::{Deserialize, Serialize};
use solana_sdk::fee_calculator::FeeCalculator;
use solana_sdk::hash::Hash;
use solana_sdk::timing::timestamp;
use solana_sdk::{fee_calculator::FeeCalculator, hash::Hash, timing::timestamp};
use std::collections::HashMap;
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
@ -122,8 +120,7 @@ impl BlockhashQueue {
mod tests {
use super::*;
use bincode::serialize;
use solana_sdk::clock::MAX_RECENT_BLOCKHASHES;
use solana_sdk::hash::hash;
use solana_sdk::{clock::MAX_RECENT_BLOCKHASHES, hash::hash};
#[test]
fn test_register_hash() {

View File

@ -3,9 +3,7 @@ use bv::BitVec;
use fnv::FnvHasher;
use rand::{self, Rng};
use serde::{Deserialize, Serialize};
use std::cmp;
use std::hash::Hasher;
use std::marker::PhantomData;
use std::{cmp, hash::Hasher, marker::PhantomData};
/// Generate a stable hash of `self` for each `hash_index`
/// Best effort can be made for uniqueness of each hash.

View File

@ -1,11 +1,13 @@
use serde::Serialize;
use solana_sdk::client::Client;
use solana_sdk::instruction::{AccountMeta, Instruction};
use solana_sdk::loader_instruction;
use solana_sdk::message::Message;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::system_instruction;
use solana_sdk::{
client::Client,
instruction::{AccountMeta, Instruction},
loader_instruction,
message::Message,
pubkey::Pubkey,
signature::{Keypair, KeypairUtil},
system_instruction,
};
pub fn load_program<T: Client>(
bank_client: &T,

View File

@ -1,18 +1,17 @@
use crate::native_loader;
use crate::system_instruction_processor;
use serde::{Deserialize, Serialize};
use solana_sdk::account::{create_keyed_readonly_accounts, Account, KeyedAccount};
use solana_sdk::clock::Epoch;
use solana_sdk::instruction::{CompiledInstruction, InstructionError};
use solana_sdk::instruction_processor_utils;
use solana_sdk::message::Message;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::system_program;
use solana_sdk::transaction::TransactionError;
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
use std::sync::RwLock;
use solana_sdk::{
account::{create_keyed_readonly_accounts, Account, KeyedAccount},
clock::Epoch,
instruction::{CompiledInstruction, InstructionError},
instruction_processor_utils,
message::Message,
pubkey::Pubkey,
system_program,
transaction::TransactionError,
};
use std::{cell::RefCell, collections::HashMap, rc::Rc, sync::RwLock};
#[cfg(unix)]
use libloading::os::unix::*;
@ -342,9 +341,11 @@ pub fn is_zeroed(buf: &[u8]) -> bool {
#[cfg(test)]
mod tests {
use super::*;
use solana_sdk::instruction::{AccountMeta, Instruction, InstructionError};
use solana_sdk::message::Message;
use solana_sdk::native_loader::create_loadable_account;
use solana_sdk::{
instruction::{AccountMeta, Instruction, InstructionError},
message::Message,
native_loader::create_loadable_account,
};
#[test]
fn test_is_zeroed() {

View File

@ -5,13 +5,11 @@ use libloading::os::unix::*;
#[cfg(windows)]
use libloading::os::windows::*;
use log::*;
use solana_sdk::account::KeyedAccount;
use solana_sdk::instruction::InstructionError;
use solana_sdk::instruction_processor_utils;
use solana_sdk::pubkey::Pubkey;
use std::env;
use std::path::PathBuf;
use std::str;
use solana_sdk::{
account::KeyedAccount, instruction::InstructionError, instruction_processor_utils,
pubkey::Pubkey,
};
use std::{env, path::PathBuf, str};
/// Dynamic link library prefixes
#[cfg(unix)]

View File

@ -1,5 +1,7 @@
use std::fmt;
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
use std::{
fmt,
sync::atomic::{AtomicBool, AtomicU64, Ordering},
};
struct U64Visitor;
impl<'a> serde::de::Visitor<'a> for U64Visitor {

View File

@ -1,9 +1,8 @@
//! Stakes serve as a cache of stake and vote accounts to derive
//! node stakes
use solana_sdk::account::Account;
use solana_sdk::clock::Epoch;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::sysvar::stake_history::StakeHistory;
use solana_sdk::{
account::Account, clock::Epoch, pubkey::Pubkey, sysvar::stake_history::StakeHistory,
};
use solana_stake_program::stake_state::{new_stake_history_entry, Delegation, StakeState};
use solana_vote_program::vote_state::VoteState;
use std::collections::HashMap;

View File

@ -1,11 +1,15 @@
use log::*;
use rand::{thread_rng, Rng};
use serde::Serialize;
use solana_sdk::clock::{Slot, MAX_RECENT_BLOCKHASHES};
use solana_sdk::hash::Hash;
use solana_sdk::signature::Signature;
use std::collections::{HashMap, HashSet};
use std::sync::{Arc, Mutex};
use solana_sdk::{
clock::{Slot, MAX_RECENT_BLOCKHASHES},
hash::Hash,
signature::Signature,
};
use std::{
collections::{HashMap, HashSet},
sync::{Arc, Mutex},
};
pub const MAX_CACHE_ENTRIES: usize = MAX_RECENT_BLOCKHASHES;
const CACHED_SIGNATURE_SIZE: usize = 20;

View File

@ -1,7 +1,5 @@
use crate::bank::Bank;
use solana_sdk::account::Account;
use solana_sdk::account_utils::StateMut;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::{account::Account, account_utils::StateMut, pubkey::Pubkey};
use solana_storage_program::storage_contract::StorageContract;
use std::collections::{HashMap, HashSet};
@ -82,10 +80,12 @@ pub fn archiver_accounts(bank: &Bank) -> HashMap<Pubkey, Account> {
pub(crate) mod tests {
use super::*;
use crate::bank_client::BankClient;
use solana_sdk::client::SyncClient;
use solana_sdk::genesis_config::create_genesis_config;
use solana_sdk::message::Message;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::{
client::SyncClient,
genesis_config::create_genesis_config,
message::Message,
signature::{Keypair, KeypairUtil},
};
use solana_storage_program::{
storage_contract::{StorageAccount, STORAGE_ACCOUNT_SPACE},
storage_instruction::{self, StorageAccountType},

View File

@ -1,5 +1,4 @@
use log::*;
use solana_sdk::{
account::{get_signers, Account, KeyedAccount},
account_utils::StateMut,
@ -13,7 +12,6 @@ use solana_sdk::{
system_program,
sysvar::{self, recent_blockhashes::RecentBlockhashes, rent::Rent, Sysvar},
};
use std::collections::HashSet;
// represents an address that may or may not have been generated

View File

@ -57,9 +57,11 @@ impl<'a, 'b> Drop for TransactionBatch<'a, 'b> {
mod tests {
use super::*;
use crate::genesis_utils::{create_genesis_config_with_leader, GenesisConfigInfo};
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::system_transaction;
use solana_sdk::{
pubkey::Pubkey,
signature::{Keypair, KeypairUtil},
system_transaction,
};
#[test]
fn test_transaction_batch() {

View File

@ -1,9 +1,6 @@
use solana_runtime::bank::Bank;
use solana_sdk::genesis_config::create_genesis_config;
use solana_sdk::hash::hash;
use solana_sdk::pubkey::Pubkey;
use std::sync::Arc;
use std::thread::Builder;
use solana_sdk::{genesis_config::create_genesis_config, hash::hash, pubkey::Pubkey};
use std::{sync::Arc, thread::Builder};
#[test]
fn test_race_register_tick_freeze() {

View File

@ -1,10 +1,10 @@
use solana_runtime::bank::Bank;
use solana_runtime::bank_client::BankClient;
use solana_runtime::loader_utils::create_invoke_instruction;
use solana_sdk::client::SyncClient;
use solana_sdk::genesis_config::create_genesis_config;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::KeypairUtil;
use solana_runtime::{
bank::Bank, bank_client::BankClient, loader_utils::create_invoke_instruction,
};
use solana_sdk::{
client::SyncClient, genesis_config::create_genesis_config, pubkey::Pubkey,
signature::KeypairUtil,
};
#[test]
fn test_program_native_noop() {

View File

@ -26,8 +26,7 @@ use solana_storage_program::{
storage_instruction::{self, StorageAccountType},
storage_processor::process_instruction,
};
use std::collections::HashMap;
use std::sync::Arc;
use std::{collections::HashMap, sync::Arc};
const TICKS_IN_SEGMENT: u64 = DEFAULT_SLOTS_PER_SEGMENT * DEFAULT_TICKS_PER_SLOT;