From 44b391096d69367c37c6046254166e7bf681eafe Mon Sep 17 00:00:00 2001 From: Jack May Date: Mon, 8 Apr 2019 11:15:58 -0700 Subject: [PATCH] Configurable local cluster native processors (#3676) --- bench-tps/src/bench.rs | 2 +- core/src/local_cluster.rs | 11 ++++++++++- core/tests/local_cluster.rs | 8 +++++--- core/tests/replicator.rs | 2 ++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/bench-tps/src/bench.rs b/bench-tps/src/bench.rs index e313f3c74..e91ec0782 100644 --- a/bench-tps/src/bench.rs +++ b/bench-tps/src/bench.rs @@ -752,7 +752,7 @@ mod tests { let fullnode_config = FullnodeConfig::default(); const NUM_NODES: usize = 1; let cluster = - LocalCluster::new_with_config(&[999_990; NUM_NODES], 2_000_000, &fullnode_config); + LocalCluster::new_with_config(&[999_990; NUM_NODES], 2_000_000, &fullnode_config, &[]); let drone_keypair = Keypair::new(); cluster.transfer(&cluster.funding_keypair, &drone_keypair.pubkey(), 1_000_000); diff --git a/core/src/local_cluster.rs b/core/src/local_cluster.rs index bfaf7d48c..1854bcfb6 100644 --- a/core/src/local_cluster.rs +++ b/core/src/local_cluster.rs @@ -68,13 +68,14 @@ pub struct LocalCluster { impl LocalCluster { pub fn new(num_nodes: usize, cluster_lamports: u64, lamports_per_node: u64) -> Self { let stakes: Vec<_> = (0..num_nodes).map(|_| lamports_per_node).collect(); - Self::new_with_config(&stakes, cluster_lamports, &FullnodeConfig::default()) + Self::new_with_config(&stakes, cluster_lamports, &FullnodeConfig::default(), &[]) } pub fn new_with_config( node_stakes: &[u64], cluster_lamports: u64, fullnode_config: &FullnodeConfig, + native_instruction_processors: &[(String, Pubkey)], ) -> Self { Self::new_with_config_replicators( node_stakes, @@ -83,6 +84,7 @@ impl LocalCluster { 0, DEFAULT_TICKS_PER_SLOT, DEFAULT_SLOTS_PER_EPOCH, + native_instruction_processors, ) } @@ -92,6 +94,7 @@ impl LocalCluster { fullnode_config: &FullnodeConfig, ticks_per_slot: u64, slots_per_epoch: u64, + native_instruction_processors: &[(String, Pubkey)], ) -> Self { Self::new_with_config_replicators( node_stakes, @@ -100,6 +103,7 @@ impl LocalCluster { 0, ticks_per_slot, slots_per_epoch, + native_instruction_processors, ) } @@ -110,6 +114,7 @@ impl LocalCluster { num_replicators: usize, ticks_per_slot: u64, slots_per_epoch: u64, + native_instruction_processors: &[(String, Pubkey)], ) -> Self { let leader_keypair = Arc::new(Keypair::new()); let leader_pubkey = leader_keypair.pubkey(); @@ -118,6 +123,9 @@ impl LocalCluster { GenesisBlock::new_with_leader(cluster_lamports, &leader_pubkey, node_stakes[0]); genesis_block.ticks_per_slot = ticks_per_slot; genesis_block.slots_per_epoch = slots_per_epoch; + genesis_block + .native_instruction_processors + .extend_from_slice(native_instruction_processors); let (genesis_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block); let leader_ledger_path = tmp_copy_blocktree!(&genesis_ledger_path); let voting_keypair = Keypair::new(); @@ -444,6 +452,7 @@ mod test { num_replicators, 16, 16, + &[], ); assert_eq!(cluster.fullnodes.len(), NUM_NODES); assert_eq!(cluster.replicators.len(), num_replicators); diff --git a/core/tests/local_cluster.rs b/core/tests/local_cluster.rs index 91fec26aa..d37968017 100644 --- a/core/tests/local_cluster.rs +++ b/core/tests/local_cluster.rs @@ -60,7 +60,7 @@ fn test_fullnode_exit_2() { let num_nodes = 2; let mut fullnode_config = FullnodeConfig::default(); fullnode_config.rpc_config.enable_fullnode_exit = true; - let local = LocalCluster::new_with_config(&[100; 2], 10_000, &fullnode_config); + let local = LocalCluster::new_with_config(&[100; 2], 10_000, &fullnode_config, &[]); cluster_tests::fullnode_exit(&local.entry_point_info, num_nodes); } @@ -71,7 +71,7 @@ fn test_leader_failure_4() { let num_nodes = 4; let mut fullnode_config = FullnodeConfig::default(); fullnode_config.rpc_config.enable_fullnode_exit = true; - let local = LocalCluster::new_with_config(&[100; 4], 10_000, &fullnode_config); + let local = LocalCluster::new_with_config(&[100; 4], 10_000, &fullnode_config, &[]); cluster_tests::kill_entry_and_spend_and_verify_rest( &local.entry_point_info, &local.funding_keypair, @@ -93,6 +93,7 @@ fn test_two_unbalanced_stakes() { &fullnode_config, num_ticks_per_slot, num_slots_per_epoch, + &[], ); cluster_tests::sleep_n_epochs( 10.0, @@ -113,7 +114,7 @@ fn test_forwarding() { // Set up a cluster where one node is never the leader, so all txs sent to this node // will be have to be forwarded in order to be confirmed let fullnode_config = FullnodeConfig::default(); - let cluster = LocalCluster::new_with_config(&[999_990, 3], 2_000_000, &fullnode_config); + let cluster = LocalCluster::new_with_config(&[999_990, 3], 2_000_000, &fullnode_config, &[]); let cluster_nodes = discover_nodes(&cluster.entry_point_info.gossip, 2).unwrap(); assert!(cluster_nodes.len() >= 2); @@ -137,6 +138,7 @@ fn test_restart_node() { &fullnode_config, ticks_per_slot, slots_per_epoch, + &[], ); let nodes = cluster.get_node_ids(); cluster_tests::sleep_n_epochs( diff --git a/core/tests/replicator.rs b/core/tests/replicator.rs index 3fe819ad1..714ad1936 100644 --- a/core/tests/replicator.rs +++ b/core/tests/replicator.rs @@ -114,6 +114,7 @@ fn run_replicator_startup_basic(num_nodes: usize, num_replicators: usize) { num_replicators, DEFAULT_TICKS_PER_SLOT, DEFAULT_SLOTS_PER_EPOCH, + &[], ); let cluster_nodes = discover_nodes( @@ -228,6 +229,7 @@ fn test_account_setup() { num_replicators, DEFAULT_TICKS_PER_SLOT, DEFAULT_SLOTS_PER_EPOCH, + &[], ); let _ = discover_nodes(