Use lamports in genesis (#7631)

* Use lamports in genesis

* readability
This commit is contained in:
Rob Walker 2019-12-28 12:49:10 -08:00 committed by GitHub
parent 44e45aa090
commit e0564f628e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 71 deletions

View File

@ -3,10 +3,7 @@ use crate::{
unlocks::UnlockInfo,
validators::{create_and_add_validator, ValidatorInfo},
};
use solana_sdk::{
genesis_config::GenesisConfig,
native_token::{lamports_to_sol, sol_to_lamports},
};
use solana_sdk::{genesis_config::GenesisConfig, native_token::SOL_LAMPORTS};
// 30 month schedule is 1/5th every 6 months for 30 months
const UNLOCKS_BY_FIFTHS_FOR_30_MONTHS: UnlockInfo = UnlockInfo {
@ -39,107 +36,107 @@ pub const BATCH_FOUR_STAKER_INFOS: &[StakerInfo] = &[
StakerInfo {
name: "impossible pizza",
staker: "CDtJpwRSiPRDGeKrvymWQKM7JY9M3hU7iimEKBDxZyoP",
sol: 5_000_000.0,
lamports: 5_000_000 * SOL_LAMPORTS,
},
StakerInfo {
name: "wretched texture",
staker: "HbENu65qjWLEB5TrMouSSWLq9mbtGx2bvfhPjk2FpYek",
sol: 225_000.0,
lamports: 225_000 * SOL_LAMPORTS,
},
StakerInfo {
name: "nutritious examination",
staker: "C9CfFpmLDsQsz6wt7MrrZquNB5oS4QkpJkmDAiboVEZZ",
sol: 5_000_000.0,
lamports: 5_000_000 * SOL_LAMPORTS,
},
StakerInfo {
name: "tidy impression",
staker: "6ne6Rbag4FAnop1KNgVdM1SEHnJEysHSWyqvRpFrzaig",
sol: 5_000_000.0,
lamports: 5_000_000 * SOL_LAMPORTS,
},
StakerInfo {
name: "unbecoming silver",
staker: "42yapY7Vrs5jqht9TCKZsPoyb4vDFYcPfRkqAP85NSAQ",
sol: 28_800.0,
lamports: 28_800 * SOL_LAMPORTS,
},
StakerInfo {
name: "dramatic treatment",
staker: "GTyawCMwt3kMb51AgDtfdp97mDot7jNwc8ifuS9qqANg",
sol: 1_205_602.0,
lamports: 1_205_602 * SOL_LAMPORTS,
},
StakerInfo {
name: "angry noise",
staker: "Fqxs9MhqjKuMq6YwjBG4ktEapuZQ3kj19mpuHLZKtkg9",
sol: 5_000_000.0,
lamports: 5_000_000 * SOL_LAMPORTS,
},
StakerInfo {
name: "hard cousin",
staker: "9MYDzj7QuAX9QAK7da1GhzPB4gA3qbPNWsW3MMSZobru",
sol: 5_000_000.0,
lamports: 5_000_000 * SOL_LAMPORTS,
},
StakerInfo {
name: "inexpensive uncle",
staker: "E4DLNkmdL34ejA48ApfPDoFVuD9XWAFqi8bXzBGRhKst",
sol: 300_000.0,
lamports: 300_000 * SOL_LAMPORTS,
},
StakerInfo {
name: "lopsided skill",
staker: "8cV7zCTF5UMrZakZXiL2Jw5uY3ms2Wz4twzFXEY9Kge2",
sol: 5_000_000.0,
lamports: 5_000_000 * SOL_LAMPORTS,
},
StakerInfo {
name: "red snake",
staker: "JBGnGdLyo7V2z9hz51mnnbyDp9sBACtw5WYH9YRG8n7e",
sol: 3_655_292.0,
lamports: 3_655_292 * SOL_LAMPORTS,
},
StakerInfo {
name: "hellish money",
staker: "CqKdQ57mBj2mKcAbpjWc28Ls7yXzBXboxSTCRWocmUVj",
sol: 200_000.0,
lamports: 200_000 * SOL_LAMPORTS,
},
StakerInfo {
name: "full grape",
staker: "2SCJKvh7wWo32PtfUZdVZQ84WnMWoUpF4WTm6ZxcCJ15",
sol: 450_000.0,
lamports: 450_000 * SOL_LAMPORTS,
},
StakerInfo {
name: "nice ghost",
staker: "FeumxB3gfzrVQzABBiha8AacKPY3Rf4BTFSh2aZWHqR8",
sol: 650_000.0,
lamports: 650_000 * SOL_LAMPORTS,
},
StakerInfo {
name: "jolly year",
staker: "HBwFWNGPVZgkf3yqUKxuAds5aANGWX62LzUFvZVCWLdJ",
sol: 5_000_000.0,
lamports: 5_000_000 * SOL_LAMPORTS,
},
StakerInfo {
name: "typical initiative",
staker: "3JMz3kaDUZEVK2JVjRqwERGMp7LbWbgUjAFBb42qxoHb",
sol: 5_000_000.0,
lamports: 5_000_000 * SOL_LAMPORTS,
},
StakerInfo {
name: "deserted window",
staker: "XTeBBZextvHkoRqDF8yb4hihjcraKQDwTEXhzjd8fip",
sol: 3_655_292.0,
lamports: 3_655_292 * SOL_LAMPORTS,
},
StakerInfo {
name: "eight nation",
staker: "E5bSU5ywqPiz3ije89ef5gaEC7jy81BAc72Zeb9MqeHY",
sol: 103_519.0,
lamports: 103_519 * SOL_LAMPORTS,
},
StakerInfo {
name: "earsplitting meaning",
staker: "4ZemkSoE75RFE1SVLnnmHcaNWT4qN8KFrKP2wAYfv8CB",
sol: 5_000_000.0,
lamports: 5_000_000 * SOL_LAMPORTS,
},
StakerInfo {
name: "alike cheese",
staker: "72BGEwYee5txFonmpEarTEKCZVN2UxcSUgdphdhcx3V",
sol: 3_880_295.0,
lamports: 3_880_295 * SOL_LAMPORTS,
},
StakerInfo {
name: "noisy honey",
staker: "DRp1Scyn4yJZQfMAdQew2x8RtvRmsNELN37JTK5Xvzgn",
sol: 5_000_000.0,
lamports: 5_000_000 * SOL_LAMPORTS,
},
];
@ -147,12 +144,12 @@ pub const FOUNDATION_STAKER_INFOS: &[StakerInfo] = &[
StakerInfo {
name: "lyrical supermarket",
staker: "GRZwoJGisLTszcxtWpeREJ98EGg8pZewhbtcrikoU7b3",
sol: 5_000_000.0,
lamports: 5_000_000 * SOL_LAMPORTS,
},
StakerInfo {
name: "frequent description",
staker: "J51tinoLdmEdUR27LUVymrb2LB3xQo1aSHSgmbSGdj58",
sol: 57_500_000.0,
lamports: 57_500_000 * SOL_LAMPORTS,
},
];
@ -160,12 +157,12 @@ pub const GRANTS_STAKER_INFOS: &[StakerInfo] = &[
StakerInfo {
name: "rightful agreement",
staker: "DNaKiBwwbbqk1wVoC5AQxWQbuDhvaDVbAtXzsVos9mrc",
sol: 5_000_000.0,
lamports: 5_000_000 * SOL_LAMPORTS,
},
StakerInfo {
name: "tasty location",
staker: "HvXQPXAijjG1vnQs6HXVtUUtFVzi5HNgXV9LGnHvYF85",
sol: 15_000_000.0,
lamports: 15_000_000 * SOL_LAMPORTS,
},
];
@ -173,17 +170,17 @@ pub const COMMUNITY_STAKER_INFOS: &[StakerInfo] = &[
StakerInfo {
name: "shrill charity",
staker: "BzuqQFnu7oNUeok9ZoJezpqu2vZJU7XR1PxVLkk6wwUD",
sol: 5_000_000.0,
lamports: 5_000_000 * SOL_LAMPORTS,
},
StakerInfo {
name: "legal gate",
staker: "FwMbkDZUb78aiMWhZY4BEroAcqmnrXZV77nwrg71C57d",
sol: 16_086_641.0,
lamports: 16_086_641 * SOL_LAMPORTS,
},
StakerInfo {
name: "cluttered complaint",
staker: "4h1rt2ic4AXwG7p3Qqhw57EMDD4c3tLYb5J3QstGA2p5",
sol: 153_333_633.41,
lamports: 153_333_633 * SOL_LAMPORTS + 41 * SOL_LAMPORTS / 100,
},
];
@ -206,70 +203,70 @@ pub const VALIDATOR_INFOS: &[ValidatorInfo] = &[
name: "01Node",
node: "5n8KCdzqtvTnhkvCrFR7errH6ZUp11kL97r2awXkfzFe",
vote: "4uYMbY5Ae5ZSRNxQ3RWVyXS9rzW7E3AMZYHuUEotxu6K",
node_sol: 500.0,
node_lamports: 500 * SOL_LAMPORTS,
commission: 0,
},
ValidatorInfo {
name: "Bison Trails",
node: "7suRNpX7bJsXphHJtBv4ZsLjJZ1dTGeX256pLqJZdEAm",
vote: "DfirEZ9Up1xbE7sQji9UwtcRGe5uCcRqQtnaGpha5KNY",
node_sol: 500.0,
node_lamports: 500 * SOL_LAMPORTS,
commission: 0,
},
ValidatorInfo {
name: "ChainFlow",
node: "2te46rxywMdCNdkvjumiBBPQoVczJFxhxEaxFavQNqe3",
vote: "8bRCnytB7bySmqxodNGbZuUAtncKkB8T733DD1Dm9WMb",
node_sol: 500.0,
node_lamports: 500 * SOL_LAMPORTS,
commission: 0,
},
ValidatorInfo {
name: "ChorusOne",
node: "ChorusXqjLC2NbiStKR6k9WoD7wu6TVTtFG8qCL5XBVa",
vote: "ChorusvBuPwukqgDvYfWtEg8j4T1NcMgSTQ4b1UbAwgQ",
node_sol: 500.0,
node_lamports: 500 * SOL_LAMPORTS,
commission: 0,
},
ValidatorInfo {
name: "Dokia Capital",
node: "GeZ5PrJi9muVCJiJAaFBNGoCEdxGEqTp7L2BmT2WTTy1",
vote: "7ZdRx2EBYoRuPfyeoNbuHodMUXcAQRcC37MUw3kP6akn",
node_sol: 500.0,
node_lamports: 500 * SOL_LAMPORTS,
commission: 0,
},
ValidatorInfo {
name: "Forbole",
node: "Fe5sLQAAT7RBT8mcH1AAGCbExJQcYxcwXvp1GjrGbvxs",
vote: "Dr8MkZZuvZVQJFKtjShZYEfg6n93sc1GxevqLnGss7FW",
node_sol: 500.0,
node_lamports: 500 * SOL_LAMPORTS,
commission: 0,
},
ValidatorInfo {
name: "P2P.ORG - Secure Non-custodial Staking",
node: "44e8VyWoyZSE2oYHxMHMedAiHkGJqJgPd3tdt6iKoAFL",
vote: "BwwpzEpo1wzgV9N1987ntgNG6jLt3C9532C68pswT7Gp",
node_sol: 500.0,
node_lamports: 500 * SOL_LAMPORTS,
commission: 0,
},
ValidatorInfo {
name: "RockX",
node: "Ez4iUU87ViJLCnmSy1t1Ti3DLoysFXiBseNfnRfoehyY",
vote: "GUdGALCHQBeqkNc2ZAht3tBXab1N5u9qJC3PAzpL54r7",
node_sol: 500.0,
node_lamports: 500 * SOL_LAMPORTS,
commission: 0,
},
ValidatorInfo {
name: "Stake Capital",
node: "HavuVVDXXsJqMzPwQ4KcF5kFm2xqjbChhyi1bgGeCQif",
vote: "HswPkKj1xoLLmpM8t1vy5Pbi8zYYUs9ZawswvofKsFo1",
node_sol: 500.0,
node_lamports: 500 * SOL_LAMPORTS,
commission: 0,
},
ValidatorInfo {
name: "Staking Facilities",
node: "pbAxyqHHPMwgEjv8kmjGxysk9rhNtN7q22eAjReq6Hj",
vote: "4VZ3pJX19PpuGjoSB1qeN9sVQfrqgLVNg16is37adiFp",
node_sol: 500.0,
node_lamports: 500 * SOL_LAMPORTS,
commission: 0,
},
];
@ -289,22 +286,22 @@ pub fn add_genesis_accounts(genesis_config: &mut GenesisConfig, mut issued_lampo
genesis_config,
&BATCH_FOUR_STAKER_INFOS,
&UNLOCKS_BY_FIFTHS_FOR_30_MONTHS,
sol_to_lamports(1_000_000.0),
1_000_000 * SOL_LAMPORTS,
) + add_stakes(
genesis_config,
&FOUNDATION_STAKER_INFOS,
&UNLOCKS_BY_TENTHS_FOR_60_MONTHS,
sol_to_lamports(1_000_000.0),
1_000_000 * SOL_LAMPORTS,
) + add_stakes(
genesis_config,
&GRANTS_STAKER_INFOS,
&UNLOCKS_BY_TENTHS_FOR_60_MONTHS,
sol_to_lamports(1_000_000.0),
1_000_000 * SOL_LAMPORTS,
) + add_stakes(
genesis_config,
&COMMUNITY_STAKER_INFOS,
&UNLOCKS_ALL_DAY_ZERO,
sol_to_lamports(1_000_000.0),
1_000_000 * SOL_LAMPORTS,
) + add_validators(genesis_config, &VALIDATOR_INFOS);
// "one thanks" (community pool) gets 500_000_000SOL (total) - above distributions
@ -313,10 +310,10 @@ pub fn add_genesis_accounts(genesis_config: &mut GenesisConfig, mut issued_lampo
&StakerInfo {
name: "one thanks",
staker: "3b7akieYUyCgz3Cwt5sTSErMWjg8NEygD6mbGjhGkduB",
sol: 500_000_000.0 - lamports_to_sol(issued_lamports),
lamports: 500_000_000 * SOL_LAMPORTS - issued_lamports,
},
&UNLOCKS_ALL_DAY_ZERO,
sol_to_lamports(1_000_000.0),
1_000_000 * SOL_LAMPORTS,
);
}
@ -336,6 +333,6 @@ mod tests {
.map(|(_, account)| account.lamports)
.sum::<u64>();
assert_eq!(500_000_000.0, lamports_to_sol(lamports));
assert_eq!(500_000_000 * SOL_LAMPORTS, lamports);
}
}

