Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all usage of Default::default() and ban it in future commits #2711

Merged
merged 3 commits into from
Feb 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bench-tps/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ pub fn fund_keys(client: &mut ThinClient, source: &Keypair, dests: &[Keypair], t
.map(|(k, m)| {
(
k.clone(),
SystemTransaction::new_move_many(k, &m, Default::default(), 0),
SystemTransaction::new_move_many(k, &m, Hash::default(), 0),
)
})
.collect();
Expand Down
5 changes: 3 additions & 2 deletions benches/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use solana::entry::Entry;
use solana::genesis_block::GenesisBlock;
use solana::last_id_queue::MAX_ENTRY_IDS;
use solana::packet::to_packets_chunked;
use solana::poh_service::PohServiceConfig;
use solana_sdk::hash::hash;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{KeypairUtil, Signature};
Expand Down Expand Up @@ -103,7 +104,7 @@ fn bench_banking_stage_multi_accounts(bencher: &mut Bencher) {
let (_stage, signal_receiver) = BankingStage::new(
&bank,
verified_receiver,
Default::default(),
PohServiceConfig::default(),
&genesis_block.last_id(),
std::u64::MAX,
genesis_block.bootstrap_leader_id,
Expand Down Expand Up @@ -212,7 +213,7 @@ fn bench_banking_stage_multi_programs(bencher: &mut Bencher) {
let (_stage, signal_receiver) = BankingStage::new(
&bank,
verified_receiver,
Default::default(),
PohServiceConfig::default(),
&genesis_block.last_id(),
std::u64::MAX,
genesis_block.bootstrap_leader_id,
Expand Down
4 changes: 2 additions & 2 deletions benches/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use test::Bencher;
#[ignore]
fn bench_bits_set(bencher: &mut Bencher) {
let mut bits: BitVec<u8> = BitVec::new_fill(false, 38_340_234 as u64);
let mut hasher: FnvHasher = Default::default();
let mut hasher = FnvHasher::default();

bencher.iter(|| {
let idx = hasher.finish() % bits.len();
Expand All @@ -30,7 +30,7 @@ fn bench_bits_set(bencher: &mut Bencher) {
#[ignore]
fn bench_bits_set_hasher(bencher: &mut Bencher) {
let bits: BitVec<u8> = BitVec::new_fill(false, 38_340_234 as u64);
let mut hasher: FnvHasher = Default::default();
let mut hasher = FnvHasher::default();

bencher.iter(|| {
let idx = hasher.finish() % bits.len();
Expand Down
15 changes: 12 additions & 3 deletions ci/nits.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@ set -e
cd "$(dirname "$0")/.."
source ci/_

# please don't print from --lib...
# Logging hygiene: Please don't print from --lib, use the `log` crate instead
declare prints=(
'print!'
'println!'
'eprint!'
'eprintln!'
)

if _ git grep "${prints[@]/#/-e }" src
then
if _ git grep "${prints[@]/#/-e }" src; then
exit 1
fi


# Code readability: please be explicit about the type instead of using
# Default::default()
#
# Ref: https://github.com/solana-labs/solana/issues/2630
if _ git grep 'Default::default()' -- '*.rs'; then
exit 1
fi

6 changes: 3 additions & 3 deletions programs/native/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ mod test {
#[test]
fn test_storage_tx() {
let keypair = Keypair::new();
let mut accounts = [(keypair.pubkey(), Default::default())];
let mut accounts = [(keypair.pubkey(), Account::default())];
let mut keyed_accounts = create_keyed_accounts(&mut accounts);
assert!(entrypoint(&id(), &mut keyed_accounts, &[], 42).is_err());
}
Expand Down Expand Up @@ -258,7 +258,7 @@ mod test {
#[test]
fn test_invalid_accounts_len() {
let keypair = Keypair::new();
let mut accounts = [Default::default()];
let mut accounts = [Account::default()];

let tx = StorageTransaction::new_mining_proof(
&keypair,
Expand All @@ -269,7 +269,7 @@ mod test {
);
assert!(test_transaction(&tx, &mut accounts).is_err());

let mut accounts = [Default::default(), Default::default(), Default::default()];
let mut accounts = [Account::default(), Account::default(), Account::default()];

assert!(test_transaction(&tx, &mut accounts).is_err());
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/budget_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ mod tests {
fn test_serialize_claim() {
let expr = BudgetExpr::Pay(Payment {
tokens: 0,
to: Default::default(),
to: Pubkey::default(),
});
let instruction = Instruction::NewBudget(expr);
let instructions = vec![transaction::Instruction::new(0, &instruction, vec![])];
let claim0 = Transaction {
account_keys: vec![],
last_id: Default::default(),
last_id: Hash::default(),
signatures: vec![],
program_ids: vec![],
instructions,
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/system_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ mod tests {
let t2 = Keypair::new();
let moves = vec![(t1.pubkey(), 1), (t2.pubkey(), 2)];

let tx = SystemTransaction::new_move_many(&from, &moves, Default::default(), 0);
let tx = SystemTransaction::new_move_many(&from, &moves, Hash::default(), 0);
assert_eq!(tx.account_keys[0], from.pubkey());
assert_eq!(tx.account_keys[1], t1.pubkey());
assert_eq!(tx.account_keys[2], t2.pubkey());
Expand Down
10 changes: 5 additions & 5 deletions sdk/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ mod tests {
let tx = Transaction::new_with_instructions(
&[&key],
&[key1, key2],
Default::default(),
Hash::default(),
0,
vec![prog1, prog2],
instructions,
Expand Down Expand Up @@ -447,7 +447,7 @@ mod tests {
let tx = Transaction::new_with_instructions(
&[&key],
&[],
Default::default(),
Hash::default(),
0,
vec![],
instructions,
Expand All @@ -461,12 +461,12 @@ mod tests {
let tx = Transaction::new_with_instructions(
&[&key],
&[],
Default::default(),
Hash::default(),
0,
vec![Default::default()],
vec![Pubkey::default()],
instructions,
);
assert_eq!(*tx.program_id(0), Default::default());
assert_eq!(*tx.program_id(0), Pubkey::default());
assert!(!tx.verify_refs());
}

Expand Down
16 changes: 8 additions & 8 deletions src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::counter::Counter;
use crate::entry::Entry;
use crate::packet::Packets;
use crate::poh_recorder::{PohRecorder, PohRecorderError};
use crate::poh_service::{Config, PohService};
use crate::poh_service::{PohService, PohServiceConfig};
use crate::result::{Error, Result};
use crate::service::Service;
use crate::sigverify_stage::VerifiedPackets;
Expand Down Expand Up @@ -51,7 +51,7 @@ impl BankingStage {
pub fn new(
bank: &Arc<Bank>,
verified_receiver: Receiver<VerifiedPackets>,
config: Config,
config: PohServiceConfig,
last_entry_id: &Hash,
max_tick_height: u64,
leader_id: Pubkey,
Expand Down Expand Up @@ -293,7 +293,7 @@ mod tests {
let (banking_stage, _entry_receiver) = BankingStage::new(
&bank,
verified_receiver,
Default::default(),
PohServiceConfig::default(),
&bank.last_id(),
std::u64::MAX,
genesis_block.bootstrap_leader_id,
Expand All @@ -315,7 +315,7 @@ mod tests {
let (banking_stage, entry_receiver) = BankingStage::new(
&bank,
verified_receiver,
Default::default(),
PohServiceConfig::default(),
&bank.last_id(),
std::u64::MAX,
genesis_block.bootstrap_leader_id,
Expand All @@ -338,7 +338,7 @@ mod tests {
let (banking_stage, entry_receiver) = BankingStage::new(
&bank,
verified_receiver,
Config::Sleep(Duration::from_millis(1)),
PohServiceConfig::Sleep(Duration::from_millis(1)),
&bank.last_id(),
std::u64::MAX,
genesis_block.bootstrap_leader_id,
Expand Down Expand Up @@ -367,7 +367,7 @@ mod tests {
let (banking_stage, entry_receiver) = BankingStage::new(
&bank,
verified_receiver,
Default::default(),
PohServiceConfig::default(),
&bank.last_id(),
std::u64::MAX,
genesis_block.bootstrap_leader_id,
Expand Down Expand Up @@ -425,7 +425,7 @@ mod tests {
let (banking_stage, entry_receiver) = BankingStage::new(
&bank,
verified_receiver,
Default::default(),
PohServiceConfig::default(),
&bank.last_id(),
std::u64::MAX,
genesis_block.bootstrap_leader_id,
Expand Down Expand Up @@ -494,7 +494,7 @@ mod tests {
let (banking_stage, _entry_receiver) = BankingStage::new(
&bank,
verified_receiver,
Default::default(),
PohServiceConfig::default(),
&bank.last_id(),
max_tick_height,
genesis_block.bootstrap_leader_id,
Expand Down
2 changes: 1 addition & 1 deletion src/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<T: BloomHashIndex> Bloom<T> {
Bloom {
keys,
bits,
_phantom: Default::default(),
_phantom: PhantomData::default(),
}
}
/// create filter optimal for num size given the `false_rate`
Expand Down
9 changes: 5 additions & 4 deletions src/fullnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::counter::Counter;
use crate::genesis_block::GenesisBlock;
use crate::gossip_service::GossipService;
use crate::leader_scheduler::LeaderSchedulerConfig;
use crate::poh_service::PohServiceConfig;
use crate::rpc::JsonRpcService;
use crate::rpc_pubsub::PubSubService;
use crate::service::Service;
Expand Down Expand Up @@ -77,8 +78,8 @@ impl Default for FullnodeConfig {
voting_disabled: false,
entry_stream: None,
storage_rotate_count: NUM_HASHES_FOR_STORAGE_ROTATE,
leader_scheduler_config: Default::default(),
ledger_config: Default::default(),
leader_scheduler_config: LeaderSchedulerConfig::default(),
ledger_config: BlocktreeConfig::default(),
}
}
}
Expand Down Expand Up @@ -271,7 +272,7 @@ impl Fullnode {
);
let tpu = Tpu::new(
&Arc::new(bank.copy_for_tpu()),
Default::default(),
PohServiceConfig::default(),
node.sockets
.tpu
.iter()
Expand Down Expand Up @@ -389,7 +390,7 @@ impl Fullnode {
self.to_validator_receiver = to_validator_receiver;
self.node_services.tpu.switch_to_leader(
&Arc::new(self.bank.copy_for_tpu()),
Default::default(),
PohServiceConfig::default(),
self.tpu_sockets
.iter()
.map(|s| s.try_clone().expect("Failed to clone TPU sockets"))
Expand Down
2 changes: 1 addition & 1 deletion src/leader_scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ impl LeaderScheduler {

impl Default for LeaderScheduler {
fn default() -> Self {
let config = Default::default();
let config = LeaderSchedulerConfig::default();
Self::new(&config)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub fn to_packets_chunked<T: Serialize>(xs: &[T], chunks: usize) -> Vec<SharedPa
p.write()
.unwrap()
.packets
.resize(x.len(), Default::default());
.resize(x.len(), Packet::default());
for (i, o) in x.iter().zip(p.write().unwrap().packets.iter_mut()) {
let mut wr = io::Cursor::new(&mut o.data[..]);
serialize_into(&mut wr, &i).expect("serialize request");
Expand Down
31 changes: 14 additions & 17 deletions src/poh_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::time::Duration;
pub const NUM_TICKS_PER_SECOND: usize = 10;

#[derive(Copy, Clone)]
pub enum Config {
pub enum PohServiceConfig {
/// * `Tick` - Run full PoH thread. Tick is a rough estimate of how many hashes to roll before
/// transmitting a new entry.
Tick(usize),
Expand All @@ -24,10 +24,10 @@ pub enum Config {
Sleep(Duration),
}

impl Default for Config {
fn default() -> Config {
impl Default for PohServiceConfig {
fn default() -> PohServiceConfig {
// TODO: Change this to Tick to enable PoH
Config::Sleep(Duration::from_millis(1000 / NUM_TICKS_PER_SECOND as u64))
PohServiceConfig::Sleep(Duration::from_millis(1000 / NUM_TICKS_PER_SECOND as u64))
}
}

Expand All @@ -48,7 +48,7 @@ impl PohService {

pub fn new(
poh_recorder: PohRecorder,
config: Config,
config: PohServiceConfig,
to_validator_sender: TpuRotationSender,
) -> Self {
// PohService is a headless producer, so when it exits it should notify the banking stage.
Expand Down Expand Up @@ -80,14 +80,14 @@ impl PohService {

fn tick_producer(
poh: &mut PohRecorder,
config: Config,
config: PohServiceConfig,
poh_exit: &AtomicBool,
to_validator_sender: &TpuRotationSender,
) -> Result<()> {
let max_tick_height = poh.max_tick_height();
loop {
match config {
Config::Tick(num) => {
PohServiceConfig::Tick(num) => {
for _ in 1..num {
let res = poh.hash();
if let Err(e) = res {
Expand All @@ -99,7 +99,7 @@ impl PohService {
}
}
}
Config::Sleep(duration) => {
PohServiceConfig::Sleep(duration) => {
sleep(duration);
}
}
Expand Down Expand Up @@ -128,18 +128,12 @@ impl Service for PohService {

#[cfg(test)]
mod tests {
use super::{Config, PohService};
use super::*;
use crate::bank::Bank;
use crate::genesis_block::GenesisBlock;
use crate::poh_recorder::PohRecorder;
use crate::result::Result;
use crate::service::Service;
use crate::test_tx::test_tx;
use solana_sdk::hash::hash;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::channel;
use std::sync::Arc;
use std::thread::{Builder, JoinHandle};

#[test]
fn test_poh_service() {
Expand Down Expand Up @@ -173,8 +167,11 @@ mod tests {

const HASHES_PER_TICK: u64 = 2;
let (sender, _) = channel();
let poh_service =
PohService::new(poh_recorder, Config::Tick(HASHES_PER_TICK as usize), sender);
let poh_service = PohService::new(
poh_recorder,
PohServiceConfig::Tick(HASHES_PER_TICK as usize),
sender,
);

// get some events
let mut hashes = 0;
Expand Down
Loading