Remove airdrop dependency from replicators
This commit is contained in:
parent
a5b5248a09
commit
adcda3c715
|
@ -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,
|
||||
|
|
|
@ -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<AtomicBool>,
|
||||
slot: u64,
|
||||
ledger_path: String,
|
||||
keypair: Arc<Keypair>,
|
||||
storage_keypair: Arc<Keypair>,
|
||||
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)]
|
||||
|
|
Loading…
Reference in New Issue