| 
									
										
										
										
											2019-03-01 10:36:52 -08:00
										 |  |  | extern crate solana;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-23 19:19:55 -07:00
										 |  |  | use solana::cluster::Cluster;
 | 
					
						
							| 
									
										
										
										
											2019-03-01 10:36:52 -08:00
										 |  |  | use solana::cluster_tests;
 | 
					
						
							| 
									
										
										
										
											2019-03-04 09:59:36 -08:00
										 |  |  | use solana::fullnode::FullnodeConfig;
 | 
					
						
							| 
									
										
										
										
											2019-05-16 07:14:58 -07:00
										 |  |  | use solana::gossip_service::discover_cluster;
 | 
					
						
							| 
									
										
										
										
											2019-04-15 15:27:45 -07:00
										 |  |  | use solana::local_cluster::{ClusterConfig, LocalCluster};
 | 
					
						
							| 
									
										
										
										
											2019-05-13 16:24:32 -07:00
										 |  |  | use solana_runtime::epoch_schedule::MINIMUM_SLOT_LENGTH;
 | 
					
						
							| 
									
										
										
										
											2019-05-18 14:01:36 -07:00
										 |  |  | use solana_sdk::poh_config::PohConfig;
 | 
					
						
							| 
									
										
										
										
											2019-03-23 19:19:55 -07:00
										 |  |  | use solana_sdk::timing;
 | 
					
						
							| 
									
										
										
										
											2019-03-07 15:49:07 -08:00
										 |  |  | use std::time::Duration;
 | 
					
						
							| 
									
										
										
										
											2019-03-01 10:36:52 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #[test]
 | 
					
						
							| 
									
										
										
										
											2019-03-05 17:56:51 -08:00
										 |  |  | fn test_spend_and_verify_all_nodes_1() {
 | 
					
						
							| 
									
										
										
										
											2019-03-01 10:36:52 -08:00
										 |  |  |     solana_logger::setup();
 | 
					
						
							|  |  |  |     let num_nodes = 1;
 | 
					
						
							| 
									
										
										
										
											2019-04-15 15:27:45 -07:00
										 |  |  |     let local = LocalCluster::new_with_equal_stakes(num_nodes, 10_000, 100);
 | 
					
						
							| 
									
										
										
										
											2019-03-01 10:36:52 -08:00
										 |  |  |     cluster_tests::spend_and_verify_all_nodes(
 | 
					
						
							|  |  |  |         &local.entry_point_info,
 | 
					
						
							|  |  |  |         &local.funding_keypair,
 | 
					
						
							|  |  |  |         num_nodes,
 | 
					
						
							|  |  |  |     );
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[test]
 | 
					
						
							| 
									
										
										
										
											2019-03-05 17:56:51 -08:00
										 |  |  | fn test_spend_and_verify_all_nodes_2() {
 | 
					
						
							| 
									
										
										
										
											2019-03-01 10:36:52 -08:00
										 |  |  |     solana_logger::setup();
 | 
					
						
							|  |  |  |     let num_nodes = 2;
 | 
					
						
							| 
									
										
										
										
											2019-04-15 15:27:45 -07:00
										 |  |  |     let local = LocalCluster::new_with_equal_stakes(num_nodes, 10_000, 100);
 | 
					
						
							| 
									
										
										
										
											2019-03-01 10:36:52 -08:00
										 |  |  |     cluster_tests::spend_and_verify_all_nodes(
 | 
					
						
							|  |  |  |         &local.entry_point_info,
 | 
					
						
							|  |  |  |         &local.funding_keypair,
 | 
					
						
							|  |  |  |         num_nodes,
 | 
					
						
							|  |  |  |     );
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[test]
 | 
					
						
							| 
									
										
										
										
											2019-03-05 17:56:51 -08:00
										 |  |  | fn test_spend_and_verify_all_nodes_3() {
 | 
					
						
							| 
									
										
										
										
											2019-03-01 10:36:52 -08:00
										 |  |  |     solana_logger::setup();
 | 
					
						
							|  |  |  |     let num_nodes = 3;
 | 
					
						
							| 
									
										
										
										
											2019-04-15 15:27:45 -07:00
										 |  |  |     let local = LocalCluster::new_with_equal_stakes(num_nodes, 10_000, 100);
 | 
					
						
							| 
									
										
										
										
											2019-03-01 10:36:52 -08:00
										 |  |  |     cluster_tests::spend_and_verify_all_nodes(
 | 
					
						
							|  |  |  |         &local.entry_point_info,
 | 
					
						
							|  |  |  |         &local.funding_keypair,
 | 
					
						
							|  |  |  |         num_nodes,
 | 
					
						
							|  |  |  |     );
 | 
					
						
							|  |  |  | }
 | 
					
						
							| 
									
										
										
										
											2019-03-03 22:01:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-19 15:47:03 -07:00
										 |  |  | #[test]
 | 
					
						
							|  |  |  | #[ignore]
 | 
					
						
							|  |  |  | fn test_spend_and_verify_all_nodes_env_num_nodes() {
 | 
					
						
							|  |  |  |     solana_logger::setup();
 | 
					
						
							|  |  |  |     let num_nodes: usize = std::env::var("NUM_NODES")
 | 
					
						
							|  |  |  |         .expect("please set environment variable NUM_NODES")
 | 
					
						
							|  |  |  |         .parse()
 | 
					
						
							|  |  |  |         .expect("could not parse NUM_NODES as a number");
 | 
					
						
							|  |  |  |     let local = LocalCluster::new_with_equal_stakes(num_nodes, 10_000, 100);
 | 
					
						
							|  |  |  |     cluster_tests::spend_and_verify_all_nodes(
 | 
					
						
							|  |  |  |         &local.entry_point_info,
 | 
					
						
							|  |  |  |         &local.funding_keypair,
 | 
					
						
							|  |  |  |         num_nodes,
 | 
					
						
							|  |  |  |     );
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-03 22:01:09 -08:00
										 |  |  | #[test]
 | 
					
						
							|  |  |  | #[should_panic]
 | 
					
						
							| 
									
										
										
										
											2019-03-05 17:56:51 -08:00
										 |  |  | fn test_fullnode_exit_default_config_should_panic() {
 | 
					
						
							| 
									
										
										
										
											2019-03-03 22:01:09 -08:00
										 |  |  |     solana_logger::setup();
 | 
					
						
							|  |  |  |     let num_nodes = 2;
 | 
					
						
							| 
									
										
										
										
											2019-04-15 15:27:45 -07:00
										 |  |  |     let local = LocalCluster::new_with_equal_stakes(num_nodes, 10_000, 100);
 | 
					
						
							| 
									
										
										
										
											2019-03-03 22:01:09 -08:00
										 |  |  |     cluster_tests::fullnode_exit(&local.entry_point_info, num_nodes);
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[test]
 | 
					
						
							| 
									
										
										
										
											2019-03-05 17:56:51 -08:00
										 |  |  | fn test_fullnode_exit_2() {
 | 
					
						
							| 
									
										
										
										
											2019-03-03 22:01:09 -08:00
										 |  |  |     solana_logger::setup();
 | 
					
						
							|  |  |  |     let num_nodes = 2;
 | 
					
						
							| 
									
										
										
										
											2019-03-05 21:12:30 -08:00
										 |  |  |     let mut fullnode_config = FullnodeConfig::default();
 | 
					
						
							|  |  |  |     fullnode_config.rpc_config.enable_fullnode_exit = true;
 | 
					
						
							| 
									
										
										
										
											2019-04-15 15:27:45 -07:00
										 |  |  |     let config = ClusterConfig {
 | 
					
						
							|  |  |  |         cluster_lamports: 10_000,
 | 
					
						
							|  |  |  |         node_stakes: vec![100; 2],
 | 
					
						
							|  |  |  |         fullnode_config,
 | 
					
						
							|  |  |  |         ..ClusterConfig::default()
 | 
					
						
							|  |  |  |     };
 | 
					
						
							|  |  |  |     let local = LocalCluster::new(&config);
 | 
					
						
							| 
									
										
										
										
											2019-03-03 22:01:09 -08:00
										 |  |  |     cluster_tests::fullnode_exit(&local.entry_point_info, num_nodes);
 | 
					
						
							|  |  |  | }
 | 
					
						
							| 
									
										
										
										
											2019-03-05 17:56:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-21 07:43:21 -07:00
										 |  |  | // Cluster needs a supermajority to remain, so the minimum size for this test is 4
 | 
					
						
							| 
									
										
										
										
											2019-03-05 17:56:51 -08:00
										 |  |  | #[test]
 | 
					
						
							| 
									
										
										
										
											2019-03-21 07:43:21 -07:00
										 |  |  | fn test_leader_failure_4() {
 | 
					
						
							|  |  |  |     solana_logger::setup();
 | 
					
						
							|  |  |  |     let num_nodes = 4;
 | 
					
						
							| 
									
										
										
										
											2019-03-05 21:12:30 -08:00
										 |  |  |     let mut fullnode_config = FullnodeConfig::default();
 | 
					
						
							|  |  |  |     fullnode_config.rpc_config.enable_fullnode_exit = true;
 | 
					
						
							| 
									
										
										
										
											2019-04-15 15:27:45 -07:00
										 |  |  |     let config = ClusterConfig {
 | 
					
						
							|  |  |  |         cluster_lamports: 10_000,
 | 
					
						
							|  |  |  |         node_stakes: vec![100; 4],
 | 
					
						
							| 
									
										
										
										
											2019-04-29 15:26:52 -07:00
										 |  |  |         fullnode_config: fullnode_config.clone(),
 | 
					
						
							| 
									
										
										
										
											2019-04-15 15:27:45 -07:00
										 |  |  |         ..ClusterConfig::default()
 | 
					
						
							|  |  |  |     };
 | 
					
						
							|  |  |  |     let local = LocalCluster::new(&config);
 | 
					
						
							| 
									
										
										
										
											2019-03-05 17:56:51 -08:00
										 |  |  |     cluster_tests::kill_entry_and_spend_and_verify_rest(
 | 
					
						
							|  |  |  |         &local.entry_point_info,
 | 
					
						
							|  |  |  |         &local.funding_keypair,
 | 
					
						
							|  |  |  |         num_nodes,
 | 
					
						
							| 
									
										
										
										
											2019-05-18 14:01:36 -07:00
										 |  |  |         config.ticks_per_slot * config.poh_config.target_tick_duration.as_millis() as u64,
 | 
					
						
							| 
									
										
										
										
											2019-03-05 17:56:51 -08:00
										 |  |  |     );
 | 
					
						
							|  |  |  | }
 | 
					
						
							| 
									
										
										
										
											2019-03-07 15:49:07 -08:00
										 |  |  | #[test]
 | 
					
						
							|  |  |  | fn test_two_unbalanced_stakes() {
 | 
					
						
							| 
									
										
										
										
											2019-04-15 17:15:50 -07:00
										 |  |  |     solana_logger::setup();
 | 
					
						
							| 
									
										
										
										
											2019-03-07 15:49:07 -08:00
										 |  |  |     let mut fullnode_config = FullnodeConfig::default();
 | 
					
						
							|  |  |  |     let num_ticks_per_second = 100;
 | 
					
						
							| 
									
										
										
										
											2019-05-18 14:01:36 -07:00
										 |  |  |     let num_ticks_per_slot = 10;
 | 
					
						
							| 
									
										
										
										
											2019-04-29 15:26:52 -07:00
										 |  |  |     let num_slots_per_epoch = MINIMUM_SLOT_LENGTH as u64;
 | 
					
						
							| 
									
										
										
										
											2019-05-18 14:01:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-07 15:49:07 -08:00
										 |  |  |     fullnode_config.rpc_config.enable_fullnode_exit = true;
 | 
					
						
							| 
									
										
										
										
											2019-04-15 15:27:45 -07:00
										 |  |  |     let mut cluster = LocalCluster::new(&ClusterConfig {
 | 
					
						
							|  |  |  |         node_stakes: vec![999_990, 3],
 | 
					
						
							|  |  |  |         cluster_lamports: 1_000_000,
 | 
					
						
							|  |  |  |         fullnode_config: fullnode_config.clone(),
 | 
					
						
							|  |  |  |         ticks_per_slot: num_ticks_per_slot,
 | 
					
						
							|  |  |  |         slots_per_epoch: num_slots_per_epoch,
 | 
					
						
							| 
									
										
										
										
											2019-05-18 14:01:36 -07:00
										 |  |  |         poh_config: PohConfig::new_sleep(Duration::from_millis(1000 / num_ticks_per_second)),
 | 
					
						
							| 
									
										
										
										
											2019-04-15 15:27:45 -07:00
										 |  |  |         ..ClusterConfig::default()
 | 
					
						
							|  |  |  |     });
 | 
					
						
							| 
									
										
										
										
											2019-04-29 15:26:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-23 19:19:55 -07:00
										 |  |  |     cluster_tests::sleep_n_epochs(
 | 
					
						
							|  |  |  |         10.0,
 | 
					
						
							| 
									
										
										
										
											2019-05-18 14:01:36 -07:00
										 |  |  |         &cluster.genesis_block.poh_config,
 | 
					
						
							| 
									
										
										
										
											2019-03-23 19:19:55 -07:00
										 |  |  |         num_ticks_per_slot,
 | 
					
						
							|  |  |  |         num_slots_per_epoch,
 | 
					
						
							|  |  |  |     );
 | 
					
						
							| 
									
										
										
										
											2019-03-07 15:49:07 -08:00
										 |  |  |     cluster.close_preserve_ledgers();
 | 
					
						
							| 
									
										
										
										
											2019-03-23 19:19:55 -07:00
										 |  |  |     let leader_id = cluster.entry_point_info.id;
 | 
					
						
							|  |  |  |     let leader_ledger = cluster.fullnode_infos[&leader_id].ledger_path.clone();
 | 
					
						
							| 
									
										
										
										
											2019-03-19 06:36:45 -07:00
										 |  |  |     cluster_tests::verify_ledger_ticks(&leader_ledger, num_ticks_per_slot as usize);
 | 
					
						
							| 
									
										
										
										
											2019-03-07 15:49:07 -08:00
										 |  |  | }
 | 
					
						
							| 
									
										
										
										
											2019-03-09 16:25:38 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #[test]
 | 
					
						
							| 
									
										
										
										
											2019-03-18 22:08:21 -07:00
										 |  |  | #[ignore]
 | 
					
						
							| 
									
										
										
										
											2019-03-09 16:25:38 -08:00
										 |  |  | fn test_forwarding() {
 | 
					
						
							|  |  |  |     // Set up a cluster where one node is never the leader, so all txs sent to this node
 | 
					
						
							| 
									
										
										
										
											2019-03-10 17:33:01 -07:00
										 |  |  |     // will be have to be forwarded in order to be confirmed
 | 
					
						
							| 
									
										
										
										
											2019-04-15 15:27:45 -07:00
										 |  |  |     let config = ClusterConfig {
 | 
					
						
							|  |  |  |         node_stakes: vec![999_990, 3],
 | 
					
						
							|  |  |  |         cluster_lamports: 2_000_000,
 | 
					
						
							|  |  |  |         ..ClusterConfig::default()
 | 
					
						
							|  |  |  |     };
 | 
					
						
							|  |  |  |     let cluster = LocalCluster::new(&config);
 | 
					
						
							| 
									
										
										
										
											2019-03-09 16:25:38 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-16 07:14:58 -07:00
										 |  |  |     let (cluster_nodes, _) = discover_cluster(&cluster.entry_point_info.gossip, 2).unwrap();
 | 
					
						
							| 
									
										
										
										
											2019-03-09 16:25:38 -08:00
										 |  |  |     assert!(cluster_nodes.len() >= 2);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let leader_id = cluster.entry_point_info.id;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let validator_info = cluster_nodes.iter().find(|c| c.id != leader_id).unwrap();
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-10 17:33:01 -07:00
										 |  |  |     // Confirm that transactions were forwarded to and processed by the leader.
 | 
					
						
							|  |  |  |     cluster_tests::send_many_transactions(&validator_info, &cluster.funding_keypair, 20);
 | 
					
						
							| 
									
										
										
										
											2019-03-09 16:25:38 -08:00
										 |  |  | }
 | 
					
						
							| 
									
										
										
										
											2019-03-23 19:19:55 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #[test]
 | 
					
						
							|  |  |  | fn test_restart_node() {
 | 
					
						
							|  |  |  |     let fullnode_config = FullnodeConfig::default();
 | 
					
						
							| 
									
										
										
										
											2019-04-29 15:26:52 -07:00
										 |  |  |     let slots_per_epoch = MINIMUM_SLOT_LENGTH as u64;
 | 
					
						
							| 
									
										
										
										
											2019-03-23 19:19:55 -07:00
										 |  |  |     let ticks_per_slot = 16;
 | 
					
						
							| 
									
										
										
										
											2019-04-15 15:27:45 -07:00
										 |  |  |     let mut cluster = LocalCluster::new(&ClusterConfig {
 | 
					
						
							|  |  |  |         node_stakes: vec![3],
 | 
					
						
							|  |  |  |         cluster_lamports: 100,
 | 
					
						
							|  |  |  |         fullnode_config: fullnode_config.clone(),
 | 
					
						
							| 
									
										
										
										
											2019-03-23 19:19:55 -07:00
										 |  |  |         ticks_per_slot,
 | 
					
						
							|  |  |  |         slots_per_epoch,
 | 
					
						
							| 
									
										
										
										
											2019-04-15 15:27:45 -07:00
										 |  |  |         ..ClusterConfig::default()
 | 
					
						
							|  |  |  |     });
 | 
					
						
							| 
									
										
										
										
											2019-03-23 19:19:55 -07:00
										 |  |  |     let nodes = cluster.get_node_ids();
 | 
					
						
							|  |  |  |     cluster_tests::sleep_n_epochs(
 | 
					
						
							|  |  |  |         1.0,
 | 
					
						
							| 
									
										
										
										
											2019-05-18 14:01:36 -07:00
										 |  |  |         &cluster.genesis_block.poh_config,
 | 
					
						
							| 
									
										
										
										
											2019-03-23 19:19:55 -07:00
										 |  |  |         timing::DEFAULT_TICKS_PER_SLOT,
 | 
					
						
							|  |  |  |         slots_per_epoch,
 | 
					
						
							|  |  |  |     );
 | 
					
						
							|  |  |  |     cluster.restart_node(nodes[0]);
 | 
					
						
							|  |  |  |     cluster_tests::sleep_n_epochs(
 | 
					
						
							|  |  |  |         0.5,
 | 
					
						
							| 
									
										
										
										
											2019-05-18 14:01:36 -07:00
										 |  |  |         &cluster.genesis_block.poh_config,
 | 
					
						
							| 
									
										
										
										
											2019-03-23 19:19:55 -07:00
										 |  |  |         timing::DEFAULT_TICKS_PER_SLOT,
 | 
					
						
							|  |  |  |         slots_per_epoch,
 | 
					
						
							|  |  |  |     );
 | 
					
						
							|  |  |  |     cluster_tests::send_many_transactions(&cluster.entry_point_info, &cluster.funding_keypair, 1);
 | 
					
						
							|  |  |  | }
 | 
					
						
							| 
									
										
										
										
											2019-04-15 15:27:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #[test]
 | 
					
						
							|  |  |  | fn test_listener_startup() {
 | 
					
						
							|  |  |  |     let config = ClusterConfig {
 | 
					
						
							|  |  |  |         node_stakes: vec![100; 1],
 | 
					
						
							|  |  |  |         cluster_lamports: 1_000,
 | 
					
						
							|  |  |  |         num_listeners: 3,
 | 
					
						
							|  |  |  |         ..ClusterConfig::default()
 | 
					
						
							|  |  |  |     };
 | 
					
						
							|  |  |  |     let cluster = LocalCluster::new(&config);
 | 
					
						
							| 
									
										
										
										
											2019-05-16 07:14:58 -07:00
										 |  |  |     let (cluster_nodes, _) = discover_cluster(&cluster.entry_point_info.gossip, 4).unwrap();
 | 
					
						
							| 
									
										
										
										
											2019-04-15 15:27:45 -07:00
										 |  |  |     assert_eq!(cluster_nodes.len(), 4);
 | 
					
						
							|  |  |  | }
 |