From 4f1116164ceb05c77e6c3c034e12b278f88bf3ca Mon Sep 17 00:00:00 2001 From: Ashwin Sekar Date: Thu, 14 Dec 2023 14:50:48 -0500 Subject: [PATCH] local-cluster: fix flaky test_rpc_block_subscribe (#34421) * local-cluster: fix flaky test_rpc_block_subscribe * reenable test * pr feedback: add comment linking pr --- local-cluster/tests/local_cluster.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/local-cluster/tests/local_cluster.rs b/local-cluster/tests/local_cluster.rs index 2784b1fc4..597134cce 100644 --- a/local-cluster/tests/local_cluster.rs +++ b/local-cluster/tests/local_cluster.rs @@ -2562,35 +2562,41 @@ fn run_test_load_program_accounts_partition(scan_commitment: CommitmentConfig) { #[test] #[serial] -#[ignore] fn test_rpc_block_subscribe() { - let total_stake = 100 * DEFAULT_NODE_STAKE; - let leader_stake = total_stake; - let node_stakes = vec![leader_stake]; + let leader_stake = 100 * DEFAULT_NODE_STAKE; + let rpc_stake = DEFAULT_NODE_STAKE; + let total_stake = leader_stake + rpc_stake; + let node_stakes = vec![leader_stake, rpc_stake]; let mut validator_config = ValidatorConfig::default_for_test(); validator_config.enable_default_rpc_block_subscribe(); let validator_keys = [ "28bN3xyvrP4E8LwEgtLjhnkb7cY4amQb6DrYAbAYjgRV4GAGgkVM2K7wnxnAS7WDneuavza7x21MiafLu1HkwQt4", + "2saHBBoTkLMmttmPQP8KfBkcCw45S5cwtV3wTdGCscRC8uxdgvHxpHiWXKx4LvJjNJtnNcbSv5NdheokFFqnNDt8", ] .iter() .map(|s| (Arc::new(Keypair::from_base58_string(s)), true)) .take(node_stakes.len()) .collect::>(); + let rpc_node_pubkey = &validator_keys[1].0.pubkey(); let mut config = ClusterConfig { cluster_lamports: total_stake, node_stakes, - validator_configs: vec![validator_config], + validator_configs: make_identical_validator_configs(&validator_config, 2), validator_keys: Some(validator_keys), skip_warmup_slots: true, ..ClusterConfig::default() }; let cluster = LocalCluster::new(&mut config, SocketAddrSpace::Unspecified); + let rpc_node_contact_info = cluster.get_contact_info(rpc_node_pubkey).unwrap(); let (mut block_subscribe_client, receiver) = PubsubClient::block_subscribe( &format!( "ws://{}", - &cluster.entry_point_info.rpc_pubsub().unwrap().to_string() + // It is important that we subscribe to a non leader node as there + // is a race condition which can cause leader nodes to not send + // BlockUpdate notifications properly. See https://github.com/solana-labs/solana/pull/34421 + &rpc_node_contact_info.rpc_pubsub().unwrap().to_string() ), RpcBlockSubscribeFilter::All, Some(RpcBlockSubscribeConfig {