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();
|
let mut fullnode_exit = FullnodeConfig::default();
|
||||||
fullnode_exit.rpc_config.enable_fullnode_exit = true;
|
fullnode_exit.rpc_config.enable_fullnode_exit = true;
|
||||||
const NUM_NODES: usize = 1;
|
const NUM_NODES: usize = 1;
|
||||||
let num_replicators = 0;
|
let num_replicators = 1;
|
||||||
let cluster = LocalCluster::new_with_config_replicators(
|
let cluster = LocalCluster::new_with_config_replicators(
|
||||||
&[3; NUM_NODES],
|
&[3; NUM_NODES],
|
||||||
100,
|
100,
|
||||||
|
|
|
@ -19,7 +19,6 @@ use rand::Rng;
|
||||||
use solana_client::rpc_client::RpcClient;
|
use solana_client::rpc_client::RpcClient;
|
||||||
use solana_client::rpc_request::RpcRequest;
|
use solana_client::rpc_request::RpcRequest;
|
||||||
use solana_client::thin_client::{create_client, ThinClient};
|
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::hash::{Hash, Hasher};
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
||||||
use solana_sdk::system_transaction;
|
use solana_sdk::system_transaction;
|
||||||
|
@ -58,7 +57,6 @@ pub struct Replicator {
|
||||||
exit: Arc<AtomicBool>,
|
exit: Arc<AtomicBool>,
|
||||||
slot: u64,
|
slot: u64,
|
||||||
ledger_path: String,
|
ledger_path: String,
|
||||||
keypair: Arc<Keypair>,
|
|
||||||
storage_keypair: Arc<Keypair>,
|
storage_keypair: Arc<Keypair>,
|
||||||
signature: ring::signature::Signature,
|
signature: ring::signature::Signature,
|
||||||
cluster_entrypoint: ContactInfo,
|
cluster_entrypoint: ContactInfo,
|
||||||
|
@ -248,6 +246,9 @@ impl Replicator {
|
||||||
repair_slot_range,
|
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 =
|
let mut thread_handles =
|
||||||
create_request_processor(node.sockets.storage.unwrap(), &exit, slot);
|
create_request_processor(node.sockets.storage.unwrap(), &exit, slot);
|
||||||
|
|
||||||
|
@ -263,28 +264,11 @@ impl Replicator {
|
||||||
|
|
||||||
let exit3 = exit.clone();
|
let exit3 = exit.clone();
|
||||||
let blocktree1 = blocktree.clone();
|
let blocktree1 = blocktree.clone();
|
||||||
let keypair1 = keypair.clone();
|
let t_replicate = spawn(move || loop {
|
||||||
let storage_keypair1 = storage_keypair.clone();
|
Self::wait_for_ledger_download(slot, &blocktree1, &exit3, &node_info, &cluster_info);
|
||||||
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) {
|
if exit3.load(Ordering::Relaxed) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
thread_handles.push(t_replicate);
|
thread_handles.push(t_replicate);
|
||||||
|
|
||||||
|
@ -296,7 +280,6 @@ impl Replicator {
|
||||||
exit,
|
exit,
|
||||||
slot,
|
slot,
|
||||||
ledger_path: ledger_path.to_string(),
|
ledger_path: ledger_path.to_string(),
|
||||||
keypair: keypair.clone(),
|
|
||||||
storage_keypair,
|
storage_keypair,
|
||||||
signature,
|
signature,
|
||||||
cluster_entrypoint,
|
cluster_entrypoint,
|
||||||
|
@ -422,16 +405,18 @@ impl Replicator {
|
||||||
client: &ThinClient,
|
client: &ThinClient,
|
||||||
keypair: &Keypair,
|
keypair: &Keypair,
|
||||||
storage_keypair: &Keypair,
|
storage_keypair: &Keypair,
|
||||||
entrypoint: &ContactInfo,
|
) -> io::Result<()> {
|
||||||
) {
|
|
||||||
// make sure replicator has some balance
|
// 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
|
// check if the account exists
|
||||||
if client
|
let bal = client.poll_get_balance(&storage_keypair.pubkey());
|
||||||
.wait_for_balance(&storage_keypair.pubkey(), None)
|
if bal.is_err() || bal.unwrap() == 0 {
|
||||||
.is_none()
|
|
||||||
{
|
|
||||||
let blockhash = client.get_recent_blockhash().expect("blockhash");
|
let blockhash = client.get_recent_blockhash().expect("blockhash");
|
||||||
//TODO the account space needs to be well defined somewhere
|
//TODO the account space needs to be well defined somewhere
|
||||||
let tx = system_transaction::create_account(
|
let tx = system_transaction::create_account(
|
||||||
|
@ -443,9 +428,10 @@ impl Replicator {
|
||||||
&solana_storage_api::id(),
|
&solana_storage_api::id(),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
let signature = client.transfer_signed(&tx).unwrap();
|
let signature = client.transfer_signed(&tx)?;
|
||||||
client.poll_for_signature(&signature).unwrap();
|
client.poll_for_signature(&signature)?;
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn submit_mining_proof(&self) {
|
fn submit_mining_proof(&self) {
|
||||||
|
@ -453,7 +439,13 @@ impl Replicator {
|
||||||
self.cluster_entrypoint.client_facing_addr(),
|
self.cluster_entrypoint.client_facing_addr(),
|
||||||
FULLNODE_PORT_RANGE,
|
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(
|
let ix = storage_instruction::mining_proof(
|
||||||
&self.storage_keypair.pubkey(),
|
&self.storage_keypair.pubkey(),
|
||||||
|
@ -516,38 +508,6 @@ impl Replicator {
|
||||||
"Couldn't get blockhash or entry_height",
|
"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)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in New Issue