From adcda3c7156050bb9d89c2b2eefec5954c3f64d4 Mon Sep 17 00:00:00 2001 From: Sagar Dhawan Date: Fri, 5 Apr 2019 15:45:26 -0700 Subject: [PATCH] Remove airdrop dependency from replicators --- core/src/local_cluster.rs | 2 +- core/src/replicator.rs | 92 +++++++++++---------------------------- 2 files changed, 27 insertions(+), 67 deletions(-) diff --git a/core/src/local_cluster.rs b/core/src/local_cluster.rs index 0760e4aaeb..7355531197 100644 --- a/core/src/local_cluster.rs +++ b/core/src/local_cluster.rs @@ -435,7 +435,7 @@ mod test { let mut fullnode_exit = FullnodeConfig::default(); fullnode_exit.rpc_config.enable_fullnode_exit = true; const NUM_NODES: usize = 1; - let num_replicators = 0; + let num_replicators = 1; let cluster = LocalCluster::new_with_config_replicators( &[3; NUM_NODES], 100, diff --git a/core/src/replicator.rs b/core/src/replicator.rs index 493873563d..3387b8996b 100644 --- a/core/src/replicator.rs +++ b/core/src/replicator.rs @@ -19,7 +19,6 @@ use rand::Rng; use solana_client::rpc_client::RpcClient; use solana_client::rpc_request::RpcRequest; use solana_client::thin_client::{create_client, ThinClient}; -use solana_drone::drone::{request_airdrop_transaction, DRONE_PORT}; use solana_sdk::hash::{Hash, Hasher}; use solana_sdk::signature::{Keypair, KeypairUtil, Signature}; use solana_sdk::system_transaction; @@ -58,7 +57,6 @@ pub struct Replicator { exit: Arc, slot: u64, ledger_path: String, - keypair: Arc, storage_keypair: Arc, signature: ring::signature::Signature, cluster_entrypoint: ContactInfo, @@ -248,6 +246,9 @@ impl Replicator { repair_slot_range, ); + let client = create_client(cluster_entrypoint.client_facing_addr(), FULLNODE_PORT_RANGE); + Self::setup_mining_account(&client, &keypair, &storage_keypair)?; + let mut thread_handles = create_request_processor(node.sockets.storage.unwrap(), &exit, slot); @@ -263,27 +264,10 @@ impl Replicator { let exit3 = exit.clone(); let blocktree1 = blocktree.clone(); - let keypair1 = keypair.clone(); - let storage_keypair1 = storage_keypair.clone(); - let cluster_entrypoint1 = cluster_entrypoint.clone(); - let t_replicate = spawn(move || { - let client = create_client( - cluster_entrypoint1.client_facing_addr(), - FULLNODE_PORT_RANGE, - ); - Self::setup_mining_account(&client, &keypair1, &storage_keypair1, &cluster_entrypoint1); - - loop { - Self::wait_for_ledger_download( - slot, - &blocktree1, - &exit3, - &node_info, - &cluster_info, - ); - if exit3.load(Ordering::Relaxed) { - break; - } + let t_replicate = spawn(move || loop { + Self::wait_for_ledger_download(slot, &blocktree1, &exit3, &node_info, &cluster_info); + if exit3.load(Ordering::Relaxed) { + break; } }); thread_handles.push(t_replicate); @@ -296,7 +280,6 @@ impl Replicator { exit, slot, ledger_path: ledger_path.to_string(), - keypair: keypair.clone(), storage_keypair, signature, cluster_entrypoint, @@ -422,16 +405,18 @@ impl Replicator { client: &ThinClient, keypair: &Keypair, storage_keypair: &Keypair, - entrypoint: &ContactInfo, - ) { + ) -> io::Result<()> { // make sure replicator has some balance - Self::get_airdrop_lamports(client, keypair, entrypoint); + if client.poll_get_balance(&keypair.pubkey())? == 0 { + Err(io::Error::new( + io::ErrorKind::Other, + "No account has been setup", + ))? + } // check if the account exists - if client - .wait_for_balance(&storage_keypair.pubkey(), None) - .is_none() - { + let bal = client.poll_get_balance(&storage_keypair.pubkey()); + if bal.is_err() || bal.unwrap() == 0 { let blockhash = client.get_recent_blockhash().expect("blockhash"); //TODO the account space needs to be well defined somewhere let tx = system_transaction::create_account( @@ -443,9 +428,10 @@ impl Replicator { &solana_storage_api::id(), 0, ); - let signature = client.transfer_signed(&tx).unwrap(); - client.poll_for_signature(&signature).unwrap(); + let signature = client.transfer_signed(&tx)?; + client.poll_for_signature(&signature)?; } + Ok(()) } fn submit_mining_proof(&self) { @@ -453,7 +439,13 @@ impl Replicator { self.cluster_entrypoint.client_facing_addr(), FULLNODE_PORT_RANGE, ); - Self::get_airdrop_lamports(&client, &self.keypair, &self.cluster_entrypoint); + // No point if we've got no storage account + assert!( + client + .poll_get_balance(&self.storage_keypair.pubkey()) + .unwrap() + > 0 + ); let ix = storage_instruction::mining_proof( &self.storage_keypair.pubkey(), @@ -516,38 +508,6 @@ impl Replicator { "Couldn't get blockhash or entry_height", ))? } - - fn get_airdrop_lamports( - client: &ThinClient, - keypair: &Keypair, - cluster_entrypoint: &ContactInfo, - ) { - if client.wait_for_balance(&keypair.pubkey(), None).is_none() { - let mut drone_addr = cluster_entrypoint.tpu; - drone_addr.set_port(DRONE_PORT); - - let airdrop_amount = 1; - - let blockhash = client.get_recent_blockhash().expect("blockhash"); - match request_airdrop_transaction( - &drone_addr, - &keypair.pubkey(), - airdrop_amount, - blockhash, - ) { - Ok(transaction) => { - let signature = client.transfer_signed(&transaction).unwrap(); - client.poll_for_signature(&signature).unwrap(); - } - Err(err) => { - panic!( - "Error requesting airdrop: {:?} to addr: {:?} amount: {}", - err, drone_addr, airdrop_amount - ); - } - }; - } - } } #[cfg(test)]