Minor code restyling, no functional changes

This commit is contained in:
Michael Vines
2019-05-07 08:05:12 -07:00
parent 2c78a93001
commit 4f3b22d04e
4 changed files with 105 additions and 95 deletions

View File

@ -58,7 +58,7 @@ pub struct ClusterConfig {
pub fullnode_config: FullnodeConfig, pub fullnode_config: FullnodeConfig,
/// Number of replicators in the cluster /// Number of replicators in the cluster
/// Note- replicators will timeout if ticks_per_slot is much larger than the default 8 /// Note- replicators will timeout if ticks_per_slot is much larger than the default 8
pub num_replicators: u64, pub num_replicators: usize,
/// Number of nodes that are unstaked and not voting (a.k.a listening) /// Number of nodes that are unstaked and not voting (a.k.a listening)
pub num_listeners: u64, pub num_listeners: u64,
/// The stakes of each node /// The stakes of each node

View File

@ -141,13 +141,13 @@ impl StorageStage {
storage_rotate_count: u64, storage_rotate_count: u64,
cluster_info: &Arc<RwLock<ClusterInfo>>, cluster_info: &Arc<RwLock<ClusterInfo>>,
) -> Self { ) -> Self {
let storage_state_inner = storage_state.state.clone();
let exit0 = exit.clone();
let keypair0 = storage_keypair.clone();
let (instruction_sender, instruction_receiver) = channel(); let (instruction_sender, instruction_receiver) = channel();
let t_storage_mining_verifier = Builder::new() let t_storage_mining_verifier = {
let storage_state_inner = storage_state.state.clone();
let exit = exit.clone();
let storage_keypair = storage_keypair.clone();
Builder::new()
.name("solana-storage-mining-verify-stage".to_string()) .name("solana-storage-mining-verify-stage".to_string())
.spawn(move || { .spawn(move || {
let mut current_key = 0; let mut current_key = 0;
@ -155,7 +155,7 @@ impl StorageStage {
loop { loop {
if let Some(ref some_blocktree) = blocktree { if let Some(ref some_blocktree) = blocktree {
if let Err(e) = Self::process_entries( if let Err(e) = Self::process_entries(
&keypair0, &storage_keypair,
&storage_state_inner, &storage_state_inner,
&slot_receiver, &slot_receiver,
&some_blocktree, &some_blocktree,
@ -165,44 +165,46 @@ impl StorageStage {
&instruction_sender, &instruction_sender,
) { ) {
match e { match e {
Error::RecvTimeoutError(RecvTimeoutError::Disconnected) => break, Error::RecvTimeoutError(RecvTimeoutError::Disconnected) => {
break
}
Error::RecvTimeoutError(RecvTimeoutError::Timeout) => (), Error::RecvTimeoutError(RecvTimeoutError::Timeout) => (),
_ => info!("Error from process_entries: {:?}", e), _ => info!("Error from process_entries: {:?}", e),
} }
} }
} }
if exit0.load(Ordering::Relaxed) { if exit.load(Ordering::Relaxed) {
break; break;
} }
} }
}) })
.unwrap(); .unwrap()
};
let cluster_info0 = cluster_info.clone(); let t_storage_create_accounts = {
let exit1 = exit.clone(); let cluster_info = cluster_info.clone();
let keypair1 = keypair.clone(); let exit = exit.clone();
let storage_keypair1 = storage_keypair.clone(); let keypair = keypair.clone();
let bank_forks1 = bank_forks.clone(); let storage_keypair = storage_keypair.clone();
let t_storage_create_accounts = Builder::new() let bank_forks = bank_forks.clone();
Builder::new()
.name("solana-storage-create-accounts".to_string()) .name("solana-storage-create-accounts".to_string())
.spawn(move || { .spawn(move || {
let transactions_socket = UdpSocket::bind("0.0.0.0:0").unwrap(); let transactions_socket = UdpSocket::bind("0.0.0.0:0").unwrap();
loop { loop {
match instruction_receiver.recv_timeout(Duration::from_secs(1)) { match instruction_receiver.recv_timeout(Duration::from_secs(1)) {
Ok(instruction) => { Ok(instruction) => {
if Self::send_transaction( Self::send_transaction(
&bank_forks1, &bank_forks,
&cluster_info0, &cluster_info,
instruction, instruction,
&keypair1, &keypair,
&storage_keypair1, &storage_keypair,
Some(storage_keypair1.pubkey()),
&transactions_socket, &transactions_socket,
) )
.is_err() .unwrap_or_else(|err| {
{ info!("failed to send storage transaction: {:?}", err)
debug!("Failed to send storage transaction"); });
}
} }
Err(e) => match e { Err(e) => match e {
RecvTimeoutError::Disconnected => break, RecvTimeoutError::Disconnected => break,
@ -210,13 +212,14 @@ impl StorageStage {
}, },
}; };
if exit1.load(Ordering::Relaxed) { if exit.load(Ordering::Relaxed) {
break; break;
} }
sleep(Duration::from_millis(100)); sleep(Duration::from_millis(100));
} }
}) })
.unwrap(); .unwrap()
};
StorageStage { StorageStage {
t_storage_mining_verifier, t_storage_mining_verifier,
@ -230,20 +233,21 @@ impl StorageStage {
instruction: Instruction, instruction: Instruction,
keypair: &Arc<Keypair>, keypair: &Arc<Keypair>,
storage_keypair: &Arc<Keypair>, storage_keypair: &Arc<Keypair>,
account_to_create: Option<Pubkey>,
transactions_socket: &UdpSocket, transactions_socket: &UdpSocket,
) -> io::Result<()> { ) -> io::Result<()> {
let working_bank = bank_forks.read().unwrap().working_bank(); let working_bank = bank_forks.read().unwrap().working_bank();
let blockhash = working_bank.confirmed_last_blockhash(); let blockhash = working_bank.confirmed_last_blockhash();
let mut instructions = vec![]; let mut instructions = vec![];
let mut signing_keys = vec![]; let mut signing_keys = vec![];
if let Some(account) = account_to_create { if working_bank
if working_bank.get_account(&account).is_none() { .get_account(&storage_keypair.pubkey())
.is_none()
{
// TODO the account space needs to be well defined somewhere // TODO the account space needs to be well defined somewhere
let create_instruction = system_instruction::create_account( let create_instruction = system_instruction::create_account(
&keypair.pubkey(), &keypair.pubkey(),
&storage_keypair.pubkey(), &storage_keypair.pubkey(),
1, 1000,
1024 * 4, 1024 * 4,
&solana_storage_api::id(), &solana_storage_api::id(),
); );
@ -251,7 +255,6 @@ impl StorageStage {
signing_keys.push(keypair.as_ref()); signing_keys.push(keypair.as_ref());
info!("storage account requested"); info!("storage account requested");
} }
}
instructions.push(instruction); instructions.push(instruction);
signing_keys.push(storage_keypair.as_ref()); signing_keys.push(storage_keypair.as_ref());
let mut transaction = Transaction::new_unsigned_instructions(instructions); let mut transaction = Transaction::new_unsigned_instructions(instructions);
@ -264,17 +267,21 @@ impl StorageStage {
} }
fn process_entry_crossing( fn process_entry_crossing(
storage_keypair: &Arc<Keypair>,
state: &Arc<RwLock<StorageStateInner>>, state: &Arc<RwLock<StorageStateInner>>,
keypair: &Arc<Keypair>,
_blocktree: &Arc<Blocktree>, _blocktree: &Arc<Blocktree>,
entry_id: Hash, entry_id: Hash,
slot: u64, slot: u64,
instruction_sender: &InstructionSender, instruction_sender: &InstructionSender,
) -> Result<()> { ) -> Result<()> {
let mut seed = [0u8; 32]; let mut seed = [0u8; 32];
let signature = keypair.sign(&entry_id.as_ref()); let signature = storage_keypair.sign(&entry_id.as_ref());
let ix = storage_instruction::advertise_recent_blockhash(&keypair.pubkey(), entry_id, slot); let ix = storage_instruction::advertise_recent_blockhash(
&storage_keypair.pubkey(),
entry_id,
slot,
);
instruction_sender.send(ix)?; instruction_sender.send(ix)?;
seed.copy_from_slice(&signature.to_bytes()[..32]); seed.copy_from_slice(&signature.to_bytes()[..32]);
@ -383,7 +390,7 @@ impl StorageStage {
} }
fn process_entries( fn process_entries(
keypair: &Arc<Keypair>, storage_keypair: &Arc<Keypair>,
storage_state: &Arc<RwLock<StorageStateInner>>, storage_state: &Arc<RwLock<StorageStateInner>>,
slot_receiver: &Receiver<u64>, slot_receiver: &Receiver<u64>,
blocktree: &Arc<Blocktree>, blocktree: &Arc<Blocktree>,
@ -419,8 +426,8 @@ impl StorageStage {
slot, entry.num_hashes slot, entry.num_hashes
); );
Self::process_entry_crossing( Self::process_entry_crossing(
&storage_keypair,
&storage_state, &storage_state,
&keypair,
&blocktree, &blocktree,
entry.hash, entry.hash,
slot, slot,

View File

@ -107,7 +107,7 @@ fn run_replicator_startup_basic(num_nodes: usize, num_replicators: usize) {
fullnode_config.storage_rotate_count = STORAGE_ROTATE_TEST_COUNT; fullnode_config.storage_rotate_count = STORAGE_ROTATE_TEST_COUNT;
let config = ClusterConfig { let config = ClusterConfig {
fullnode_config, fullnode_config,
num_replicators: num_replicators as u64, num_replicators,
node_stakes: vec![100; num_nodes], node_stakes: vec![100; num_nodes],
cluster_lamports: 10_000, cluster_lamports: 10_000,
..ClusterConfig::default() ..ClusterConfig::default()

View File

@ -85,8 +85,11 @@ fn test_replay() {
let (bank_forks, _bank_forks_info, blocktree, ledger_signal_receiver, leader_schedule_cache) = let (bank_forks, _bank_forks_info, blocktree, ledger_signal_receiver, leader_schedule_cache) =
fullnode::new_banks_from_blocktree(&blocktree_path, None); fullnode::new_banks_from_blocktree(&blocktree_path, None);
let bank = bank_forks.working_bank(); let working_bank = bank_forks.working_bank();
assert_eq!(bank.get_balance(&mint_keypair.pubkey()), mint_balance); assert_eq!(
working_bank.get_balance(&mint_keypair.pubkey()),
mint_balance
);
let leader_schedule_cache = Arc::new(leader_schedule_cache); let leader_schedule_cache = Arc::new(leader_schedule_cache);
// start cluster_info1 // start cluster_info1
@ -100,7 +103,7 @@ fn test_replay() {
let blocktree = Arc::new(blocktree); let blocktree = Arc::new(blocktree);
{ {
let (poh_service_exit, poh_recorder, poh_service, _entry_receiver) = let (poh_service_exit, poh_recorder, poh_service, _entry_receiver) =
create_test_recorder(&bank, &blocktree); create_test_recorder(&working_bank, &blocktree);
let tvu = Tvu::new( let tvu = Tvu::new(
&voting_keypair.pubkey(), &voting_keypair.pubkey(),
Some(Arc::new(voting_keypair)), Some(Arc::new(voting_keypair)),