Skip to content

Commit

Permalink
Cleanup runtime use syntax (solana-labs#8002)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmay authored Jan 29, 2020
1 parent 4a07413 commit 83718a3
Show file tree
Hide file tree
Showing 26 changed files with 201 additions and 184 deletions.
10 changes: 5 additions & 5 deletions runtime/benches/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions runtime/benches/accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 10 additions & 6 deletions runtime/benches/append_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
28 changes: 13 additions & 15 deletions runtime/benches/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [
Expand Down
6 changes: 4 additions & 2 deletions runtime/benches/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions runtime/benches/status_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()>;
Expand Down
3 changes: 1 addition & 2 deletions runtime/benches/transaction_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
97 changes: 55 additions & 42 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
52 changes: 28 additions & 24 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]
Expand Down
6 changes: 4 additions & 2 deletions runtime/src/accounts_index.rs
Original file line number Diff line number Diff line change
@@ -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)>;
Expand Down
10 changes: 4 additions & 6 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
3 changes: 1 addition & 2 deletions runtime/src/bank_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 2 additions & 5 deletions runtime/src/blockhash_queue.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 1 addition & 3 deletions runtime/src/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading

0 comments on commit 83718a3

Please sign in to comment.