2019-11-08 20:56:57 -08:00
|
|
|
//! A command-line executable for generating the chain's genesis config.
|
2018-03-03 13:41:36 -08:00
|
|
|
|
2019-11-25 15:11:55 -08:00
|
|
|
mod address_generator;
|
2019-11-04 12:46:33 -08:00
|
|
|
mod genesis_accounts;
|
2019-11-25 15:11:55 -08:00
|
|
|
mod stakes;
|
|
|
|
mod unlocks;
|
2019-12-03 20:44:02 -08:00
|
|
|
mod validators;
|
2019-11-04 12:46:33 -08:00
|
|
|
|
2019-11-25 15:11:55 -08:00
|
|
|
use crate::genesis_accounts::add_genesis_accounts;
|
2019-11-21 09:57:27 -08:00
|
|
|
use clap::{crate_description, crate_name, value_t, value_t_or_exit, App, Arg, ArgMatches};
|
|
|
|
use solana_clap_utils::input_parsers::pubkey_of;
|
2019-12-03 11:24:01 -08:00
|
|
|
use solana_clap_utils::input_validators::is_valid_percentage;
|
2019-10-15 12:52:44 -07:00
|
|
|
use solana_genesis::Base64Account;
|
2019-11-25 15:11:55 -08:00
|
|
|
use solana_ledger::{blocktree::create_new_ledger, poh::compute_hashes_per_tick};
|
2019-10-08 22:34:26 -07:00
|
|
|
use solana_sdk::{
|
|
|
|
account::Account,
|
|
|
|
clock,
|
|
|
|
epoch_schedule::EpochSchedule,
|
|
|
|
fee_calculator::FeeCalculator,
|
2019-11-08 20:56:57 -08:00
|
|
|
genesis_config::{GenesisConfig, OperatingMode},
|
2019-11-25 15:11:55 -08:00
|
|
|
native_token::lamports_to_sol,
|
2019-10-18 17:00:51 -07:00
|
|
|
native_token::sol_to_lamports,
|
2019-10-08 22:34:26 -07:00
|
|
|
poh_config::PohConfig,
|
2019-11-21 09:57:27 -08:00
|
|
|
pubkey::Pubkey,
|
2019-10-30 16:25:12 -07:00
|
|
|
rent::Rent,
|
2019-11-21 09:57:27 -08:00
|
|
|
signature::{Keypair, KeypairUtil},
|
2019-10-08 22:34:26 -07:00
|
|
|
system_program, timing,
|
|
|
|
};
|
2019-11-20 10:12:43 -08:00
|
|
|
use solana_stake_program::stake_state;
|
2019-11-20 16:32:19 -08:00
|
|
|
use solana_storage_program::storage_contract;
|
2019-11-20 10:12:43 -08:00
|
|
|
use solana_vote_program::vote_state;
|
2019-11-26 19:23:37 -08:00
|
|
|
use std::{
|
|
|
|
collections::{BTreeMap, HashMap},
|
|
|
|
error,
|
|
|
|
fs::File,
|
|
|
|
io,
|
|
|
|
path::PathBuf,
|
|
|
|
str::FromStr,
|
|
|
|
time::Duration,
|
|
|
|
};
|
2018-03-03 13:41:36 -08:00
|
|
|
|
2019-06-11 18:47:35 -07:00
|
|
|
pub enum AccountFileFormat {
|
|
|
|
Pubkey,
|
|
|
|
Keypair,
|
|
|
|
}
|
|
|
|
|
2019-11-21 09:57:27 -08:00
|
|
|
fn required_pubkey(matches: &ArgMatches<'_>, name: &str) -> Result<Pubkey, Box<dyn error::Error>> {
|
|
|
|
pubkey_of(matches, name).ok_or_else(|| {
|
|
|
|
format!(
|
|
|
|
"Invalid pubkey or file: {}",
|
|
|
|
matches.value_of(name).unwrap()
|
|
|
|
)
|
|
|
|
.into()
|
|
|
|
})
|
2019-11-06 11:18:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn pubkey_from_str(key_str: &str) -> Result<Pubkey, Box<dyn error::Error>> {
|
|
|
|
Pubkey::from_str(key_str).or_else(|_| {
|
|
|
|
let bytes: Vec<u8> = serde_json::from_str(key_str)?;
|
|
|
|
let keypair = Keypair::from_bytes(&bytes)
|
|
|
|
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
|
|
|
|
Ok(keypair.pubkey())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-11-25 15:11:55 -08:00
|
|
|
pub fn load_genesis_accounts(file: &str, genesis_config: &mut GenesisConfig) -> io::Result<u64> {
|
|
|
|
let mut lamports = 0;
|
2019-06-06 19:24:09 -07:00
|
|
|
let accounts_file = File::open(file.to_string())?;
|
|
|
|
|
2019-10-15 12:52:44 -07:00
|
|
|
let genesis_accounts: HashMap<String, Base64Account> =
|
2019-09-06 11:15:23 -07:00
|
|
|
serde_yaml::from_reader(accounts_file)
|
|
|
|
.map_err(|err| io::Error::new(io::ErrorKind::Other, format!("{:?}", err)))?;
|
2019-06-06 19:24:09 -07:00
|
|
|
|
2019-11-06 11:18:25 -08:00
|
|
|
for (key, account_details) in genesis_accounts {
|
|
|
|
let pubkey = pubkey_from_str(key.as_str()).map_err(|err| {
|
|
|
|
io::Error::new(
|
|
|
|
io::ErrorKind::Other,
|
|
|
|
format!("Invalid pubkey/keypair {}: {:?}", key, err),
|
|
|
|
)
|
|
|
|
})?;
|
2019-06-06 19:24:09 -07:00
|
|
|
|
2019-09-24 10:42:33 -07:00
|
|
|
let owner_program_id = Pubkey::from_str(account_details.owner.as_str()).map_err(|err| {
|
|
|
|
io::Error::new(
|
|
|
|
io::ErrorKind::Other,
|
|
|
|
format!("Invalid owner: {}: {:?}", account_details.owner, err),
|
|
|
|
)
|
|
|
|
})?;
|
2019-09-06 11:15:23 -07:00
|
|
|
|
|
|
|
let mut account = Account::new(account_details.balance, 0, &owner_program_id);
|
2019-09-24 10:42:33 -07:00
|
|
|
if account_details.data != "~" {
|
|
|
|
account.data = base64::decode(account_details.data.as_str()).map_err(|err| {
|
|
|
|
io::Error::new(
|
|
|
|
io::ErrorKind::Other,
|
|
|
|
format!("Invalid account data: {}: {:?}", account_details.data, err),
|
|
|
|
)
|
|
|
|
})?;
|
|
|
|
}
|
2019-09-06 11:15:23 -07:00
|
|
|
account.executable = account_details.executable;
|
2019-11-25 15:11:55 -08:00
|
|
|
lamports += account.lamports;
|
2019-11-08 20:56:57 -08:00
|
|
|
genesis_config.add_account(pubkey, account);
|
2019-06-19 15:40:39 -07:00
|
|
|
}
|
|
|
|
|
2019-11-25 15:11:55 -08:00
|
|
|
Ok(lamports)
|
2019-06-06 19:24:09 -07:00
|
|
|
}
|
|
|
|
|
2019-11-14 11:27:01 -08:00
|
|
|
#[allow(clippy::cognitive_complexity)]
|
2018-12-08 21:44:20 -08:00
|
|
|
fn main() -> Result<(), Box<dyn error::Error>> {
|
2019-10-18 17:00:51 -07:00
|
|
|
let default_bootstrap_leader_lamports = &sol_to_lamports(500.0).to_string();
|
|
|
|
let default_bootstrap_leader_stake_lamports = &sol_to_lamports(0.5).to_string();
|
2019-06-10 22:18:32 -07:00
|
|
|
let default_target_lamports_per_signature = &FeeCalculator::default()
|
|
|
|
.target_lamports_per_signature
|
|
|
|
.to_string();
|
2019-10-08 22:34:26 -07:00
|
|
|
let default_target_signatures_per_slot = &FeeCalculator::default()
|
|
|
|
.target_signatures_per_slot
|
|
|
|
.to_string();
|
2019-10-30 16:25:12 -07:00
|
|
|
let (
|
|
|
|
default_lamports_per_byte_year,
|
|
|
|
default_rent_exemption_threshold,
|
|
|
|
default_rent_burn_percentage,
|
|
|
|
) = {
|
|
|
|
let rent = Rent::default();
|
|
|
|
(
|
|
|
|
&rent.lamports_per_byte_year.to_string(),
|
|
|
|
&rent.exemption_threshold.to_string(),
|
|
|
|
&rent.burn_percent.to_string(),
|
|
|
|
)
|
|
|
|
};
|
2019-05-18 14:01:36 -07:00
|
|
|
let default_target_tick_duration =
|
2019-11-25 23:40:36 -08:00
|
|
|
timing::duration_as_us(&PohConfig::default().target_tick_duration);
|
2019-09-06 14:30:56 -07:00
|
|
|
let default_ticks_per_slot = &clock::DEFAULT_TICKS_PER_SLOT.to_string();
|
2019-11-15 12:18:45 -08:00
|
|
|
let default_operating_mode = "softlaunch";
|
2019-05-07 20:28:41 -07:00
|
|
|
|
2019-03-13 20:54:30 -07:00
|
|
|
let matches = App::new(crate_name!())
|
|
|
|
.about(crate_description!())
|
2019-11-13 20:10:38 -08:00
|
|
|
.version(solana_clap_utils::version!())
|
2019-01-24 12:04:04 -08:00
|
|
|
.arg(
|
2019-11-06 11:18:25 -08:00
|
|
|
Arg::with_name("bootstrap_leader_pubkey_file")
|
2019-01-24 12:04:04 -08:00
|
|
|
.short("b")
|
2019-11-06 11:18:25 -08:00
|
|
|
.long("bootstrap-leader-pubkey")
|
|
|
|
.value_name("BOOTSTRAP LEADER PUBKEY")
|
2019-01-24 12:04:04 -08:00
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
2019-11-06 11:18:25 -08:00
|
|
|
.help("Path to file containing the bootstrap leader's pubkey"),
|
2019-01-24 12:04:04 -08:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("ledger_path")
|
|
|
|
.short("l")
|
|
|
|
.long("ledger")
|
|
|
|
.value_name("DIR")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
|
|
|
.help("Use directory as persistent ledger location"),
|
|
|
|
)
|
2018-07-12 14:42:01 -07:00
|
|
|
.arg(
|
2019-11-15 13:50:26 -08:00
|
|
|
Arg::with_name("faucet_lamports")
|
2018-07-12 14:42:01 -07:00
|
|
|
.short("t")
|
2019-11-15 13:50:26 -08:00
|
|
|
.long("faucet-lamports")
|
2019-03-05 17:01:57 -08:00
|
|
|
.value_name("LAMPORTS")
|
2018-07-12 14:42:01 -07:00
|
|
|
.takes_value(true)
|
2019-11-15 13:50:26 -08:00
|
|
|
.requires("faucet_pubkey_file")
|
|
|
|
.help("Number of lamports to assign to the faucet"),
|
2018-12-07 19:01:28 -08:00
|
|
|
)
|
|
|
|
.arg(
|
2019-11-15 13:50:26 -08:00
|
|
|
Arg::with_name("faucet_pubkey_file")
|
2018-11-02 14:32:05 -07:00
|
|
|
.short("m")
|
2019-11-15 13:50:26 -08:00
|
|
|
.long("faucet-pubkey")
|
|
|
|
.value_name("PUBKEY")
|
2018-11-02 14:32:05 -07:00
|
|
|
.takes_value(true)
|
2019-11-15 13:50:26 -08:00
|
|
|
.requires("faucet_lamports")
|
|
|
|
.help("Path to file containing the faucet's pubkey"),
|
2018-12-07 19:01:28 -08:00
|
|
|
)
|
2019-04-10 12:51:25 -07:00
|
|
|
.arg(
|
2019-11-06 11:18:25 -08:00
|
|
|
Arg::with_name("bootstrap_vote_pubkey_file")
|
2019-04-10 12:51:25 -07:00
|
|
|
.short("s")
|
2019-11-06 11:18:25 -08:00
|
|
|
.long("bootstrap-vote-pubkey")
|
|
|
|
.value_name("BOOTSTRAP VOTE PUBKEY")
|
2019-04-10 12:51:25 -07:00
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
2019-11-06 11:18:25 -08:00
|
|
|
.help("Path to file containing the bootstrap leader's voting pubkey"),
|
2019-05-08 12:56:11 -07:00
|
|
|
)
|
|
|
|
.arg(
|
2019-11-06 11:18:25 -08:00
|
|
|
Arg::with_name("bootstrap_stake_pubkey_file")
|
2019-05-08 12:56:11 -07:00
|
|
|
.short("k")
|
2019-11-06 11:18:25 -08:00
|
|
|
.long("bootstrap-stake-pubkey")
|
|
|
|
.value_name("BOOTSTRAP STAKE PUBKEY")
|
2019-05-08 12:56:11 -07:00
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
2019-11-06 11:18:25 -08:00
|
|
|
.help("Path to file containing the bootstrap leader's staking pubkey"),
|
2019-04-10 12:51:25 -07:00
|
|
|
)
|
2019-05-20 19:46:15 -07:00
|
|
|
.arg(
|
2019-11-06 11:18:25 -08:00
|
|
|
Arg::with_name("bootstrap_storage_pubkey_file")
|
|
|
|
.long("bootstrap-storage-pubkey")
|
|
|
|
.value_name("BOOTSTRAP STORAGE PUBKEY")
|
2019-05-20 19:46:15 -07:00
|
|
|
.takes_value(true)
|
2019-11-06 11:18:25 -08:00
|
|
|
.help("Path to file containing the bootstrap leader's storage pubkey"),
|
2019-05-20 19:46:15 -07:00
|
|
|
)
|
2019-04-16 13:03:01 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("bootstrap_leader_lamports")
|
|
|
|
.long("bootstrap-leader-lamports")
|
|
|
|
.value_name("LAMPORTS")
|
|
|
|
.takes_value(true)
|
|
|
|
.default_value(default_bootstrap_leader_lamports)
|
|
|
|
.required(true)
|
|
|
|
.help("Number of lamports to assign to the bootstrap leader"),
|
|
|
|
)
|
2019-05-31 19:58:52 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("bootstrap_leader_stake_lamports")
|
|
|
|
.long("bootstrap-leader-stake-lamports")
|
|
|
|
.value_name("LAMPORTS")
|
|
|
|
.takes_value(true)
|
2019-10-18 17:00:51 -07:00
|
|
|
.default_value(default_bootstrap_leader_stake_lamports)
|
2019-05-31 19:58:52 -07:00
|
|
|
.required(true)
|
|
|
|
.help("Number of lamports to assign to the bootstrap leader's stake account"),
|
|
|
|
)
|
2019-05-07 20:28:41 -07:00
|
|
|
.arg(
|
2019-06-10 22:18:32 -07:00
|
|
|
Arg::with_name("target_lamports_per_signature")
|
|
|
|
.long("target-lamports-per-signature")
|
2019-05-07 20:28:41 -07:00
|
|
|
.value_name("LAMPORTS")
|
|
|
|
.takes_value(true)
|
2019-06-10 22:18:32 -07:00
|
|
|
.default_value(default_target_lamports_per_signature)
|
|
|
|
.help(
|
|
|
|
"The cost in lamports that the cluster will charge for signature \
|
|
|
|
verification when the cluster is operating at target-signatures-per-slot",
|
|
|
|
),
|
|
|
|
)
|
2019-08-23 14:04:53 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("lamports_per_byte_year")
|
|
|
|
.long("lamports-per-byte-year")
|
|
|
|
.value_name("LAMPORTS")
|
|
|
|
.takes_value(true)
|
|
|
|
.default_value(default_lamports_per_byte_year)
|
|
|
|
.help(
|
|
|
|
"The cost in lamports that the cluster will charge per byte per year \
|
|
|
|
for accounts with data.",
|
|
|
|
),
|
|
|
|
)
|
2019-09-17 04:42:55 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("rent_exemption_threshold")
|
|
|
|
.long("rent-exemption-threshold")
|
|
|
|
.value_name("NUMBER")
|
|
|
|
.takes_value(true)
|
|
|
|
.default_value(default_rent_exemption_threshold)
|
|
|
|
.help(
|
|
|
|
"amount of time (in years) the balance has to include rent for \
|
|
|
|
to qualify as rent exempted account.",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("rent_burn_percentage")
|
|
|
|
.long("rent-burn-percentage")
|
|
|
|
.value_name("NUMBER")
|
|
|
|
.takes_value(true)
|
|
|
|
.default_value(default_rent_burn_percentage)
|
2019-12-03 11:24:01 -08:00
|
|
|
.help("percentage of collected rent to burn")
|
|
|
|
.validator(is_valid_percentage),
|
2019-09-17 04:42:55 -07:00
|
|
|
)
|
2019-06-10 22:18:32 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("target_signatures_per_slot")
|
|
|
|
.long("target-signatures-per-slot")
|
|
|
|
.value_name("NUMBER")
|
|
|
|
.takes_value(true)
|
|
|
|
.default_value(default_target_signatures_per_slot)
|
|
|
|
.help(
|
|
|
|
"Used to estimate the desired processing capacity of the cluster.
|
|
|
|
When the latest slot processes fewer/greater signatures than this \
|
|
|
|
value, the lamports-per-signature fee will decrease/increase for \
|
|
|
|
the next slot. A value of 0 disables signature-based fee adjustments",
|
|
|
|
),
|
2019-05-07 20:28:41 -07:00
|
|
|
)
|
2019-05-18 14:01:36 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("target_tick_duration")
|
|
|
|
.long("target-tick-duration")
|
|
|
|
.value_name("MILLIS")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("The target tick rate of the cluster in milliseconds"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("hashes_per_tick")
|
|
|
|
.long("hashes-per-tick")
|
|
|
|
.value_name("NUM_HASHES|\"auto\"|\"sleep\"")
|
|
|
|
.takes_value(true)
|
|
|
|
.default_value("auto")
|
|
|
|
.help(
|
|
|
|
"How many PoH hashes to roll before emitting the next tick. \
|
|
|
|
If \"auto\", determine based on --target-tick-duration \
|
|
|
|
and the hash rate of this computer. If \"sleep\", for development \
|
|
|
|
sleep for --target-tick-duration instead of hashing",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("ticks_per_slot")
|
|
|
|
.long("ticks-per-slot")
|
|
|
|
.value_name("TICKS")
|
|
|
|
.takes_value(true)
|
|
|
|
.default_value(default_ticks_per_slot)
|
|
|
|
.help("The number of ticks in a slot"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("slots_per_epoch")
|
|
|
|
.long("slots-per-epoch")
|
|
|
|
.value_name("SLOTS")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("The number of slots in an epoch"),
|
|
|
|
)
|
2019-06-06 19:24:09 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("primordial_accounts_file")
|
|
|
|
.long("primordial-accounts-file")
|
|
|
|
.value_name("FILENAME")
|
|
|
|
.takes_value(true)
|
2019-11-06 11:18:25 -08:00
|
|
|
.multiple(true)
|
2019-06-06 19:24:09 -07:00
|
|
|
.help("The location of pubkey for primordial accounts and balance"),
|
|
|
|
)
|
2019-10-23 11:50:10 -07:00
|
|
|
.arg(
|
2019-11-15 12:18:45 -08:00
|
|
|
Arg::with_name("operating_mode")
|
|
|
|
.long("operating-mode")
|
|
|
|
.possible_value("development")
|
|
|
|
.possible_value("softlaunch")
|
|
|
|
.takes_value(true)
|
|
|
|
.default_value(default_operating_mode)
|
|
|
|
.help(
|
|
|
|
"Configure the cluster for \"development\" mode where all features are available at epoch 0, \
|
|
|
|
or \"softlaunch\" mode where some features are disabled at epoch 0"
|
|
|
|
),
|
2019-10-23 11:50:10 -07:00
|
|
|
)
|
2018-12-07 19:01:28 -08:00
|
|
|
.get_matches();
|
2018-07-12 14:42:01 -07:00
|
|
|
|
2019-11-15 13:50:26 -08:00
|
|
|
let faucet_lamports = value_t!(matches, "faucet_lamports", u64);
|
2019-07-30 15:53:41 -07:00
|
|
|
let ledger_path = PathBuf::from(matches.value_of("ledger_path").unwrap());
|
2019-05-31 19:58:52 -07:00
|
|
|
let bootstrap_leader_lamports = value_t_or_exit!(matches, "bootstrap_leader_lamports", u64);
|
2019-05-08 12:56:11 -07:00
|
|
|
let bootstrap_leader_stake_lamports =
|
2019-05-31 19:58:52 -07:00
|
|
|
value_t_or_exit!(matches, "bootstrap_leader_stake_lamports", u64);
|
2018-07-12 14:42:01 -07:00
|
|
|
|
2019-11-21 09:57:27 -08:00
|
|
|
let bootstrap_leader_pubkey = required_pubkey(&matches, "bootstrap_leader_pubkey_file")?;
|
|
|
|
let bootstrap_vote_pubkey = required_pubkey(&matches, "bootstrap_vote_pubkey_file")?;
|
|
|
|
let bootstrap_stake_pubkey = required_pubkey(&matches, "bootstrap_stake_pubkey_file")?;
|
|
|
|
let bootstrap_storage_pubkey = pubkey_of(&matches, "bootstrap_storage_pubkey_file");
|
|
|
|
let faucet_pubkey = pubkey_of(&matches, "faucet_pubkey_file");
|
2019-11-06 11:18:25 -08:00
|
|
|
|
2019-11-12 12:33:40 -08:00
|
|
|
let rent = Rent {
|
|
|
|
lamports_per_byte_year: value_t_or_exit!(matches, "lamports_per_byte_year", u64),
|
|
|
|
exemption_threshold: value_t_or_exit!(matches, "rent_exemption_threshold", f64),
|
|
|
|
burn_percent: value_t_or_exit!(matches, "rent_burn_percentage", u8),
|
|
|
|
};
|
|
|
|
|
2019-11-25 15:11:55 -08:00
|
|
|
let bootstrap_leader_vote_account =
|
|
|
|
vote_state::create_account(&bootstrap_vote_pubkey, &bootstrap_leader_pubkey, 0, 1);
|
|
|
|
|
2019-10-25 22:58:35 -07:00
|
|
|
let bootstrap_leader_stake_account = stake_state::create_account(
|
2019-11-06 11:18:25 -08:00
|
|
|
&bootstrap_leader_pubkey,
|
|
|
|
&bootstrap_vote_pubkey,
|
2019-10-25 22:58:35 -07:00
|
|
|
&bootstrap_leader_vote_account,
|
2019-11-12 12:33:40 -08:00
|
|
|
&rent,
|
2019-08-15 18:58:46 -07:00
|
|
|
bootstrap_leader_stake_lamports,
|
|
|
|
);
|
2019-05-08 12:56:11 -07:00
|
|
|
|
2019-11-26 19:23:37 -08:00
|
|
|
let mut accounts: BTreeMap<Pubkey, Account> = [
|
2019-10-15 12:52:44 -07:00
|
|
|
// node needs an account to issue votes from
|
|
|
|
(
|
2019-11-06 11:18:25 -08:00
|
|
|
bootstrap_leader_pubkey,
|
2019-10-15 12:52:44 -07:00
|
|
|
Account::new(bootstrap_leader_lamports, 0, &system_program::id()),
|
|
|
|
),
|
|
|
|
// where votes go to
|
2019-11-06 11:18:25 -08:00
|
|
|
(bootstrap_vote_pubkey, bootstrap_leader_vote_account),
|
|
|
|
// bootstrap leader stake
|
|
|
|
(bootstrap_stake_pubkey, bootstrap_leader_stake_account),
|
2019-11-26 19:23:37 -08:00
|
|
|
]
|
|
|
|
.iter()
|
|
|
|
.cloned()
|
|
|
|
.collect();
|
2019-11-19 14:35:56 -08:00
|
|
|
|
|
|
|
if let Some(bootstrap_storage_pubkey) = bootstrap_storage_pubkey {
|
2019-11-26 19:23:37 -08:00
|
|
|
accounts.insert(
|
2019-11-06 11:18:25 -08:00
|
|
|
bootstrap_storage_pubkey,
|
|
|
|
storage_contract::create_validator_storage_account(bootstrap_leader_pubkey, 1),
|
2019-11-26 19:23:37 -08:00
|
|
|
);
|
2019-11-19 14:35:56 -08:00
|
|
|
}
|
2019-11-15 13:50:26 -08:00
|
|
|
|
2019-10-15 12:52:44 -07:00
|
|
|
let ticks_per_slot = value_t_or_exit!(matches, "ticks_per_slot", u64);
|
2019-06-11 18:47:35 -07:00
|
|
|
|
2019-10-08 22:34:26 -07:00
|
|
|
let fee_calculator = FeeCalculator::new(
|
|
|
|
value_t_or_exit!(matches, "target_lamports_per_signature", u64),
|
|
|
|
value_t_or_exit!(matches, "target_signatures_per_slot", usize),
|
|
|
|
);
|
2019-06-10 22:18:32 -07:00
|
|
|
|
2019-06-19 15:40:39 -07:00
|
|
|
let mut poh_config = PohConfig::default();
|
2019-11-25 23:40:36 -08:00
|
|
|
poh_config.target_tick_duration = if matches.is_present("target_tick_duration") {
|
|
|
|
Duration::from_micros(value_t_or_exit!(matches, "target_tick_duration", u64))
|
|
|
|
} else {
|
|
|
|
Duration::from_micros(default_target_tick_duration)
|
|
|
|
};
|
2019-05-18 14:01:36 -07:00
|
|
|
|
2019-11-16 20:53:54 -08:00
|
|
|
let operating_mode = if matches.value_of("operating_mode").unwrap() == "development" {
|
|
|
|
OperatingMode::Development
|
|
|
|
} else {
|
|
|
|
OperatingMode::SoftLaunch
|
|
|
|
};
|
|
|
|
|
2019-05-18 14:01:36 -07:00
|
|
|
match matches.value_of("hashes_per_tick").unwrap() {
|
2019-11-16 20:53:54 -08:00
|
|
|
"auto" => match operating_mode {
|
|
|
|
OperatingMode::Development => {
|
|
|
|
let hashes_per_tick =
|
|
|
|
compute_hashes_per_tick(poh_config.target_tick_duration, 1_000_000);
|
|
|
|
poh_config.hashes_per_tick = Some(hashes_per_tick);
|
|
|
|
}
|
|
|
|
OperatingMode::SoftLaunch => {
|
|
|
|
poh_config.hashes_per_tick =
|
|
|
|
Some(clock::DEFAULT_HASHES_PER_SECOND / clock::DEFAULT_TICKS_PER_SECOND);
|
|
|
|
}
|
|
|
|
},
|
2019-05-18 14:01:36 -07:00
|
|
|
"sleep" => {
|
2019-06-19 15:40:39 -07:00
|
|
|
poh_config.hashes_per_tick = None;
|
2019-05-18 14:01:36 -07:00
|
|
|
}
|
|
|
|
_ => {
|
2019-06-19 15:40:39 -07:00
|
|
|
poh_config.hashes_per_tick = Some(value_t_or_exit!(matches, "hashes_per_tick", u64));
|
2019-05-18 14:01:36 -07:00
|
|
|
}
|
|
|
|
}
|
2019-10-15 12:52:44 -07:00
|
|
|
|
2019-11-16 20:53:54 -08:00
|
|
|
let slots_per_epoch = if matches.value_of("slots_per_epoch").is_some() {
|
|
|
|
value_t_or_exit!(matches, "slots_per_epoch", u64)
|
2019-10-23 11:50:10 -07:00
|
|
|
} else {
|
2019-11-16 20:53:54 -08:00
|
|
|
match operating_mode {
|
|
|
|
OperatingMode::Development => clock::DEFAULT_DEV_SLOTS_PER_EPOCH,
|
|
|
|
OperatingMode::SoftLaunch => clock::DEFAULT_SLOTS_PER_EPOCH,
|
|
|
|
}
|
2019-10-23 11:50:10 -07:00
|
|
|
};
|
2019-11-16 20:53:54 -08:00
|
|
|
let epoch_schedule = EpochSchedule::new(slots_per_epoch);
|
|
|
|
|
2019-11-07 18:33:14 -08:00
|
|
|
let native_instruction_processors =
|
|
|
|
solana_genesis_programs::get_programs(operating_mode, 0).unwrap();
|
|
|
|
let inflation = solana_genesis_programs::get_inflation(operating_mode, 0).unwrap();
|
2019-11-25 15:11:55 -08:00
|
|
|
|
2019-11-08 20:56:57 -08:00
|
|
|
let mut genesis_config = GenesisConfig {
|
2019-10-15 12:52:44 -07:00
|
|
|
accounts,
|
2019-10-23 11:50:10 -07:00
|
|
|
native_instruction_processors,
|
2019-10-15 12:52:44 -07:00
|
|
|
ticks_per_slot,
|
|
|
|
epoch_schedule,
|
2019-11-07 18:33:14 -08:00
|
|
|
inflation,
|
2019-10-15 12:52:44 -07:00
|
|
|
fee_calculator,
|
2019-10-30 16:25:12 -07:00
|
|
|
rent,
|
2019-10-15 12:52:44 -07:00
|
|
|
poh_config,
|
2019-10-23 11:50:10 -07:00
|
|
|
operating_mode,
|
2019-11-08 20:56:57 -08:00
|
|
|
..GenesisConfig::default()
|
2019-10-15 12:52:44 -07:00
|
|
|
};
|
2019-06-19 15:40:39 -07:00
|
|
|
|
2019-11-25 15:11:55 -08:00
|
|
|
if let Some(faucet_pubkey) = faucet_pubkey {
|
|
|
|
genesis_config.add_account(
|
|
|
|
faucet_pubkey,
|
|
|
|
Account::new(faucet_lamports.unwrap(), 0, &system_program::id()),
|
|
|
|
);
|
2019-11-21 12:05:31 -08:00
|
|
|
}
|
|
|
|
|
2019-11-23 22:15:21 -08:00
|
|
|
// add genesis stuff from storage and stake
|
|
|
|
solana_storage_program::rewards_pools::add_genesis_accounts(&mut genesis_config);
|
|
|
|
solana_stake_program::add_genesis_accounts(&mut genesis_config);
|
2019-11-21 12:05:31 -08:00
|
|
|
|
2019-11-25 15:11:55 -08:00
|
|
|
if let Some(files) = matches.values_of("primordial_accounts_file") {
|
|
|
|
for file in files {
|
|
|
|
load_genesis_accounts(file, &mut genesis_config)?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
add_genesis_accounts(&mut genesis_config);
|
|
|
|
|
2019-11-08 20:56:57 -08:00
|
|
|
create_new_ledger(&ledger_path, &genesis_config)?;
|
2019-11-25 15:11:55 -08:00
|
|
|
|
|
|
|
println!(
|
|
|
|
"Genesis mode: {:?} hashes per tick: {:?} slots_per_epoch: {} capitalization: {}SOL in {} accounts",
|
|
|
|
operating_mode,
|
|
|
|
genesis_config.poh_config.hashes_per_tick,
|
|
|
|
slots_per_epoch,
|
|
|
|
lamports_to_sol(
|
|
|
|
genesis_config
|
|
|
|
.accounts
|
|
|
|
.iter()
|
|
|
|
.map(|(pubkey, account)| {
|
|
|
|
if account.lamports == 0 {
|
|
|
|
panic!("{:?}", (pubkey, account));
|
|
|
|
}
|
|
|
|
account.lamports
|
|
|
|
})
|
|
|
|
.sum::<u64>()),
|
|
|
|
genesis_config.accounts.len()
|
|
|
|
);
|
|
|
|
|
2018-07-01 08:04:41 -07:00
|
|
|
Ok(())
|
2018-03-03 13:41:36 -08:00
|
|
|
}
|
2019-03-12 11:44:41 -07:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2019-06-06 19:24:09 -07:00
|
|
|
use super::*;
|
2019-11-08 20:56:57 -08:00
|
|
|
use solana_sdk::genesis_config::GenesisConfig;
|
2019-06-06 19:24:09 -07:00
|
|
|
use solana_sdk::pubkey::Pubkey;
|
2019-06-10 19:42:49 -07:00
|
|
|
use std::collections::HashMap;
|
2019-06-06 19:24:09 -07:00
|
|
|
use std::fs::remove_file;
|
|
|
|
use std::io::Write;
|
|
|
|
use std::path::Path;
|
2019-09-06 11:15:23 -07:00
|
|
|
use tempfile;
|
2019-03-12 11:44:41 -07:00
|
|
|
|
2019-06-06 19:24:09 -07:00
|
|
|
#[test]
|
|
|
|
fn test_append_primordial_accounts_to_genesis() {
|
|
|
|
// Test invalid file returns error
|
2019-11-25 15:11:55 -08:00
|
|
|
assert!(load_genesis_accounts("unknownfile", &mut GenesisConfig::default()).is_err());
|
2019-06-06 19:24:09 -07:00
|
|
|
|
2019-11-08 20:56:57 -08:00
|
|
|
let mut genesis_config = GenesisConfig::default();
|
2019-06-19 15:40:39 -07:00
|
|
|
|
2019-10-15 12:52:44 -07:00
|
|
|
let mut genesis_accounts = HashMap::new();
|
|
|
|
genesis_accounts.insert(
|
2019-09-06 11:15:23 -07:00
|
|
|
Pubkey::new_rand().to_string(),
|
2019-10-15 12:52:44 -07:00
|
|
|
Base64Account {
|
2019-09-06 11:15:23 -07:00
|
|
|
owner: Pubkey::new_rand().to_string(),
|
|
|
|
balance: 2 as u64,
|
|
|
|
executable: false,
|
|
|
|
data: String::from("aGVsbG8="),
|
|
|
|
},
|
|
|
|
);
|
2019-10-15 12:52:44 -07:00
|
|
|
genesis_accounts.insert(
|
2019-09-06 11:15:23 -07:00
|
|
|
Pubkey::new_rand().to_string(),
|
2019-10-15 12:52:44 -07:00
|
|
|
Base64Account {
|
2019-09-06 11:15:23 -07:00
|
|
|
owner: Pubkey::new_rand().to_string(),
|
|
|
|
balance: 1 as u64,
|
|
|
|
executable: true,
|
|
|
|
data: String::from("aGVsbG8gd29ybGQ="),
|
|
|
|
},
|
|
|
|
);
|
2019-10-15 12:52:44 -07:00
|
|
|
genesis_accounts.insert(
|
2019-09-06 11:15:23 -07:00
|
|
|
Pubkey::new_rand().to_string(),
|
2019-10-15 12:52:44 -07:00
|
|
|
Base64Account {
|
2019-09-06 11:15:23 -07:00
|
|
|
owner: Pubkey::new_rand().to_string(),
|
|
|
|
balance: 3 as u64,
|
|
|
|
executable: true,
|
|
|
|
data: String::from("bWUgaGVsbG8gdG8gd29ybGQ="),
|
|
|
|
},
|
|
|
|
);
|
2019-06-06 19:24:09 -07:00
|
|
|
|
2019-10-15 12:52:44 -07:00
|
|
|
let serialized = serde_yaml::to_string(&genesis_accounts).unwrap();
|
2019-06-06 19:24:09 -07:00
|
|
|
let path = Path::new("test_append_primordial_accounts_to_genesis.yml");
|
|
|
|
let mut file = File::create(path).unwrap();
|
|
|
|
file.write_all(&serialized.into_bytes()).unwrap();
|
|
|
|
|
2019-11-25 15:11:55 -08:00
|
|
|
load_genesis_accounts(
|
2019-06-06 19:24:09 -07:00
|
|
|
"test_append_primordial_accounts_to_genesis.yml",
|
2019-11-08 20:56:57 -08:00
|
|
|
&mut genesis_config,
|
2019-06-06 19:24:09 -07:00
|
|
|
)
|
2019-06-19 15:40:39 -07:00
|
|
|
.expect("test_append_primordial_accounts_to_genesis.yml");
|
|
|
|
// Test valid file returns ok
|
2019-06-06 19:24:09 -07:00
|
|
|
|
|
|
|
remove_file(path).unwrap();
|
|
|
|
|
2019-06-19 15:40:39 -07:00
|
|
|
{
|
|
|
|
// Test all accounts were added
|
2019-11-08 20:56:57 -08:00
|
|
|
assert_eq!(genesis_config.accounts.len(), genesis_accounts.len());
|
2019-06-19 15:40:39 -07:00
|
|
|
|
|
|
|
// Test account data matches
|
2019-11-26 19:23:37 -08:00
|
|
|
for (pubkey_str, b64_account) in genesis_accounts.iter() {
|
|
|
|
let pubkey = pubkey_str.parse().unwrap();
|
2019-06-19 15:40:39 -07:00
|
|
|
assert_eq!(
|
2019-11-26 19:23:37 -08:00
|
|
|
b64_account.owner,
|
|
|
|
genesis_config.accounts[&pubkey].owner.to_string()
|
2019-09-06 11:15:23 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2019-11-26 19:23:37 -08:00
|
|
|
b64_account.balance,
|
|
|
|
genesis_config.accounts[&pubkey].lamports
|
2019-09-06 11:15:23 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2019-11-26 19:23:37 -08:00
|
|
|
b64_account.executable,
|
|
|
|
genesis_config.accounts[&pubkey].executable
|
2019-09-06 11:15:23 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2019-11-26 19:23:37 -08:00
|
|
|
b64_account.data,
|
|
|
|
base64::encode(&genesis_config.accounts[&pubkey].data)
|
2019-06-19 15:40:39 -07:00
|
|
|
);
|
2019-11-26 19:23:37 -08:00
|
|
|
}
|
2019-06-19 15:40:39 -07:00
|
|
|
}
|
2019-06-06 19:24:09 -07:00
|
|
|
|
|
|
|
// Test more accounts can be appended
|
2019-10-15 12:52:44 -07:00
|
|
|
let mut genesis_accounts1 = HashMap::new();
|
|
|
|
genesis_accounts1.insert(
|
2019-09-06 11:15:23 -07:00
|
|
|
Pubkey::new_rand().to_string(),
|
2019-10-15 12:52:44 -07:00
|
|
|
Base64Account {
|
2019-09-06 11:15:23 -07:00
|
|
|
owner: Pubkey::new_rand().to_string(),
|
|
|
|
balance: 6 as u64,
|
|
|
|
executable: true,
|
|
|
|
data: String::from("eW91IGFyZQ=="),
|
|
|
|
},
|
|
|
|
);
|
2019-10-15 12:52:44 -07:00
|
|
|
genesis_accounts1.insert(
|
2019-09-06 11:15:23 -07:00
|
|
|
Pubkey::new_rand().to_string(),
|
2019-10-15 12:52:44 -07:00
|
|
|
Base64Account {
|
2019-09-06 11:15:23 -07:00
|
|
|
owner: Pubkey::new_rand().to_string(),
|
|
|
|
balance: 5 as u64,
|
|
|
|
executable: false,
|
|
|
|
data: String::from("bWV0YSBzdHJpbmc="),
|
|
|
|
},
|
|
|
|
);
|
2019-10-15 12:52:44 -07:00
|
|
|
genesis_accounts1.insert(
|
2019-09-06 11:15:23 -07:00
|
|
|
Pubkey::new_rand().to_string(),
|
2019-10-15 12:52:44 -07:00
|
|
|
Base64Account {
|
2019-09-06 11:15:23 -07:00
|
|
|
owner: Pubkey::new_rand().to_string(),
|
|
|
|
balance: 10 as u64,
|
|
|
|
executable: false,
|
|
|
|
data: String::from("YmFzZTY0IHN0cmluZw=="),
|
|
|
|
},
|
|
|
|
);
|
2019-06-06 19:24:09 -07:00
|
|
|
|
2019-10-15 12:52:44 -07:00
|
|
|
let serialized = serde_yaml::to_string(&genesis_accounts1).unwrap();
|
2019-06-06 19:24:09 -07:00
|
|
|
let path = Path::new("test_append_primordial_accounts_to_genesis.yml");
|
|
|
|
let mut file = File::create(path).unwrap();
|
|
|
|
file.write_all(&serialized.into_bytes()).unwrap();
|
|
|
|
|
2019-11-25 15:11:55 -08:00
|
|
|
load_genesis_accounts(
|
2019-06-06 19:24:09 -07:00
|
|
|
"test_append_primordial_accounts_to_genesis.yml",
|
2019-11-08 20:56:57 -08:00
|
|
|
&mut genesis_config,
|
2019-06-06 19:24:09 -07:00
|
|
|
)
|
2019-06-19 15:40:39 -07:00
|
|
|
.expect("test_append_primordial_accounts_to_genesis.yml");
|
2019-06-06 19:24:09 -07:00
|
|
|
|
|
|
|
remove_file(path).unwrap();
|
|
|
|
|
|
|
|
// Test total number of accounts is correct
|
|
|
|
assert_eq!(
|
2019-11-08 20:56:57 -08:00
|
|
|
genesis_config.accounts.len(),
|
2019-10-15 12:52:44 -07:00
|
|
|
genesis_accounts.len() + genesis_accounts1.len()
|
2019-06-06 19:24:09 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
// Test old accounts are still there
|
2019-11-26 19:23:37 -08:00
|
|
|
for (pubkey_str, b64_account) in genesis_accounts.iter() {
|
|
|
|
let pubkey = &pubkey_str.parse().unwrap();
|
2019-06-06 19:24:09 -07:00
|
|
|
assert_eq!(
|
2019-11-26 19:23:37 -08:00
|
|
|
b64_account.balance,
|
|
|
|
genesis_config.accounts[&pubkey].lamports,
|
2019-06-06 19:24:09 -07:00
|
|
|
);
|
2019-11-26 19:23:37 -08:00
|
|
|
}
|
2019-06-06 19:24:09 -07:00
|
|
|
|
|
|
|
// Test new account data matches
|
2019-11-26 19:23:37 -08:00
|
|
|
for (pubkey_str, b64_account) in genesis_accounts1.iter() {
|
|
|
|
let pubkey = pubkey_str.parse().unwrap();
|
2019-06-06 19:24:09 -07:00
|
|
|
assert_eq!(
|
2019-11-26 19:23:37 -08:00
|
|
|
b64_account.owner,
|
|
|
|
genesis_config.accounts[&pubkey].owner.to_string()
|
2019-09-06 11:15:23 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2019-11-26 19:23:37 -08:00
|
|
|
b64_account.balance,
|
|
|
|
genesis_config.accounts[&pubkey].lamports,
|
2019-06-06 19:24:09 -07:00
|
|
|
);
|
2019-09-06 11:15:23 -07:00
|
|
|
|
|
|
|
assert_eq!(
|
2019-11-26 19:23:37 -08:00
|
|
|
b64_account.executable,
|
|
|
|
genesis_config.accounts[&pubkey].executable,
|
2019-09-06 11:15:23 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2019-11-26 19:23:37 -08:00
|
|
|
b64_account.data,
|
|
|
|
base64::encode(&genesis_config.accounts[&pubkey].data),
|
2019-09-06 11:15:23 -07:00
|
|
|
);
|
2019-11-26 19:23:37 -08:00
|
|
|
}
|
2019-06-11 18:47:35 -07:00
|
|
|
|
|
|
|
// Test accounts from keypairs can be appended
|
|
|
|
let account_keypairs: Vec<_> = (0..3).map(|_| Keypair::new()).collect();
|
2019-10-15 12:52:44 -07:00
|
|
|
let mut genesis_accounts2 = HashMap::new();
|
|
|
|
genesis_accounts2.insert(
|
2019-06-11 18:47:35 -07:00
|
|
|
serde_json::to_string(&account_keypairs[0].to_bytes().to_vec()).unwrap(),
|
2019-10-15 12:52:44 -07:00
|
|
|
Base64Account {
|
2019-09-06 11:15:23 -07:00
|
|
|
owner: Pubkey::new_rand().to_string(),
|
|
|
|
balance: 20 as u64,
|
|
|
|
executable: true,
|
|
|
|
data: String::from("Y2F0IGRvZw=="),
|
|
|
|
},
|
2019-06-11 18:47:35 -07:00
|
|
|
);
|
2019-10-15 12:52:44 -07:00
|
|
|
genesis_accounts2.insert(
|
2019-06-11 18:47:35 -07:00
|
|
|
serde_json::to_string(&account_keypairs[1].to_bytes().to_vec()).unwrap(),
|
2019-10-15 12:52:44 -07:00
|
|
|
Base64Account {
|
2019-09-06 11:15:23 -07:00
|
|
|
owner: Pubkey::new_rand().to_string(),
|
|
|
|
balance: 15 as u64,
|
|
|
|
executable: false,
|
|
|
|
data: String::from("bW9ua2V5IGVsZXBoYW50"),
|
|
|
|
},
|
2019-06-11 18:47:35 -07:00
|
|
|
);
|
2019-10-15 12:52:44 -07:00
|
|
|
genesis_accounts2.insert(
|
2019-06-11 18:47:35 -07:00
|
|
|
serde_json::to_string(&account_keypairs[2].to_bytes().to_vec()).unwrap(),
|
2019-10-15 12:52:44 -07:00
|
|
|
Base64Account {
|
2019-09-06 11:15:23 -07:00
|
|
|
owner: Pubkey::new_rand().to_string(),
|
|
|
|
balance: 30 as u64,
|
|
|
|
executable: true,
|
|
|
|
data: String::from("Y29tYSBtb2Nh"),
|
|
|
|
},
|
2019-06-11 18:47:35 -07:00
|
|
|
);
|
|
|
|
|
2019-10-15 12:52:44 -07:00
|
|
|
let serialized = serde_yaml::to_string(&genesis_accounts2).unwrap();
|
2019-06-11 18:47:35 -07:00
|
|
|
let path = Path::new("test_append_primordial_accounts_to_genesis.yml");
|
|
|
|
let mut file = File::create(path).unwrap();
|
|
|
|
file.write_all(&serialized.into_bytes()).unwrap();
|
|
|
|
|
2019-11-25 15:11:55 -08:00
|
|
|
load_genesis_accounts(
|
2019-06-11 18:47:35 -07:00
|
|
|
"test_append_primordial_accounts_to_genesis.yml",
|
2019-11-08 20:56:57 -08:00
|
|
|
&mut genesis_config,
|
2019-06-11 18:47:35 -07:00
|
|
|
)
|
2019-10-15 12:52:44 -07:00
|
|
|
.expect("genesis");
|
2019-06-11 18:47:35 -07:00
|
|
|
|
2019-11-20 16:32:19 -08:00
|
|
|
solana_storage_program::rewards_pools::add_genesis_accounts(&mut genesis_config);
|
2019-06-22 17:18:35 -07:00
|
|
|
|
2019-06-11 18:47:35 -07:00
|
|
|
remove_file(path).unwrap();
|
|
|
|
|
|
|
|
// Test total number of accounts is correct
|
|
|
|
assert_eq!(
|
2019-11-08 20:56:57 -08:00
|
|
|
genesis_config.accounts.len(),
|
2019-10-15 12:52:44 -07:00
|
|
|
genesis_accounts.len() + genesis_accounts1.len() + genesis_accounts2.len()
|
2019-06-11 18:47:35 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
// Test old accounts are still there
|
2019-11-26 19:23:37 -08:00
|
|
|
for (pubkey_str, b64_account) in genesis_accounts {
|
|
|
|
let pubkey = pubkey_str.parse().unwrap();
|
2019-06-11 18:47:35 -07:00
|
|
|
assert_eq!(
|
2019-11-26 19:23:37 -08:00
|
|
|
b64_account.balance,
|
|
|
|
genesis_config.accounts[&pubkey].lamports,
|
2019-06-11 18:47:35 -07:00
|
|
|
);
|
2019-11-26 19:23:37 -08:00
|
|
|
}
|
2019-06-11 18:47:35 -07:00
|
|
|
|
|
|
|
// Test new account data matches
|
2019-11-26 19:23:37 -08:00
|
|
|
for (pubkey_str, b64_account) in genesis_accounts1 {
|
|
|
|
let pubkey = pubkey_str.parse().unwrap();
|
2019-06-11 18:47:35 -07:00
|
|
|
assert_eq!(
|
2019-11-26 19:23:37 -08:00
|
|
|
b64_account.owner,
|
|
|
|
genesis_config.accounts[&pubkey].owner.to_string(),
|
2019-09-06 11:15:23 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2019-11-26 19:23:37 -08:00
|
|
|
b64_account.balance,
|
|
|
|
genesis_config.accounts[&pubkey].lamports,
|
2019-06-11 18:47:35 -07:00
|
|
|
);
|
2019-09-06 11:15:23 -07:00
|
|
|
|
|
|
|
assert_eq!(
|
2019-11-26 19:23:37 -08:00
|
|
|
b64_account.executable,
|
|
|
|
genesis_config.accounts[&pubkey].executable,
|
2019-09-06 11:15:23 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2019-11-26 19:23:37 -08:00
|
|
|
b64_account.data,
|
|
|
|
base64::encode(&genesis_config.accounts[&pubkey].data),
|
2019-09-06 11:15:23 -07:00
|
|
|
);
|
2019-11-26 19:23:37 -08:00
|
|
|
}
|
2019-06-11 18:47:35 -07:00
|
|
|
|
|
|
|
// Test account data for keypairs matches
|
|
|
|
account_keypairs.iter().for_each(|keypair| {
|
2019-11-26 19:23:37 -08:00
|
|
|
let keypair_str = serde_json::to_string(&keypair.to_bytes().to_vec()).unwrap();
|
|
|
|
let pubkey = keypair.pubkey();
|
2019-06-11 18:47:35 -07:00
|
|
|
assert_eq!(
|
2019-11-26 19:23:37 -08:00
|
|
|
genesis_accounts2[&keypair_str].owner,
|
|
|
|
genesis_config.accounts[&pubkey].owner.to_string(),
|
2019-09-06 11:15:23 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2019-11-26 19:23:37 -08:00
|
|
|
genesis_accounts2[&keypair_str].balance,
|
|
|
|
genesis_config.accounts[&pubkey].lamports,
|
2019-06-11 18:47:35 -07:00
|
|
|
);
|
2019-09-06 11:15:23 -07:00
|
|
|
|
|
|
|
assert_eq!(
|
2019-11-26 19:23:37 -08:00
|
|
|
genesis_accounts2[&keypair_str].executable,
|
|
|
|
genesis_config.accounts[&pubkey].executable,
|
2019-09-06 11:15:23 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2019-11-26 19:23:37 -08:00
|
|
|
genesis_accounts2[&keypair_str].data,
|
|
|
|
base64::encode(&genesis_config.accounts[&pubkey].data),
|
2019-09-06 11:15:23 -07:00
|
|
|
);
|
2019-06-11 18:47:35 -07:00
|
|
|
});
|
2019-06-06 19:24:09 -07:00
|
|
|
}
|
2019-09-06 11:15:23 -07:00
|
|
|
|
|
|
|
#[test]
|
2019-10-15 12:52:44 -07:00
|
|
|
fn test_genesis_account_struct_compatibility() {
|
2019-09-06 11:15:23 -07:00
|
|
|
let yaml_string_pubkey = "---
|
|
|
|
98frSc8R8toHoS3tQ1xWSvHCvGEADRM9hAm5qmUKjSDX:
|
2019-09-24 10:42:33 -07:00
|
|
|
balance: 4
|
2019-09-06 11:15:23 -07:00
|
|
|
owner: Gw6S9CPzR8jHku1QQMdiqcmUKjC2dhJ3gzagWduA6PGw
|
2019-09-24 10:42:33 -07:00
|
|
|
data:
|
|
|
|
executable: true
|
|
|
|
88frSc8R8toHoS3tQ1xWSvHCvGEADRM9hAm5qmUKjSDX:
|
|
|
|
balance: 3
|
|
|
|
owner: Gw7S9CPzR8jHku1QQMdiqcmUKjC2dhJ3gzagWduA6PGw
|
|
|
|
data: ~
|
2019-09-06 11:15:23 -07:00
|
|
|
executable: true
|
|
|
|
6s36rsNPDfRSvzwek7Ly3mQu9jUMwgqBhjePZMV6Acp4:
|
|
|
|
balance: 2
|
|
|
|
owner: DBC5d45LUHTCrq42ZmCdzc8A8ufwTaiYsL9pZY7KU6TR
|
|
|
|
data: aGVsbG8=
|
|
|
|
executable: false
|
|
|
|
8Y98svZv5sPHhQiPqZvqA5Z5djQ8hieodscvb61RskMJ:
|
|
|
|
balance: 1
|
|
|
|
owner: DSknYr8cPucRbx2VyssZ7Yx3iiRqNGD38VqVahkUvgV1
|
|
|
|
data: aGVsbG8gd29ybGQ=
|
|
|
|
executable: true";
|
|
|
|
|
|
|
|
let tmpfile = tempfile::NamedTempFile::new().unwrap();
|
|
|
|
let path = tmpfile.path();
|
|
|
|
let mut file = File::create(path).unwrap();
|
|
|
|
file.write_all(yaml_string_pubkey.as_bytes()).unwrap();
|
|
|
|
|
2019-11-08 20:56:57 -08:00
|
|
|
let mut genesis_config = GenesisConfig::default();
|
2019-11-25 15:11:55 -08:00
|
|
|
load_genesis_accounts(path.to_str().unwrap(), &mut genesis_config).expect("genesis");
|
2019-09-06 11:15:23 -07:00
|
|
|
remove_file(path).unwrap();
|
|
|
|
|
2019-11-08 20:56:57 -08:00
|
|
|
assert_eq!(genesis_config.accounts.len(), 4);
|
2019-09-24 10:42:33 -07:00
|
|
|
|
2019-09-06 11:15:23 -07:00
|
|
|
let yaml_string_keypair = "---
|
|
|
|
\"[17,12,234,59,35,246,168,6,64,36,169,164,219,96,253,79,238,202,164,160,195,89,9,96,179,117,255,239,32,64,124,66,233,130,19,107,172,54,86,32,119,148,4,39,199,40,122,230,249,47,150,168,163,159,83,233,97,18,25,238,103,25,253,108]\":
|
|
|
|
balance: 20
|
|
|
|
owner: 9ZfsP6Um1KU8d5gNzTsEbSJxanKYp5EPF36qUu4FJqgp
|
|
|
|
data: Y2F0IGRvZw==
|
|
|
|
executable: true
|
|
|
|
\"[36,246,244,43,37,214,110,50,134,148,148,8,205,82,233,67,223,245,122,5,149,232,213,125,244,182,26,29,56,224,70,45,42,163,71,62,222,33,229,54,73,136,53,174,128,103,247,235,222,27,219,129,180,77,225,174,220,74,201,123,97,155,159,234]\":
|
|
|
|
balance: 15
|
|
|
|
owner: F9dmtjJPi8vfLu1EJN4KkyoGdXGmVfSAhxz35Qo9RDCJ
|
|
|
|
data: bW9ua2V5IGVsZXBoYW50
|
|
|
|
executable: false
|
|
|
|
\"[103,27,132,107,42,149,72,113,24,138,225,109,209,31,158,6,26,11,8,76,24,128,131,215,156,80,251,114,103,220,111,235,56,22,87,5,209,56,53,12,224,170,10,66,82,42,11,138,51,76,120,27,166,200,237,16,200,31,23,5,57,22,131,221]\":
|
|
|
|
balance: 30
|
|
|
|
owner: AwAR5mAbNPbvQ4CvMeBxwWE8caigQoMC2chkWAbh2b9V
|
|
|
|
data: Y29tYSBtb2Nh
|
|
|
|
executable: true";
|
|
|
|
|
|
|
|
let tmpfile = tempfile::NamedTempFile::new().unwrap();
|
|
|
|
let path = tmpfile.path();
|
|
|
|
let mut file = File::create(path).unwrap();
|
|
|
|
file.write_all(yaml_string_keypair.as_bytes()).unwrap();
|
|
|
|
|
2019-11-08 20:56:57 -08:00
|
|
|
let mut genesis_config = GenesisConfig::default();
|
2019-11-25 15:11:55 -08:00
|
|
|
load_genesis_accounts(path.to_str().unwrap(), &mut genesis_config).expect("genesis");
|
2019-09-06 11:15:23 -07:00
|
|
|
remove_file(path).unwrap();
|
2019-09-24 10:42:33 -07:00
|
|
|
|
2019-11-08 20:56:57 -08:00
|
|
|
assert_eq!(genesis_config.accounts.len(), 3);
|
2019-09-06 11:15:23 -07:00
|
|
|
}
|
2019-03-12 11:44:41 -07:00
|
|
|
}
|