genesis: rename mint account to faucet account and make it optional (#6990)

This commit is contained in:
Michael Vines
2019-11-15 14:50:26 -07:00
committed by GitHub
parent cab2232aba
commit 5ab70c4e97
12 changed files with 52 additions and 72 deletions

View File

@ -28,7 +28,6 @@ maybeDisableAirdrops=
maybeInternalNodesStakeLamports= maybeInternalNodesStakeLamports=
maybeInternalNodesLamports= maybeInternalNodesLamports=
maybeExternalPrimordialAccountsFile= maybeExternalPrimordialAccountsFile=
maybeLamports=
maybeSlotsPerEpoch= maybeSlotsPerEpoch=
maybeTargetLamportsPerSignature= maybeTargetLamportsPerSignature=
maybeSlotsPerEpoch= maybeSlotsPerEpoch=
@ -114,9 +113,6 @@ while [[ -n $1 ]]; do
elif [[ $1 = --slots-per-epoch ]]; then elif [[ $1 = --slots-per-epoch ]]; then
maybeSlotsPerEpoch="$1 $2" maybeSlotsPerEpoch="$1 $2"
shift 2 shift 2
elif [[ $1 = --lamports ]]; then
maybeLamports="$1 $2"
shift 2
elif [[ $1 = --target-lamports-per-signature ]]; then elif [[ $1 = --target-lamports-per-signature ]]; then
maybeTargetLamportsPerSignature="$1 $2" maybeTargetLamportsPerSignature="$1 $2"
shift 2 shift 2
@ -412,7 +408,6 @@ if ! $skipStart; then
$maybeInternalNodesStakeLamports $maybeInternalNodesStakeLamports
$maybeInternalNodesLamports $maybeInternalNodesLamports
$maybeExternalPrimordialAccountsFile $maybeExternalPrimordialAccountsFile
$maybeLamports
$maybeSlotsPerEpoch $maybeSlotsPerEpoch
$maybeTargetLamportsPerSignature $maybeTargetLamportsPerSignature
$maybeNoSnapshot $maybeNoSnapshot

View File

@ -506,14 +506,6 @@ deploy() {
maybeExternalAccountsFile="--external-accounts-file ${EXTERNAL_ACCOUNTS_FILE}" maybeExternalAccountsFile="--external-accounts-file ${EXTERNAL_ACCOUNTS_FILE}"
fi fi
if [[ -z $LAMPORTS ]]; then
maybeLamports="--lamports 500000000000000000"
elif [[ $LAMPORTS == skip ]]; then
maybeLamports=""
else
maybeLamports="--lamports ${LAMPORTS}"
fi
if [[ -z $ADDITIONAL_DISK_SIZE_GB ]]; then if [[ -z $ADDITIONAL_DISK_SIZE_GB ]]; then
maybeAdditionalDisk="--validator-additional-disk-size-gb 32000" maybeAdditionalDisk="--validator-additional-disk-size-gb 32000"
elif [[ $ADDITIONAL_DISK_SIZE_GB == skip ]]; then elif [[ $ADDITIONAL_DISK_SIZE_GB == skip ]]; then
@ -522,7 +514,6 @@ deploy() {
maybeAdditionalDisk="--validator-additional-disk-size-gb ${ADDITIONAL_DISK_SIZE_GB}" maybeAdditionalDisk="--validator-additional-disk-size-gb ${ADDITIONAL_DISK_SIZE_GB}"
fi fi
# Multiple V100 GPUs are available in us-west1, us-central1 and europe-west4 # Multiple V100 GPUs are available in us-west1, us-central1 and europe-west4
# shellcheck disable=SC2068 # shellcheck disable=SC2068
# shellcheck disable=SC2086 # shellcheck disable=SC2086
@ -545,7 +536,6 @@ deploy() {
${maybeInternalNodesStakeLamports} \ ${maybeInternalNodesStakeLamports} \
${maybeInternalNodesLamports} \ ${maybeInternalNodesLamports} \
${maybeExternalAccountsFile} \ ${maybeExternalAccountsFile} \
${maybeLamports} \
--target-lamports-per-signature 1 \ --target-lamports-per-signature 1 \
--slots-per-epoch 4096 \ --slots-per-epoch 4096 \
${maybeAdditionalDisk} ${maybeAdditionalDisk}

View File

@ -1,16 +1,7 @@
use solana_sdk::{account::Account, pubkey::Pubkey, system_program}; use solana_sdk::{account::Account, pubkey::Pubkey};
pub(crate) fn create_genesis_accounts( pub(crate) fn create_genesis_accounts() -> Vec<(Pubkey, Account)> {
mint_pubkey: &Pubkey, vec![]
mint_lamports: u64,
) -> Vec<(Pubkey, Account)> {
vec![
// the mint
(
*mint_pubkey,
Account::new(mint_lamports, 0, &system_program::id()),
),
]
} }
#[cfg(test)] #[cfg(test)]
@ -19,9 +10,6 @@ mod tests {
#[test] #[test]
fn test_create_genesis_accounts() { fn test_create_genesis_accounts() {
let mint_lamports = 42; assert_eq!(create_genesis_accounts(), vec![]);
let accounts = create_genesis_accounts(&Pubkey::default(), mint_lamports);
let genesis_lamports: u64 = accounts.iter().map(|(_, account)| account.lamports).sum();
assert_eq!(genesis_lamports, mint_lamports);
} }
} }

View File

@ -3,7 +3,7 @@
mod genesis_accounts; mod genesis_accounts;
use crate::genesis_accounts::create_genesis_accounts; use crate::genesis_accounts::create_genesis_accounts;
use clap::{crate_description, crate_name, value_t_or_exit, App, Arg}; use clap::{crate_description, crate_name, value_t, value_t_or_exit, App, Arg};
use solana_genesis::Base64Account; use solana_genesis::Base64Account;
use solana_ledger::blocktree::create_new_ledger; use solana_ledger::blocktree::create_new_ledger;
use solana_ledger::poh::compute_hashes_per_tick; use solana_ledger::poh::compute_hashes_per_tick;
@ -88,7 +88,6 @@ pub fn add_genesis_accounts(file: &str, genesis_config: &mut GenesisConfig) -> i
fn main() -> Result<(), Box<dyn error::Error>> { fn main() -> Result<(), Box<dyn error::Error>> {
let default_bootstrap_leader_lamports = &sol_to_lamports(500.0).to_string(); 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(); let default_bootstrap_leader_stake_lamports = &sol_to_lamports(0.5).to_string();
let default_lamports = &sol_to_lamports(500_000_000.0).to_string();
let default_target_lamports_per_signature = &FeeCalculator::default() let default_target_lamports_per_signature = &FeeCalculator::default()
.target_lamports_per_signature .target_lamports_per_signature
.to_string(); .to_string();
@ -135,23 +134,22 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.help("Use directory as persistent ledger location"), .help("Use directory as persistent ledger location"),
) )
.arg( .arg(
Arg::with_name("lamports") Arg::with_name("faucet_lamports")
.short("t") .short("t")
.long("lamports") .long("faucet-lamports")
.value_name("LAMPORTS") .value_name("LAMPORTS")
.takes_value(true) .takes_value(true)
.default_value(default_lamports) .requires("faucet_pubkey_file")
.required(true) .help("Number of lamports to assign to the faucet"),
.help("Number of lamports to create in the mint"),
) )
.arg( .arg(
Arg::with_name("mint_pubkey_file") Arg::with_name("faucet_pubkey_file")
.short("m") .short("m")
.long("mint") .long("faucet-pubkey")
.value_name("MINT") .value_name("PUBKEY")
.takes_value(true) .takes_value(true)
.required(true) .requires("faucet_lamports")
.help("Path to file containing keys of the mint"), .help("Path to file containing the faucet's pubkey"),
) )
.arg( .arg(
Arg::with_name("bootstrap_vote_pubkey_file") Arg::with_name("bootstrap_vote_pubkey_file")
@ -314,9 +312,9 @@ fn main() -> Result<(), Box<dyn error::Error>> {
let bootstrap_vote_pubkey_file = matches.value_of("bootstrap_vote_pubkey_file").unwrap(); let bootstrap_vote_pubkey_file = matches.value_of("bootstrap_vote_pubkey_file").unwrap();
let bootstrap_stake_pubkey_file = matches.value_of("bootstrap_stake_pubkey_file").unwrap(); let bootstrap_stake_pubkey_file = matches.value_of("bootstrap_stake_pubkey_file").unwrap();
let bootstrap_storage_pubkey_file = matches.value_of("bootstrap_storage_pubkey_file").unwrap(); let bootstrap_storage_pubkey_file = matches.value_of("bootstrap_storage_pubkey_file").unwrap();
let mint_pubkey_file = matches.value_of("mint_pubkey_file").unwrap(); let faucet_pubkey_file = matches.value_of("faucet_pubkey_file");
let faucet_lamports = value_t!(matches, "faucet_lamports", u64);
let ledger_path = PathBuf::from(matches.value_of("ledger_path").unwrap()); let ledger_path = PathBuf::from(matches.value_of("ledger_path").unwrap());
let lamports = value_t_or_exit!(matches, "lamports", u64);
let bootstrap_leader_lamports = value_t_or_exit!(matches, "bootstrap_leader_lamports", u64); let bootstrap_leader_lamports = value_t_or_exit!(matches, "bootstrap_leader_lamports", u64);
let bootstrap_leader_stake_lamports = let bootstrap_leader_stake_lamports =
value_t_or_exit!(matches, "bootstrap_leader_stake_lamports", u64); value_t_or_exit!(matches, "bootstrap_leader_stake_lamports", u64);
@ -325,7 +323,6 @@ fn main() -> Result<(), Box<dyn error::Error>> {
let bootstrap_vote_pubkey = pubkey_from_file(bootstrap_vote_pubkey_file)?; let bootstrap_vote_pubkey = pubkey_from_file(bootstrap_vote_pubkey_file)?;
let bootstrap_stake_pubkey = pubkey_from_file(bootstrap_stake_pubkey_file)?; let bootstrap_stake_pubkey = pubkey_from_file(bootstrap_stake_pubkey_file)?;
let bootstrap_storage_pubkey = pubkey_from_file(bootstrap_storage_pubkey_file)?; let bootstrap_storage_pubkey = pubkey_from_file(bootstrap_storage_pubkey_file)?;
let mint_pubkey = pubkey_from_file(mint_pubkey_file)?;
let bootstrap_leader_vote_account = let bootstrap_leader_vote_account =
vote_state::create_account(&bootstrap_vote_pubkey, &bootstrap_leader_pubkey, 0, 1); vote_state::create_account(&bootstrap_vote_pubkey, &bootstrap_leader_pubkey, 0, 1);
@ -359,7 +356,14 @@ fn main() -> Result<(), Box<dyn error::Error>> {
storage_contract::create_validator_storage_account(bootstrap_leader_pubkey, 1), storage_contract::create_validator_storage_account(bootstrap_leader_pubkey, 1),
), ),
]; ];
accounts.append(&mut create_genesis_accounts(&mint_pubkey, lamports));
if let Some(faucet_pubkey_file) = faucet_pubkey_file {
accounts.append(&mut vec![(
pubkey_from_file(faucet_pubkey_file)?,
Account::new(faucet_lamports.unwrap(), 0, &system_program::id()),
)]);
}
accounts.append(&mut create_genesis_accounts());
let ticks_per_slot = value_t_or_exit!(matches, "ticks_per_slot", u64); let ticks_per_slot = value_t_or_exit!(matches, "ticks_per_slot", u64);
let slots_per_epoch = value_t_or_exit!(matches, "slots_per_epoch", u64); let slots_per_epoch = value_t_or_exit!(matches, "slots_per_epoch", u64);

View File

@ -7,8 +7,8 @@ here=$(dirname "$0")
# shellcheck source=multinode-demo/common.sh # shellcheck source=multinode-demo/common.sh
source "$here"/common.sh source "$here"/common.sh
[[ -f "$SOLANA_CONFIG_DIR"/mint-keypair.json ]] || { [[ -f "$SOLANA_CONFIG_DIR"/faucet-keypair.json ]] || {
echo "$SOLANA_CONFIG_DIR/mint-keypair.json not found, create it by running:" echo "$SOLANA_CONFIG_DIR/faucet-keypair.json not found, create it by running:"
echo echo
echo " ${here}/setup.sh" echo " ${here}/setup.sh"
exit 1 exit 1
@ -16,4 +16,4 @@ source "$here"/common.sh
set -x set -x
# shellcheck disable=SC2086 # Don't want to double quote $solana_drone # shellcheck disable=SC2086 # Don't want to double quote $solana_drone
exec $solana_drone --keypair "$SOLANA_CONFIG_DIR"/mint-keypair.json "$@" exec $solana_drone --keypair "$SOLANA_CONFIG_DIR"/faucet-keypair.json "$@"

View File

@ -10,10 +10,10 @@ rm -rf "$SOLANA_CONFIG_DIR"/bootstrap-leader
mkdir -p "$SOLANA_CONFIG_DIR"/bootstrap-leader mkdir -p "$SOLANA_CONFIG_DIR"/bootstrap-leader
# Create genesis ledger # Create genesis ledger
if [[ -r $MINT_KEYPAIR ]]; then if [[ -r $FAUCET_KEYPAIR ]]; then
cp -f "$MINT_KEYPAIR" "$SOLANA_CONFIG_DIR"/mint-keypair.json cp -f "$FAUCET_KEYPAIR" "$SOLANA_CONFIG_DIR"/faucet-keypair.json
else else
$solana_keygen new -f -o "$SOLANA_CONFIG_DIR"/mint-keypair.json $solana_keygen new -f -o "$SOLANA_CONFIG_DIR"/faucet-keypair.json
fi fi
if [[ -f $BOOTSTRAP_LEADER_IDENTITY_KEYPAIR ]]; then if [[ -f $BOOTSTRAP_LEADER_IDENTITY_KEYPAIR ]]; then
@ -32,7 +32,8 @@ default_arg --bootstrap-vote-pubkey "$SOLANA_CONFIG_DIR"/bootstrap-leader/vote-k
default_arg --bootstrap-stake-pubkey "$SOLANA_CONFIG_DIR"/bootstrap-leader/stake-keypair.json default_arg --bootstrap-stake-pubkey "$SOLANA_CONFIG_DIR"/bootstrap-leader/stake-keypair.json
default_arg --bootstrap-storage-pubkey "$SOLANA_CONFIG_DIR"/bootstrap-leader/storage-keypair.json default_arg --bootstrap-storage-pubkey "$SOLANA_CONFIG_DIR"/bootstrap-leader/storage-keypair.json
default_arg --ledger "$SOLANA_CONFIG_DIR"/bootstrap-leader default_arg --ledger "$SOLANA_CONFIG_DIR"/bootstrap-leader
default_arg --mint "$SOLANA_CONFIG_DIR"/mint-keypair.json default_arg --faucet-pubkey "$SOLANA_CONFIG_DIR"/faucet-keypair.json
default_arg --faucet-lamports 500000000000000000
default_arg --hashes-per-tick auto default_arg --hashes-per-tick auto
default_arg --operating-mode development default_arg --operating-mode development
$solana_genesis "${args[@]}" $solana_genesis "${args[@]}"

View File

@ -61,7 +61,7 @@ Operate a configured testnet
- Override the default --hashes-per-tick for the cluster - Override the default --hashes-per-tick for the cluster
--no-airdrop --no-airdrop
- If set, disables airdrops. Nodes must be funded in genesis config when airdrops are disabled. - If set, disables airdrops. Nodes must be funded in genesis config when airdrops are disabled.
--lamports NUM_LAMPORTS_TO_MINT --faucet-lamports NUM_LAMPORTS_TO_MINT
- Override the default 500000000000000000 lamports minted in genesis - Override the default 500000000000000000 lamports minted in genesis
--internal-nodes-stake-lamports NUM_LAMPORTS_PER_NODE --internal-nodes-stake-lamports NUM_LAMPORTS_PER_NODE
- Amount to stake internal nodes. - Amount to stake internal nodes.
@ -172,7 +172,7 @@ while [[ -n $1 ]]; do
elif [[ $1 = --target-lamports-per-signature ]]; then elif [[ $1 = --target-lamports-per-signature ]]; then
genesisOptions="$genesisOptions $1 $2" genesisOptions="$genesisOptions $1 $2"
shift 2 shift 2
elif [[ $1 = --lamports ]]; then elif [[ $1 = --faucet-lamports ]]; then
genesisOptions="$genesisOptions $1 $2" genesisOptions="$genesisOptions $1 $2"
shift 2 shift 2
elif [[ $1 = --operating-mode ]]; then elif [[ $1 = --operating-mode ]]; then

View File

@ -77,7 +77,7 @@ solana-bench-exchange)
idle) idle)
# Add the mint keypair to idle clients for convenience # Add the mint keypair to idle clients for convenience
net/scripts/rsync-retry.sh -vPrc \ net/scripts/rsync-retry.sh -vPrc \
"$entrypointIp":~/solana/config/mint-keypair.json ~/solana/ "$entrypointIp":~/solana/config/faucet-keypair.json ~/solana/
exit 0 exit 0
;; ;;
*) *)

View File

@ -36,5 +36,5 @@ PATH="$HOME"/.cargo/bin:"$PATH"
set -x set -x
scripts/solana-install-deploy.sh \ scripts/solana-install-deploy.sh \
--keypair config/mint-keypair.json \ --keypair config/faucet-keypair.json \
localhost "$releaseChannel" "$updatePlatform" localhost "$releaseChannel" "$updatePlatform"

View File

@ -230,7 +230,7 @@ EOF
args+=($genesisOptions) args+=($genesisOptions)
if [[ -f net/keypairs/mint.json ]]; then if [[ -f net/keypairs/mint.json ]]; then
export MINT_KEYPAIR=net/keypairs/mint.json export FAUCET_KEYPAIR=net/keypairs/mint.json
fi fi
if [[ -f net/keypairs/bootstrap-leader-identity.json ]]; then if [[ -f net/keypairs/bootstrap-leader-identity.json ]]; then
export BOOTSTRAP_LEADER_IDENTITY_KEYPAIR=net/keypairs/bootstrap-leader-identity.json export BOOTSTRAP_LEADER_IDENTITY_KEYPAIR=net/keypairs/bootstrap-leader-identity.json
@ -312,13 +312,13 @@ EOF
set -x set -x
# Add the mint keypair to validators for convenient access from tools # Add the mint keypair to validators for convenient access from tools
# like bench-tps and add to blocktreamers to run a drone # like bench-tps and add to blocktreamers to run a drone
scp "$entrypointIp":~/solana/config/mint-keypair.json config/ scp "$entrypointIp":~/solana/config/faucet-keypair.json config/
if [[ $nodeType = blockstreamer ]]; then if [[ $nodeType = blockstreamer ]]; then
# Run another drone with the mint keypair on the blockstreamer node. # Run another drone with the mint keypair on the blockstreamer node.
# Typically the blockstreamer node has a static IP/DNS name for hosting # Typically the blockstreamer node has a static IP/DNS name for hosting
# the blockexplorer web app, and is a location that somebody would expect # the blockexplorer web app, and is a location that somebody would expect
# to be able to airdrop from # to be able to airdrop from
scp "$entrypointIp":~/solana/config/mint-keypair.json config/ scp "$entrypointIp":~/solana/config/faucet-keypair.json config/
if [[ $airdropsEnabled = true ]]; then if [[ $airdropsEnabled = true ]]; then
cat >> ~/solana/on-reboot <<EOF cat >> ~/solana/on-reboot <<EOF
multinode-demo/drone.sh > drone.log 2>&1 & multinode-demo/drone.sh > drone.log 2>&1 &

6
run.sh
View File

@ -59,12 +59,12 @@ if [[ -e $leader_stake_account_keypair ]]; then
else else
solana-keygen new -o "$leader_stake_account_keypair" solana-keygen new -o "$leader_stake_account_keypair"
fi fi
solana-keygen new -f -o "$dataDir"/drone-keypair.json solana-keygen new -f -o "$dataDir"/faucet-keypair.json
solana-keygen new -f -o "$dataDir"/leader-storage-account-keypair.json solana-keygen new -f -o "$dataDir"/leader-storage-account-keypair.json
solana-genesis \ solana-genesis \
--hashes-per-tick sleep \ --hashes-per-tick sleep \
--mint "$dataDir"/drone-keypair.json \ --faucet-keypair "$dataDir"/faucet-keypair.json \
--bootstrap-leader-pubkey "$dataDir"/leader-keypair.json \ --bootstrap-leader-pubkey "$dataDir"/leader-keypair.json \
--bootstrap-vote-pubkey "$dataDir"/leader-vote-account-keypair.json \ --bootstrap-vote-pubkey "$dataDir"/leader-vote-account-keypair.json \
--bootstrap-stake-pubkey "$dataDir"/leader-stake-account-keypair.json \ --bootstrap-stake-pubkey "$dataDir"/leader-stake-account-keypair.json \
@ -78,7 +78,7 @@ abort() {
} }
trap abort INT TERM EXIT trap abort INT TERM EXIT
solana-drone --keypair "$dataDir"/drone-keypair.json & solana-drone --keypair "$dataDir"/faucet-keypair.json &
drone=$! drone=$!
args=( args=(

View File

@ -44,16 +44,16 @@ pub struct GenesisConfig {
// useful for basic tests // useful for basic tests
pub fn create_genesis_config(lamports: u64) -> (GenesisConfig, Keypair) { pub fn create_genesis_config(lamports: u64) -> (GenesisConfig, Keypair) {
let mint_keypair = Keypair::new(); let faucet_keypair = Keypair::new();
( (
GenesisConfig::new( GenesisConfig::new(
&[( &[(
mint_keypair.pubkey(), faucet_keypair.pubkey(),
Account::new(lamports, 0, &system_program::id()), Account::new(lamports, 0, &system_program::id()),
)], )],
&[solana_system_program()], &[solana_system_program()],
), ),
mint_keypair, faucet_keypair,
) )
} }
@ -180,19 +180,21 @@ mod tests {
#[test] #[test]
fn test_genesis_config() { fn test_genesis_config() {
let mint_keypair = Keypair::new(); let faucet_keypair = Keypair::new();
let mut config = GenesisConfig::default(); let mut config = GenesisConfig::default();
config.add_account( config.add_account(
mint_keypair.pubkey(), faucet_keypair.pubkey(),
Account::new(10_000, 0, &Pubkey::default()), Account::new(10_000, 0, &Pubkey::default()),
); );
config.add_account(Pubkey::new_rand(), Account::new(1, 0, &Pubkey::default())); config.add_account(Pubkey::new_rand(), Account::new(1, 0, &Pubkey::default()));
config.add_native_instruction_processor("hi".to_string(), Pubkey::new_rand()); config.add_native_instruction_processor("hi".to_string(), Pubkey::new_rand());
assert_eq!(config.accounts.len(), 2); assert_eq!(config.accounts.len(), 2);
assert!(config.accounts.iter().any( assert!(config
|(pubkey, account)| *pubkey == mint_keypair.pubkey() && account.lamports == 10_000 .accounts
)); .iter()
.any(|(pubkey, account)| *pubkey == faucet_keypair.pubkey()
&& account.lamports == 10_000));
let path = &make_tmp_path("genesis_config"); let path = &make_tmp_path("genesis_config");
config.write(&path).expect("write"); config.write(&path).expect("write");