View File

@ -4,8 +4,8 @@ use crate::{
unlocks::{UnlockInfo, Unlocks},
};
use solana_sdk::{
account::Account, clock::Slot, genesis_config::GenesisConfig, native_token::sol_to_lamports,
pubkey::Pubkey, system_program, timing::years_as_slots,
account::Account, clock::Slot, genesis_config::GenesisConfig, pubkey::Pubkey, system_program,
timing::years_as_slots,
};
use solana_stake_program::{
self,
@ -16,7 +16,7 @@ use solana_stake_program::{
pub struct StakerInfo {
pub name: &'static str,
pub staker: &'static str,
pub sol: f64,
pub lamports: u64,
}
// lamports required to run staking operations for one year
@ -54,7 +54,7 @@ pub fn create_and_add_stakes(
.parse::<Pubkey>()
.expect("invalid custodian");
let total_lamports = sol_to_lamports(staker_info.sol);
let total_lamports = staker_info.lamports;
// staker is a system account
let staker_rent_reserve = genesis_config.rent.minimum_balance(0).max(1);
@ -154,7 +154,7 @@ pub fn create_and_add_stakes(
#[cfg(test)]
mod tests {
use super::*;
use solana_sdk::{native_token::lamports_to_sol, rent::Rent};
use solana_sdk::rent::Rent;
fn create_and_check_stakes(
genesis_config: &mut GenesisConfig,
@ -241,7 +241,7 @@ mod tests {
&StakerInfo {
name: "fun",
staker: "P1aceHo1derPubkey11111111111111111111111111",
sol: lamports_to_sol(total_lamports),
lamports: total_lamports,
},
&UnlockInfo {
cliff_fraction: 0.5,
@ -266,7 +266,7 @@ mod tests {
&StakerInfo {
name: "fun",
staker: "P1aceHo1derPubkey11111111111111111111111111",
sol: lamports_to_sol(total_lamports),
lamports: total_lamports,
},
&UnlockInfo {
cliff_fraction: 0.5,
@ -291,7 +291,7 @@ mod tests {
&StakerInfo {
name: "fun",
staker: "P1aceHo1derPubkey11111111111111111111111111",
sol: lamports_to_sol(total_lamports),
lamports: total_lamports,
},
&UnlockInfo {
cliff_fraction: 0.5,
@ -315,7 +315,7 @@ mod tests {
&StakerInfo {
name: "fun",
staker: "P1aceHo1derPubkey11111111111111111111111111",
sol: lamports_to_sol(total_lamports),
lamports: total_lamports,
},
&UnlockInfo {
cliff_fraction: 0.5,

View File

@ -1,7 +1,7 @@
//! validators generator
use solana_sdk::{
account::Account, genesis_config::GenesisConfig, native_token::sol_to_lamports, pubkey::Pubkey,
system_program, timing::years_as_slots,
account::Account, genesis_config::GenesisConfig, pubkey::Pubkey, system_program,
timing::years_as_slots,
};
use solana_vote_program::vote_state::{self, VoteState};
@ -9,7 +9,7 @@ use solana_vote_program::vote_state::{self, VoteState};
pub struct ValidatorInfo {
pub name: &'static str,
pub node: &'static str,
pub node_sol: f64,
pub node_lamports: u64,
pub vote: &'static str,
pub commission: u8,
}
@ -34,7 +34,6 @@ pub fn create_and_add_validator(
) -> u64 {
let node: Pubkey = validator_info.node.parse().expect("invalid node");
let vote: Pubkey = validator_info.vote.parse().expect("invalid vote");
let node_lamports = sol_to_lamports(validator_info.node_sol);
// node is the system account from which votes will be issued
let node_rent_reserve = genesis_config.rent.minimum_balance(0).max(1);
@ -42,7 +41,7 @@ pub fn create_and_add_validator(
let vote_rent_reserve = VoteState::get_rent_exempt_reserve(&genesis_config.rent).max(1);
let mut total_lamports = node_voting_fees + vote_rent_reserve + node_lamports;
let mut total_lamports = node_voting_fees + vote_rent_reserve + validator_info.node_lamports;
genesis_config
.accounts
@ -51,7 +50,7 @@ pub fn create_and_add_validator(
total_lamports += node_rent_reserve;
Account::new(node_rent_reserve, 0, &system_program::id())
})
.lamports += node_voting_fees + node_lamports;
.lamports += node_voting_fees + validator_info.node_lamports;
assert!(
genesis_config.accounts.get(&vote).is_none(),
@ -70,7 +69,7 @@ pub fn create_and_add_validator(
#[cfg(test)]
mod tests {
use super::*;
use solana_sdk::rent::Rent;
use solana_sdk::{native_token::SOL_LAMPORTS, rent::Rent};
fn create_and_check_validators(
genesis_config: &mut GenesisConfig,
@ -122,7 +121,7 @@ mod tests {
&[ValidatorInfo {
name: "fun",
node: "AiTDdNHW2vNtHt7PqWMHx3B8cMPRDNgc7kMiLPJM25QC", // random pubkeys
node_sol: 0.0,
node_lamports: 0,
vote: "77TQYZTHodhnxJcSuVjUvx8GYRCkykPyHtmFTFLjj1Rc",
commission: 50,
}],
@ -145,7 +144,7 @@ mod tests {
let total_lamports = VoteState::get_rent_exempt_reserve(&rent) * 2
+ calculate_voting_fees(&genesis_config, 1.0) * 2 // two vote accounts
+ rent.minimum_balance(0) // one node account
+ sol_to_lamports(1.0); // 2nd vote account ask has SOL
+ 1 * SOL_LAMPORTS; // 2nd vote account ask has SOL
// weird case, just wanted to verify that the duplicated node account gets double fees
create_and_check_validators(
@ -154,14 +153,14 @@ mod tests {
ValidatorInfo {
name: "fun",
node: "3VTm54dw8w6jTTsPH4BfoV5vo6mF985JAMtNDRYcaGFc", // random pubkeys
node_sol: 0.0,
node_lamports: 0,
vote: "GTKWbUoLw3Bv7Ld92crhyXcEk9zUu3VEKfzeuWJZdnfW",
commission: 50,
},
ValidatorInfo {
name: "unfun",
node: "3VTm54dw8w6jTTsPH4BfoV5vo6mF985JAMtNDRYcaGFc", // random pubkeys, same node
node_sol: 1.0,
node_lamports: 1 * SOL_LAMPORTS,
vote: "8XrFPRULg98kSm535kFaLV4GMnK5JQSuAymyrCHXsUcy",
commission: 50,
},
@ -190,14 +189,14 @@ mod tests {
ValidatorInfo {
name: "fun",
node: "3VTm54dw8w6jTTsPH4BfoV5vo6mF985JAMtNDRYcaGFc", // random pubkeys
node_sol: 0.0,
node_lamports: 0,
vote: "GTKWbUoLw3Bv7Ld92crhyXcEk9zUu3VEKfzeuWJZdnfW",
commission: 50,
},
ValidatorInfo {
name: "unfun",
node: "3VTm54dw8w6jTTsPH4BfoV5vo6mF985JAMtNDRYcaGFc", // random pubkeys, same node
node_sol: 0.0,
node_lamports: 0,
vote: "GTKWbUoLw3Bv7Ld92crhyXcEk9zUu3VEKfzeuWJZdnfW", // duplicate vote, bad juju
commission: 50,
},

View File

@ -733,6 +733,7 @@ impl Bank {
self.capitalization
.fetch_add(account.lamports, Ordering::Relaxed);
}
for (pubkey, account) in genesis_config.rewards_pools.iter() {
if self.get_account(&pubkey).is_some() {
panic!("{} repeated in genesis config", pubkey);