2018-11-29 09:29:17 -08:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2018-12-08 21:44:20 -08:00
|
|
|
|
2018-12-10 11:38:29 -08:00
|
|
|
#[cfg(feature = "chacha")]
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_json;
|
|
|
|
|
2018-11-29 09:29:17 -08:00
|
|
|
use solana::client::mk_client;
|
2018-11-02 08:40:29 -07:00
|
|
|
use solana::cluster_info::{Node, NodeInfo};
|
2018-11-29 09:29:17 -08:00
|
|
|
use solana::db_ledger::DbLedger;
|
|
|
|
use solana::fullnode::Fullnode;
|
|
|
|
use solana::leader_scheduler::LeaderScheduler;
|
2018-12-10 11:38:29 -08:00
|
|
|
use solana::ledger::{create_tmp_genesis, get_tmp_ledger_path, read_ledger, tmp_copy_ledger};
|
2018-11-29 09:29:17 -08:00
|
|
|
use solana::replicator::Replicator;
|
2018-12-03 10:26:28 -08:00
|
|
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
2018-12-10 11:21:28 -08:00
|
|
|
use solana_sdk::system_transaction::SystemTransaction;
|
|
|
|
use solana_sdk::transaction::Transaction;
|
2018-11-29 09:29:17 -08:00
|
|
|
use std::fs::remove_dir_all;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::thread::sleep;
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_replicator_startup() {
|
|
|
|
info!("starting replicator test");
|
|
|
|
let replicator_ledger_path = &get_tmp_ledger_path("replicator_test_replicator_ledger");
|
|
|
|
|
|
|
|
info!("starting leader node");
|
|
|
|
let leader_keypair = Arc::new(Keypair::new());
|
|
|
|
let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
|
|
|
|
let leader_info = leader_node.info.clone();
|
|
|
|
let vote_account_keypair = Arc::new(Keypair::new());
|
|
|
|
|
|
|
|
let leader_ledger_path = "replicator_test_leader_ledger";
|
|
|
|
let (mint, leader_ledger_path) = create_tmp_genesis(leader_ledger_path, 100, leader_info.id, 1);
|
|
|
|
|
2018-12-10 11:38:29 -08:00
|
|
|
let validator_ledger_path =
|
|
|
|
tmp_copy_ledger(&leader_ledger_path, "replicator_test_validator_ledger");
|
|
|
|
|
2018-11-29 09:29:17 -08:00
|
|
|
{
|
|
|
|
let leader = Fullnode::new(
|
|
|
|
leader_node,
|
|
|
|
&leader_ledger_path,
|
|
|
|
leader_keypair,
|
2018-12-10 11:38:29 -08:00
|
|
|
vote_account_keypair.clone(),
|
2018-11-29 09:29:17 -08:00
|
|
|
None,
|
|
|
|
false,
|
2018-12-10 11:38:29 -08:00
|
|
|
LeaderScheduler::from_bootstrap_leader(leader_info.id.clone()),
|
|
|
|
None,
|
|
|
|
);
|
|
|
|
|
|
|
|
let validator_keypair = Arc::new(Keypair::new());
|
|
|
|
let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey());
|
|
|
|
|
|
|
|
#[cfg(feature = "chacha")]
|
|
|
|
let validator_node_info = validator_node.info.clone();
|
|
|
|
|
|
|
|
let validator = Fullnode::new(
|
|
|
|
validator_node,
|
|
|
|
&validator_ledger_path,
|
|
|
|
validator_keypair,
|
|
|
|
vote_account_keypair,
|
|
|
|
Some(leader_info.gossip),
|
|
|
|
false,
|
2018-11-29 09:29:17 -08:00
|
|
|
LeaderScheduler::from_bootstrap_leader(leader_info.id),
|
|
|
|
None,
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut leader_client = mk_client(&leader_info);
|
|
|
|
|
|
|
|
let bob = Keypair::new();
|
|
|
|
|
|
|
|
let last_id = leader_client.get_last_id();
|
|
|
|
leader_client
|
|
|
|
.transfer(1, &mint.keypair(), bob.pubkey(), &last_id)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let replicator_keypair = Keypair::new();
|
|
|
|
|
2018-12-10 11:38:29 -08:00
|
|
|
// Give the replicator some tokens
|
2018-12-10 11:21:28 -08:00
|
|
|
let amount = 1;
|
|
|
|
let mut tx = Transaction::system_new(
|
|
|
|
&mint.keypair(),
|
|
|
|
replicator_keypair.pubkey(),
|
|
|
|
amount,
|
|
|
|
last_id,
|
|
|
|
);
|
2018-11-02 08:40:29 -07:00
|
|
|
leader_client
|
2018-12-10 11:21:28 -08:00
|
|
|
.retry_transfer(&mint.keypair(), &mut tx, 5)
|
2018-11-02 08:40:29 -07:00
|
|
|
.unwrap();
|
|
|
|
|
2018-11-29 09:29:17 -08:00
|
|
|
info!("starting replicator node");
|
|
|
|
let replicator_node = Node::new_localhost_with_pubkey(replicator_keypair.pubkey());
|
2018-11-02 08:40:29 -07:00
|
|
|
|
|
|
|
let leader_info = NodeInfo::new_entry_point(&leader_info.gossip);
|
|
|
|
|
|
|
|
let replicator = Replicator::new(
|
2018-11-29 09:29:17 -08:00
|
|
|
Some(replicator_ledger_path),
|
|
|
|
replicator_node,
|
2018-11-02 08:40:29 -07:00
|
|
|
&leader_info,
|
|
|
|
&replicator_keypair,
|
2018-12-07 19:01:28 -08:00
|
|
|
)
|
|
|
|
.unwrap();
|
2018-11-29 09:29:17 -08:00
|
|
|
|
2018-12-10 11:38:29 -08:00
|
|
|
// Poll the ledger dir to see that some is downloaded
|
2018-11-29 09:29:17 -08:00
|
|
|
let mut num_entries = 0;
|
|
|
|
for _ in 0..60 {
|
|
|
|
match read_ledger(replicator_ledger_path, true) {
|
|
|
|
Ok(entries) => {
|
|
|
|
for _ in entries {
|
|
|
|
num_entries += 1;
|
|
|
|
}
|
|
|
|
info!("{} entries", num_entries);
|
|
|
|
if num_entries > 0 {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
info!("error reading ledger: {:?}", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sleep(Duration::from_millis(300));
|
2018-12-10 11:38:29 -08:00
|
|
|
|
|
|
|
// Do a transfer to make sure new entries are created which
|
|
|
|
// stimulates the repair process
|
2018-11-29 09:29:17 -08:00
|
|
|
let last_id = leader_client.get_last_id();
|
|
|
|
leader_client
|
|
|
|
.transfer(1, &mint.keypair(), bob.pubkey(), &last_id)
|
|
|
|
.unwrap();
|
|
|
|
}
|
2018-12-10 11:38:29 -08:00
|
|
|
|
|
|
|
// The replicator will not submit storage proofs if
|
|
|
|
// chacha is not enabled
|
|
|
|
#[cfg(feature = "chacha")]
|
|
|
|
{
|
|
|
|
use solana::rpc_request::{RpcClient, RpcRequest};
|
|
|
|
|
|
|
|
let rpc_client = RpcClient::new_from_socket(validator_node_info.rpc);
|
2018-12-17 15:34:19 -08:00
|
|
|
let mut non_zero_pubkeys = false;
|
2018-12-10 11:38:29 -08:00
|
|
|
for _ in 0..30 {
|
|
|
|
let params = json!([0]);
|
|
|
|
let pubkeys = RpcRequest::GetStoragePubkeysForEntryHeight
|
|
|
|
.make_rpc_request(&rpc_client, 1, Some(params))
|
|
|
|
.unwrap();
|
|
|
|
info!("pubkeys: {:?}", pubkeys);
|
|
|
|
if pubkeys.as_array().unwrap().len() != 0 {
|
2018-12-17 15:34:19 -08:00
|
|
|
non_zero_pubkeys = true;
|
2018-12-10 11:38:29 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
sleep(Duration::from_secs(1));
|
|
|
|
}
|
2018-12-17 15:34:19 -08:00
|
|
|
assert!(non_zero_pubkeys);
|
2018-12-10 11:38:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check that some ledger was downloaded
|
2018-11-29 09:29:17 -08:00
|
|
|
assert!(num_entries > 0);
|
2018-12-10 11:38:29 -08:00
|
|
|
|
2018-11-02 08:40:29 -07:00
|
|
|
replicator.close();
|
2018-12-10 11:38:29 -08:00
|
|
|
validator.exit();
|
2018-12-12 15:58:29 -08:00
|
|
|
leader.close().expect("Expected successful node closure");
|
2018-11-29 09:29:17 -08:00
|
|
|
}
|
|
|
|
|
2018-12-20 09:45:49 -08:00
|
|
|
DbLedger::destroy(&leader_ledger_path).expect("Expected successful database destruction");
|
|
|
|
DbLedger::destroy(&replicator_ledger_path).expect("Expected successful database destruction");
|
2018-11-29 09:29:17 -08:00
|
|
|
let _ignored = remove_dir_all(&leader_ledger_path);
|
|
|
|
let _ignored = remove_dir_all(&replicator_ledger_path);
|
|
|
|
}
|