Configurable local cluster native processors (#3676)

This commit is contained in:
Jack May 2019-04-08 11:15:58 -07:00 committed by GitHub
parent d45d8e9670
commit 44b391096d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 5 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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(

View File

@ -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(