Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Define ClusterConfig::new_with_equal_stakes() #32330

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions local-cluster/src/local_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,25 @@ pub struct ClusterConfig {
pub tpu_connection_pool_size: usize,
}

impl ClusterConfig {
pub fn new_with_equal_stakes(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does / should this be pub?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems so... even pub(crate) didn't work (tested at #31239):

error[E0624]: associated function `new_with_equal_stakes` is private
    --> local-cluster/tests/local_cluster.rs:3038:37
     |
3038 |       let mut config = ClusterConfig::new_with_equal_stakes(
     |                                       ^^^^^^^^^^^^^^^^^^^^^ private associated function
     |
    ::: /home/ryoqun/work/solana/for-merge/local-cluster/src/local_cluster.rs:96:5
     |
96   | /     pub(crate) fn new_with_equal_stakes(
97   | |         num_nodes: usize,
98   | |         cluster_lamports: u64,
99   | |         lamports_per_node: u64,
100  | |     ) -> Self {
     | |_____________- private associated function defined here

For more information about this error, try `rustc --explain E0624`.
error: could not compile `solana-local-cluster` (test "local_cluster") due to previous error
warning: build failed, waiting for other jobs to finish...

num_nodes: usize,
cluster_lamports: u64,
lamports_per_node: u64,
) -> Self {
let stakes: Vec<_> = vec![lamports_per_node; num_nodes];
Self {
node_stakes: stakes,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

realize it was just moved, but let's do a tactical rename in this PR:

Suggested change
let stakes: Vec<_> = vec![lamports_per_node; num_nodes];
Self {
node_stakes: stakes,
let node_stakes = vec![lamports_per_node; num_nodes];
Self {
node_stakes,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about this? 0d5e602 better, imo. :)

cluster_lamports,
validator_configs: make_identical_validator_configs(
&ValidatorConfig::default_for_test(),
num_nodes,
),
..Self::default()
}
}
}

impl Default for ClusterConfig {
fn default() -> Self {
ClusterConfig {
Expand Down Expand Up @@ -133,17 +152,14 @@ impl LocalCluster {
lamports_per_node: u64,
socket_addr_space: SocketAddrSpace,
) -> Self {
let stakes: Vec<_> = (0..num_nodes).map(|_| lamports_per_node).collect();
let mut config = ClusterConfig {
node_stakes: stakes,
cluster_lamports,
validator_configs: make_identical_validator_configs(
&ValidatorConfig::default_for_test(),
Self::new(
&mut ClusterConfig::new_with_equal_stakes(
num_nodes,
cluster_lamports,
lamports_per_node,
),
..ClusterConfig::default()
};
Self::new(&mut config, socket_addr_space)
socket_addr_space,
)
}

fn sync_ledger_path_across_nested_config_fields(
Expand Down