forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LocalCluster - rename, refactor consts, verify initial transfers #4437
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ use { | |
epoch_schedule::EpochSchedule, | ||
genesis_config::{ClusterType, GenesisConfig}, | ||
message::Message, | ||
native_token::LAMPORTS_PER_SOL, | ||
poh_config::PohConfig, | ||
pubkey::Pubkey, | ||
signature::{Keypair, Signature, Signer}, | ||
|
@@ -68,6 +69,7 @@ use { | |
}, | ||
}; | ||
|
||
pub const DEFAULT_MINT_LAMPORTS: u64 = 10_000_000 * LAMPORTS_PER_SOL; | ||
const DUMMY_SNAPSHOT_CONFIG_PATH_MARKER: &str = "dummy"; | ||
|
||
pub struct ClusterConfig { | ||
|
@@ -85,8 +87,8 @@ pub struct ClusterConfig { | |
pub node_stakes: Vec<u64>, | ||
/// Optional vote keypairs to use for each node | ||
pub node_vote_keys: Option<Vec<Arc<Keypair>>>, | ||
/// The total lamports available to the cluster | ||
pub cluster_lamports: u64, | ||
/// The number of lamports in the mint account | ||
pub mint_lamports: u64, | ||
pub ticks_per_slot: u64, | ||
pub slots_per_epoch: u64, | ||
pub stakers_slot_offset: u64, | ||
|
@@ -103,12 +105,12 @@ pub struct ClusterConfig { | |
impl ClusterConfig { | ||
pub fn new_with_equal_stakes( | ||
num_nodes: usize, | ||
cluster_lamports: u64, | ||
mint_lamports: u64, | ||
lamports_per_node: u64, | ||
) -> Self { | ||
Self { | ||
node_stakes: vec![lamports_per_node; num_nodes], | ||
cluster_lamports, | ||
mint_lamports, | ||
validator_configs: make_identical_validator_configs( | ||
&ValidatorConfig::default_for_test(), | ||
num_nodes, | ||
|
@@ -126,7 +128,7 @@ impl Default for ClusterConfig { | |
validator_keys: None, | ||
node_stakes: vec![], | ||
node_vote_keys: None, | ||
cluster_lamports: 0, | ||
mint_lamports: DEFAULT_MINT_LAMPORTS, | ||
ticks_per_slot: DEFAULT_TICKS_PER_SLOT, | ||
slots_per_epoch: DEFAULT_DEV_SLOTS_PER_EPOCH, | ||
stakers_slot_offset: DEFAULT_DEV_SLOTS_PER_EPOCH, | ||
|
@@ -155,16 +157,12 @@ pub struct LocalCluster { | |
impl LocalCluster { | ||
pub fn new_with_equal_stakes( | ||
num_nodes: usize, | ||
cluster_lamports: u64, | ||
mint_lamports: u64, | ||
lamports_per_node: u64, | ||
socket_addr_space: SocketAddrSpace, | ||
) -> Self { | ||
Self::new( | ||
&mut ClusterConfig::new_with_equal_stakes( | ||
num_nodes, | ||
cluster_lamports, | ||
lamports_per_node, | ||
), | ||
&mut ClusterConfig::new_with_equal_stakes(num_nodes, mint_lamports, lamports_per_node), | ||
socket_addr_space, | ||
) | ||
} | ||
|
@@ -254,6 +252,10 @@ impl LocalCluster { | |
} | ||
}; | ||
|
||
// Mint used to fund validator identities for non-genesis accounts. | ||
// Verify we have enough lamports in the mint address to do those transfers. | ||
let mut required_mint_lamports = 0; | ||
|
||
// Bootstrap leader should always be in genesis block | ||
validator_keys[0].1 = true; | ||
let (keys_in_genesis, stakes_in_genesis): (Vec<ValidatorVoteKeypairs>, Vec<u64>) = | ||
|
@@ -278,10 +280,18 @@ impl LocalCluster { | |
stake, | ||
)) | ||
} else { | ||
required_mint_lamports += Self::required_validator_funding(*stake); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. working on making local cluster tests (and all tests) have fees. |
||
None | ||
} | ||
}) | ||
.unzip(); | ||
|
||
// Verify mint has enough lamports to fund all required validators. | ||
assert!( | ||
config.mint_lamports >= required_mint_lamports, | ||
"mint requires additional lamports to fund validators" | ||
); | ||
|
||
let leader_keypair = &keys_in_genesis[0].node_keypair; | ||
let leader_vote_keypair = &keys_in_genesis[0].vote_keypair; | ||
let leader_pubkey = leader_keypair.pubkey(); | ||
|
@@ -292,7 +302,7 @@ impl LocalCluster { | |
mint_keypair, | ||
.. | ||
} = create_genesis_config_with_vote_accounts_and_cluster_type( | ||
config.cluster_lamports, | ||
config.mint_lamports, | ||
&keys_in_genesis, | ||
stakes_in_genesis, | ||
config.cluster_type, | ||
|
@@ -519,7 +529,7 @@ impl LocalCluster { | |
&client, | ||
&self.funding_keypair, | ||
&validator_pubkey, | ||
stake * 2 + 2, | ||
Self::required_validator_funding(stake), | ||
); | ||
info!( | ||
"validator {} balance {}", | ||
|
@@ -972,6 +982,10 @@ impl LocalCluster { | |
|
||
Ok(tpu_client) | ||
} | ||
|
||
fn required_validator_funding(stake: u64) -> u64 { | ||
stake.saturating_mul(2).saturating_add(2) | ||
brooksprumo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
impl Cluster for LocalCluster { | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could probably get rid of all these lower values as well...I can't imagine there's anything special about these that require lower mint lamports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could either do them in this PR, or just up them if these tests fail once fees are added.