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, unlocks::UnlockInfo,
validators::{create_and_add_validator, ValidatorInfo}, validators::{create_and_add_validator, ValidatorInfo},
}; };
use solana_sdk::{ use solana_sdk::{genesis_config::GenesisConfig, native_token::SOL_LAMPORTS};
genesis_config::GenesisConfig,
native_token::{lamports_to_sol, sol_to_lamports},
};
// 30 month schedule is 1/5th every 6 months for 30 months // 30 month schedule is 1/5th every 6 months for 30 months
const UNLOCKS_BY_FIFTHS_FOR_30_MONTHS: UnlockInfo = UnlockInfo { const UNLOCKS_BY_FIFTHS_FOR_30_MONTHS: UnlockInfo = UnlockInfo {
@ -39,107 +36,107 @@ pub const BATCH_FOUR_STAKER_INFOS: &[StakerInfo] = &[
StakerInfo { StakerInfo {
name: "impossible pizza", name: "impossible pizza",
staker: "CDtJpwRSiPRDGeKrvymWQKM7JY9M3hU7iimEKBDxZyoP", staker: "CDtJpwRSiPRDGeKrvymWQKM7JY9M3hU7iimEKBDxZyoP",
sol: 5_000_000.0, lamports: 5_000_000 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "wretched texture", name: "wretched texture",
staker: "HbENu65qjWLEB5TrMouSSWLq9mbtGx2bvfhPjk2FpYek", staker: "HbENu65qjWLEB5TrMouSSWLq9mbtGx2bvfhPjk2FpYek",
sol: 225_000.0, lamports: 225_000 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "nutritious examination", name: "nutritious examination",
staker: "C9CfFpmLDsQsz6wt7MrrZquNB5oS4QkpJkmDAiboVEZZ", staker: "C9CfFpmLDsQsz6wt7MrrZquNB5oS4QkpJkmDAiboVEZZ",
sol: 5_000_000.0, lamports: 5_000_000 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "tidy impression", name: "tidy impression",
staker: "6ne6Rbag4FAnop1KNgVdM1SEHnJEysHSWyqvRpFrzaig", staker: "6ne6Rbag4FAnop1KNgVdM1SEHnJEysHSWyqvRpFrzaig",
sol: 5_000_000.0, lamports: 5_000_000 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "unbecoming silver", name: "unbecoming silver",
staker: "42yapY7Vrs5jqht9TCKZsPoyb4vDFYcPfRkqAP85NSAQ", staker: "42yapY7Vrs5jqht9TCKZsPoyb4vDFYcPfRkqAP85NSAQ",
sol: 28_800.0, lamports: 28_800 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "dramatic treatment", name: "dramatic treatment",
staker: "GTyawCMwt3kMb51AgDtfdp97mDot7jNwc8ifuS9qqANg", staker: "GTyawCMwt3kMb51AgDtfdp97mDot7jNwc8ifuS9qqANg",
sol: 1_205_602.0, lamports: 1_205_602 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "angry noise", name: "angry noise",
staker: "Fqxs9MhqjKuMq6YwjBG4ktEapuZQ3kj19mpuHLZKtkg9", staker: "Fqxs9MhqjKuMq6YwjBG4ktEapuZQ3kj19mpuHLZKtkg9",
sol: 5_000_000.0, lamports: 5_000_000 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "hard cousin", name: "hard cousin",
staker: "9MYDzj7QuAX9QAK7da1GhzPB4gA3qbPNWsW3MMSZobru", staker: "9MYDzj7QuAX9QAK7da1GhzPB4gA3qbPNWsW3MMSZobru",
sol: 5_000_000.0, lamports: 5_000_000 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "inexpensive uncle", name: "inexpensive uncle",
staker: "E4DLNkmdL34ejA48ApfPDoFVuD9XWAFqi8bXzBGRhKst", staker: "E4DLNkmdL34ejA48ApfPDoFVuD9XWAFqi8bXzBGRhKst",
sol: 300_000.0, lamports: 300_000 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "lopsided skill", name: "lopsided skill",
staker: "8cV7zCTF5UMrZakZXiL2Jw5uY3ms2Wz4twzFXEY9Kge2", staker: "8cV7zCTF5UMrZakZXiL2Jw5uY3ms2Wz4twzFXEY9Kge2",
sol: 5_000_000.0, lamports: 5_000_000 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "red snake", name: "red snake",
staker: "JBGnGdLyo7V2z9hz51mnnbyDp9sBACtw5WYH9YRG8n7e", staker: "JBGnGdLyo7V2z9hz51mnnbyDp9sBACtw5WYH9YRG8n7e",
sol: 3_655_292.0, lamports: 3_655_292 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "hellish money", name: "hellish money",
staker: "CqKdQ57mBj2mKcAbpjWc28Ls7yXzBXboxSTCRWocmUVj", staker: "CqKdQ57mBj2mKcAbpjWc28Ls7yXzBXboxSTCRWocmUVj",
sol: 200_000.0, lamports: 200_000 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "full grape", name: "full grape",
staker: "2SCJKvh7wWo32PtfUZdVZQ84WnMWoUpF4WTm6ZxcCJ15", staker: "2SCJKvh7wWo32PtfUZdVZQ84WnMWoUpF4WTm6ZxcCJ15",
sol: 450_000.0, lamports: 450_000 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "nice ghost", name: "nice ghost",
staker: "FeumxB3gfzrVQzABBiha8AacKPY3Rf4BTFSh2aZWHqR8", staker: "FeumxB3gfzrVQzABBiha8AacKPY3Rf4BTFSh2aZWHqR8",
sol: 650_000.0, lamports: 650_000 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "jolly year", name: "jolly year",
staker: "HBwFWNGPVZgkf3yqUKxuAds5aANGWX62LzUFvZVCWLdJ", staker: "HBwFWNGPVZgkf3yqUKxuAds5aANGWX62LzUFvZVCWLdJ",
sol: 5_000_000.0, lamports: 5_000_000 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "typical initiative", name: "typical initiative",
staker: "3JMz3kaDUZEVK2JVjRqwERGMp7LbWbgUjAFBb42qxoHb", staker: "3JMz3kaDUZEVK2JVjRqwERGMp7LbWbgUjAFBb42qxoHb",
sol: 5_000_000.0, lamports: 5_000_000 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "deserted window", name: "deserted window",
staker: "XTeBBZextvHkoRqDF8yb4hihjcraKQDwTEXhzjd8fip", staker: "XTeBBZextvHkoRqDF8yb4hihjcraKQDwTEXhzjd8fip",
sol: 3_655_292.0, lamports: 3_655_292 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "eight nation", name: "eight nation",
staker: "E5bSU5ywqPiz3ije89ef5gaEC7jy81BAc72Zeb9MqeHY", staker: "E5bSU5ywqPiz3ije89ef5gaEC7jy81BAc72Zeb9MqeHY",
sol: 103_519.0, lamports: 103_519 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "earsplitting meaning", name: "earsplitting meaning",
staker: "4ZemkSoE75RFE1SVLnnmHcaNWT4qN8KFrKP2wAYfv8CB", staker: "4ZemkSoE75RFE1SVLnnmHcaNWT4qN8KFrKP2wAYfv8CB",
sol: 5_000_000.0, lamports: 5_000_000 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "alike cheese", name: "alike cheese",
staker: "72BGEwYee5txFonmpEarTEKCZVN2UxcSUgdphdhcx3V", staker: "72BGEwYee5txFonmpEarTEKCZVN2UxcSUgdphdhcx3V",
sol: 3_880_295.0, lamports: 3_880_295 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "noisy honey", name: "noisy honey",
staker: "DRp1Scyn4yJZQfMAdQew2x8RtvRmsNELN37JTK5Xvzgn", staker: "DRp1Scyn4yJZQfMAdQew2x8RtvRmsNELN37JTK5Xvzgn",
sol: 5_000_000.0, lamports: 5_000_000 * SOL_LAMPORTS,
}, },
]; ];
@ -147,12 +144,12 @@ pub const FOUNDATION_STAKER_INFOS: &[StakerInfo] = &[
StakerInfo { StakerInfo {
name: "lyrical supermarket", name: "lyrical supermarket",
staker: "GRZwoJGisLTszcxtWpeREJ98EGg8pZewhbtcrikoU7b3", staker: "GRZwoJGisLTszcxtWpeREJ98EGg8pZewhbtcrikoU7b3",
sol: 5_000_000.0, lamports: 5_000_000 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "frequent description", name: "frequent description",
staker: "J51tinoLdmEdUR27LUVymrb2LB3xQo1aSHSgmbSGdj58", staker: "J51tinoLdmEdUR27LUVymrb2LB3xQo1aSHSgmbSGdj58",
sol: 57_500_000.0, lamports: 57_500_000 * SOL_LAMPORTS,
}, },
]; ];
@ -160,12 +157,12 @@ pub const GRANTS_STAKER_INFOS: &[StakerInfo] = &[
StakerInfo { StakerInfo {
name: "rightful agreement", name: "rightful agreement",
staker: "DNaKiBwwbbqk1wVoC5AQxWQbuDhvaDVbAtXzsVos9mrc", staker: "DNaKiBwwbbqk1wVoC5AQxWQbuDhvaDVbAtXzsVos9mrc",
sol: 5_000_000.0, lamports: 5_000_000 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "tasty location", name: "tasty location",
staker: "HvXQPXAijjG1vnQs6HXVtUUtFVzi5HNgXV9LGnHvYF85", staker: "HvXQPXAijjG1vnQs6HXVtUUtFVzi5HNgXV9LGnHvYF85",
sol: 15_000_000.0, lamports: 15_000_000 * SOL_LAMPORTS,
}, },
]; ];
@ -173,17 +170,17 @@ pub const COMMUNITY_STAKER_INFOS: &[StakerInfo] = &[
StakerInfo { StakerInfo {
name: "shrill charity", name: "shrill charity",
staker: "BzuqQFnu7oNUeok9ZoJezpqu2vZJU7XR1PxVLkk6wwUD", staker: "BzuqQFnu7oNUeok9ZoJezpqu2vZJU7XR1PxVLkk6wwUD",
sol: 5_000_000.0, lamports: 5_000_000 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "legal gate", name: "legal gate",
staker: "FwMbkDZUb78aiMWhZY4BEroAcqmnrXZV77nwrg71C57d", staker: "FwMbkDZUb78aiMWhZY4BEroAcqmnrXZV77nwrg71C57d",
sol: 16_086_641.0, lamports: 16_086_641 * SOL_LAMPORTS,
}, },
StakerInfo { StakerInfo {
name: "cluttered complaint", name: "cluttered complaint",
staker: "4h1rt2ic4AXwG7p3Qqhw57EMDD4c3tLYb5J3QstGA2p5", 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", name: "01Node",
node: "5n8KCdzqtvTnhkvCrFR7errH6ZUp11kL97r2awXkfzFe", node: "5n8KCdzqtvTnhkvCrFR7errH6ZUp11kL97r2awXkfzFe",
vote: "4uYMbY5Ae5ZSRNxQ3RWVyXS9rzW7E3AMZYHuUEotxu6K", vote: "4uYMbY5Ae5ZSRNxQ3RWVyXS9rzW7E3AMZYHuUEotxu6K",
node_sol: 500.0, node_lamports: 500 * SOL_LAMPORTS,
commission: 0, commission: 0,
}, },
ValidatorInfo { ValidatorInfo {
name: "Bison Trails", name: "Bison Trails",
node: "7suRNpX7bJsXphHJtBv4ZsLjJZ1dTGeX256pLqJZdEAm", node: "7suRNpX7bJsXphHJtBv4ZsLjJZ1dTGeX256pLqJZdEAm",
vote: "DfirEZ9Up1xbE7sQji9UwtcRGe5uCcRqQtnaGpha5KNY", vote: "DfirEZ9Up1xbE7sQji9UwtcRGe5uCcRqQtnaGpha5KNY",
node_sol: 500.0, node_lamports: 500 * SOL_LAMPORTS,
commission: 0, commission: 0,
}, },
ValidatorInfo { ValidatorInfo {
name: "ChainFlow", name: "ChainFlow",
node: "2te46rxywMdCNdkvjumiBBPQoVczJFxhxEaxFavQNqe3", node: "2te46rxywMdCNdkvjumiBBPQoVczJFxhxEaxFavQNqe3",
vote: "8bRCnytB7bySmqxodNGbZuUAtncKkB8T733DD1Dm9WMb", vote: "8bRCnytB7bySmqxodNGbZuUAtncKkB8T733DD1Dm9WMb",
node_sol: 500.0, node_lamports: 500 * SOL_LAMPORTS,
commission: 0, commission: 0,
}, },
ValidatorInfo { ValidatorInfo {
name: "ChorusOne", name: "ChorusOne",
node: "ChorusXqjLC2NbiStKR6k9WoD7wu6TVTtFG8qCL5XBVa", node: "ChorusXqjLC2NbiStKR6k9WoD7wu6TVTtFG8qCL5XBVa",
vote: "ChorusvBuPwukqgDvYfWtEg8j4T1NcMgSTQ4b1UbAwgQ", vote: "ChorusvBuPwukqgDvYfWtEg8j4T1NcMgSTQ4b1UbAwgQ",
node_sol: 500.0, node_lamports: 500 * SOL_LAMPORTS,
commission: 0, commission: 0,
}, },
ValidatorInfo { ValidatorInfo {
name: "Dokia Capital", name: "Dokia Capital",
node: "GeZ5PrJi9muVCJiJAaFBNGoCEdxGEqTp7L2BmT2WTTy1", node: "GeZ5PrJi9muVCJiJAaFBNGoCEdxGEqTp7L2BmT2WTTy1",
vote: "7ZdRx2EBYoRuPfyeoNbuHodMUXcAQRcC37MUw3kP6akn", vote: "7ZdRx2EBYoRuPfyeoNbuHodMUXcAQRcC37MUw3kP6akn",
node_sol: 500.0, node_lamports: 500 * SOL_LAMPORTS,
commission: 0, commission: 0,
}, },
ValidatorInfo { ValidatorInfo {
name: "Forbole", name: "Forbole",
node: "Fe5sLQAAT7RBT8mcH1AAGCbExJQcYxcwXvp1GjrGbvxs", node: "Fe5sLQAAT7RBT8mcH1AAGCbExJQcYxcwXvp1GjrGbvxs",
vote: "Dr8MkZZuvZVQJFKtjShZYEfg6n93sc1GxevqLnGss7FW", vote: "Dr8MkZZuvZVQJFKtjShZYEfg6n93sc1GxevqLnGss7FW",
node_sol: 500.0, node_lamports: 500 * SOL_LAMPORTS,
commission: 0, commission: 0,
}, },
ValidatorInfo { ValidatorInfo {
name: "P2P.ORG - Secure Non-custodial Staking", name: "P2P.ORG - Secure Non-custodial Staking",
node: "44e8VyWoyZSE2oYHxMHMedAiHkGJqJgPd3tdt6iKoAFL", node: "44e8VyWoyZSE2oYHxMHMedAiHkGJqJgPd3tdt6iKoAFL",
vote: "BwwpzEpo1wzgV9N1987ntgNG6jLt3C9532C68pswT7Gp", vote: "BwwpzEpo1wzgV9N1987ntgNG6jLt3C9532C68pswT7Gp",
node_sol: 500.0, node_lamports: 500 * SOL_LAMPORTS,
commission: 0, commission: 0,
}, },
ValidatorInfo { ValidatorInfo {
name: "RockX", name: "RockX",
node: "Ez4iUU87ViJLCnmSy1t1Ti3DLoysFXiBseNfnRfoehyY", node: "Ez4iUU87ViJLCnmSy1t1Ti3DLoysFXiBseNfnRfoehyY",
vote: "GUdGALCHQBeqkNc2ZAht3tBXab1N5u9qJC3PAzpL54r7", vote: "GUdGALCHQBeqkNc2ZAht3tBXab1N5u9qJC3PAzpL54r7",
node_sol: 500.0, node_lamports: 500 * SOL_LAMPORTS,
commission: 0, commission: 0,
}, },
ValidatorInfo { ValidatorInfo {
name: "Stake Capital", name: "Stake Capital",
node: "HavuVVDXXsJqMzPwQ4KcF5kFm2xqjbChhyi1bgGeCQif", node: "HavuVVDXXsJqMzPwQ4KcF5kFm2xqjbChhyi1bgGeCQif",
vote: "HswPkKj1xoLLmpM8t1vy5Pbi8zYYUs9ZawswvofKsFo1", vote: "HswPkKj1xoLLmpM8t1vy5Pbi8zYYUs9ZawswvofKsFo1",
node_sol: 500.0, node_lamports: 500 * SOL_LAMPORTS,
commission: 0, commission: 0,
}, },
ValidatorInfo { ValidatorInfo {
name: "Staking Facilities", name: "Staking Facilities",
node: "pbAxyqHHPMwgEjv8kmjGxysk9rhNtN7q22eAjReq6Hj", node: "pbAxyqHHPMwgEjv8kmjGxysk9rhNtN7q22eAjReq6Hj",
vote: "4VZ3pJX19PpuGjoSB1qeN9sVQfrqgLVNg16is37adiFp", vote: "4VZ3pJX19PpuGjoSB1qeN9sVQfrqgLVNg16is37adiFp",
node_sol: 500.0, node_lamports: 500 * SOL_LAMPORTS,
commission: 0, commission: 0,
}, },
]; ];
@ -289,22 +286,22 @@ pub fn add_genesis_accounts(genesis_config: &mut GenesisConfig, mut issued_lampo
genesis_config, genesis_config,
&BATCH_FOUR_STAKER_INFOS, &BATCH_FOUR_STAKER_INFOS,
&UNLOCKS_BY_FIFTHS_FOR_30_MONTHS, &UNLOCKS_BY_FIFTHS_FOR_30_MONTHS,
sol_to_lamports(1_000_000.0), 1_000_000 * SOL_LAMPORTS,
) + add_stakes( ) + add_stakes(
genesis_config, genesis_config,
&FOUNDATION_STAKER_INFOS, &FOUNDATION_STAKER_INFOS,
&UNLOCKS_BY_TENTHS_FOR_60_MONTHS, &UNLOCKS_BY_TENTHS_FOR_60_MONTHS,
sol_to_lamports(1_000_000.0), 1_000_000 * SOL_LAMPORTS,
) + add_stakes( ) + add_stakes(
genesis_config, genesis_config,
&GRANTS_STAKER_INFOS, &GRANTS_STAKER_INFOS,
&UNLOCKS_BY_TENTHS_FOR_60_MONTHS, &UNLOCKS_BY_TENTHS_FOR_60_MONTHS,
sol_to_lamports(1_000_000.0), 1_000_000 * SOL_LAMPORTS,
) + add_stakes( ) + add_stakes(
genesis_config, genesis_config,
&COMMUNITY_STAKER_INFOS, &COMMUNITY_STAKER_INFOS,
&UNLOCKS_ALL_DAY_ZERO, &UNLOCKS_ALL_DAY_ZERO,
sol_to_lamports(1_000_000.0), 1_000_000 * SOL_LAMPORTS,
) + add_validators(genesis_config, &VALIDATOR_INFOS); ) + add_validators(genesis_config, &VALIDATOR_INFOS);
// "one thanks" (community pool) gets 500_000_000SOL (total) - above distributions // "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 { &StakerInfo {
name: "one thanks", name: "one thanks",
staker: "3b7akieYUyCgz3Cwt5sTSErMWjg8NEygD6mbGjhGkduB", staker: "3b7akieYUyCgz3Cwt5sTSErMWjg8NEygD6mbGjhGkduB",
sol: 500_000_000.0 - lamports_to_sol(issued_lamports), lamports: 500_000_000 * SOL_LAMPORTS - issued_lamports,
}, },
&UNLOCKS_ALL_DAY_ZERO, &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) .map(|(_, account)| account.lamports)
.sum::<u64>(); .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}, unlocks::{UnlockInfo, Unlocks},
}; };
use solana_sdk::{ use solana_sdk::{
account::Account, clock::Slot, genesis_config::GenesisConfig, native_token::sol_to_lamports, account::Account, clock::Slot, genesis_config::GenesisConfig, pubkey::Pubkey, system_program,
pubkey::Pubkey, system_program, timing::years_as_slots, timing::years_as_slots,
}; };
use solana_stake_program::{ use solana_stake_program::{
self, self,
@ -16,7 +16,7 @@ use solana_stake_program::{
pub struct StakerInfo { pub struct StakerInfo {
pub name: &'static str, pub name: &'static str,
pub staker: &'static str, pub staker: &'static str,
pub sol: f64, pub lamports: u64,
} }
// lamports required to run staking operations for one year // lamports required to run staking operations for one year
@ -54,7 +54,7 @@ pub fn create_and_add_stakes(
.parse::<Pubkey>() .parse::<Pubkey>()
.expect("invalid custodian"); .expect("invalid custodian");
let total_lamports = sol_to_lamports(staker_info.sol); let total_lamports = staker_info.lamports;
// staker is a system account // staker is a system account
let staker_rent_reserve = genesis_config.rent.minimum_balance(0).max(1); let staker_rent_reserve = genesis_config.rent.minimum_balance(0).max(1);
@ -154,7 +154,7 @@ pub fn create_and_add_stakes(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use solana_sdk::{native_token::lamports_to_sol, rent::Rent}; use solana_sdk::rent::Rent;
fn create_and_check_stakes( fn create_and_check_stakes(
genesis_config: &mut GenesisConfig, genesis_config: &mut GenesisConfig,
@ -241,7 +241,7 @@ mod tests {
&StakerInfo { &StakerInfo {
name: "fun", name: "fun",
staker: "P1aceHo1derPubkey11111111111111111111111111", staker: "P1aceHo1derPubkey11111111111111111111111111",
sol: lamports_to_sol(total_lamports), lamports: total_lamports,
}, },
&UnlockInfo { &UnlockInfo {
cliff_fraction: 0.5, cliff_fraction: 0.5,
@ -266,7 +266,7 @@ mod tests {
&StakerInfo { &StakerInfo {
name: "fun", name: "fun",
staker: "P1aceHo1derPubkey11111111111111111111111111", staker: "P1aceHo1derPubkey11111111111111111111111111",
sol: lamports_to_sol(total_lamports), lamports: total_lamports,
}, },
&UnlockInfo { &UnlockInfo {
cliff_fraction: 0.5, cliff_fraction: 0.5,
@ -291,7 +291,7 @@ mod tests {
&StakerInfo { &StakerInfo {
name: "fun", name: "fun",
staker: "P1aceHo1derPubkey11111111111111111111111111", staker: "P1aceHo1derPubkey11111111111111111111111111",
sol: lamports_to_sol(total_lamports), lamports: total_lamports,
}, },
&UnlockInfo { &UnlockInfo {
cliff_fraction: 0.5, cliff_fraction: 0.5,
@ -315,7 +315,7 @@ mod tests {
&StakerInfo { &StakerInfo {
name: "fun", name: "fun",
staker: "P1aceHo1derPubkey11111111111111111111111111", staker: "P1aceHo1derPubkey11111111111111111111111111",
sol: lamports_to_sol(total_lamports), lamports: total_lamports,
}, },
&UnlockInfo { &UnlockInfo {
cliff_fraction: 0.5, cliff_fraction: 0.5,

View File

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

View File

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