solana-keygen no longer blindly overwrites a keypair, or assumes "new" (#4599)

automerge
This commit is contained in:
Michael Vines
2019-06-07 17:54:54 -07:00
committed by Grimes
parent 66c41b3e8c
commit a9f73ea321
10 changed files with 65 additions and 45 deletions

View File

@ -49,7 +49,7 @@ $ cargo run -- --help
Given a solana release tarball (as created by `ci/publish-tarball.sh`) that has already been uploaded to a publicly accessible URL, Given a solana release tarball (as created by `ci/publish-tarball.sh`) that has already been uploaded to a publicly accessible URL,
the following commands will deploy the update: the following commands will deploy the update:
```bash ```bash
$ solana-keygen -o update-manifest.json # <-- only generated once, the public key is shared with users $ solana-keygen new -o update-manifest.json # <-- only generated once, the public key is shared with users
$ solana-install deploy http://example.com/path/to/solana-release.tar.bz2 update-manifest.json $ solana-install deploy http://example.com/path/to/solana-release.tar.bz2 update-manifest.json
``` ```

View File

@ -131,7 +131,7 @@ $ solana-gossip --entrypoint testnet.solana.com:8001 spy
Now configure a key pair for your validator by running: Now configure a key pair for your validator by running:
```bash ```bash
$ solana-keygen -o ~/validator-keypair.json $ solana-keygen new -o ~/validator-keypair.json
$ solana-keygen pubkey ~/validator-keypair.json $ solana-keygen pubkey ~/validator-keypair.json
``` ```

View File

@ -307,7 +307,7 @@ while [[ $iteration -le $iterations ]]; do
source multinode-demo/common.sh source multinode-demo/common.sh
set -x set -x
client_keypair=/tmp/client-id.json-$$ client_keypair=/tmp/client-id.json-$$
$solana_keygen -o $client_keypair || exit $? $solana_keygen new -o $client_keypair || exit $?
$solana_gossip spy --num-nodes-exactly $numNodes || exit $? $solana_gossip spy --num-nodes-exactly $numNodes || exit $?
rm -rf $client_keypair rm -rf $client_keypair
) || flag_error ) || flag_error

View File

@ -1,12 +1,29 @@
use clap::{crate_description, crate_name, crate_version, App, Arg, SubCommand}; use clap::{
crate_description, crate_name, crate_version, App, AppSettings, Arg, ArgMatches, SubCommand,
};
use solana_sdk::pubkey::write_pubkey; use solana_sdk::pubkey::write_pubkey;
use solana_sdk::signature::{gen_keypair_file, read_keypair, KeypairUtil}; use solana_sdk::signature::{gen_keypair_file, read_keypair, KeypairUtil};
use std::error; use std::error;
use std::path::Path;
use std::process::exit;
fn check_for_overwrite(outfile: &str, matches: &ArgMatches) {
let force = matches.is_present("force");
if !force && Path::new(outfile).exists() {
eprintln!("Refusing to overwrite {} without --force flag", outfile);
exit(1);
}
}
fn main() -> Result<(), Box<dyn error::Error>> { fn main() -> Result<(), Box<dyn error::Error>> {
let matches = App::new(crate_name!()) let matches = App::new(crate_name!())
.about(crate_description!()) .about(crate_description!())
.version(crate_version!()) .version(crate_version!())
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(
SubCommand::with_name("new")
.about("Generate new keypair file")
.setting(AppSettings::DisableVersion)
.arg( .arg(
Arg::with_name("outfile") Arg::with_name("outfile")
.short("o") .short("o")
@ -15,21 +32,17 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.takes_value(true) .takes_value(true)
.help("Path to generated file"), .help("Path to generated file"),
) )
.subcommand(
SubCommand::with_name("new")
.about("Generate new keypair file")
.arg( .arg(
Arg::with_name("outfile") Arg::with_name("force")
.short("o") .short("f")
.long("outfile") .long("force")
.value_name("PATH") .help("Overwrite the output file if it exists"),
.takes_value(true)
.help("Path to generated file"),
), ),
) )
.subcommand( .subcommand(
SubCommand::with_name("pubkey") SubCommand::with_name("pubkey")
.about("Display the pubkey from a keypair file") .about("Display the pubkey from a keypair file")
.setting(AppSettings::DisableVersion)
.arg( .arg(
Arg::with_name("infile") Arg::with_name("infile")
.index(1) .index(1)
@ -44,48 +57,55 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.value_name("PATH") .value_name("PATH")
.takes_value(true) .takes_value(true)
.help("Path to generated file"), .help("Path to generated file"),
)
.arg(
Arg::with_name("force")
.short("f")
.long("force")
.help("Overwrite the output file if it exists"),
), ),
) )
.get_matches(); .get_matches();
match matches.subcommand() { match matches.subcommand() {
("pubkey", Some(pubkey_matches)) => { ("pubkey", Some(matches)) => {
let mut path = dirs::home_dir().expect("home directory"); let mut path = dirs::home_dir().expect("home directory");
let infile = if pubkey_matches.is_present("infile") { let infile = if matches.is_present("infile") {
pubkey_matches.value_of("infile").unwrap() matches.value_of("infile").unwrap()
} else { } else {
path.extend(&[".config", "solana", "id.json"]); path.extend(&[".config", "solana", "id.json"]);
path.to_str().unwrap() path.to_str().unwrap()
}; };
let keypair = read_keypair(infile)?; let keypair = read_keypair(infile)?;
if pubkey_matches.is_present("outfile") { if matches.is_present("outfile") {
let outfile = pubkey_matches.value_of("outfile").unwrap(); let outfile = matches.value_of("outfile").unwrap();
check_for_overwrite(&outfile, &matches);
write_pubkey(outfile, keypair.pubkey())?; write_pubkey(outfile, keypair.pubkey())?;
} else { } else {
println!("{}", keypair.pubkey()); println!("{}", keypair.pubkey());
} }
} }
match_tuple => { ("new", Some(matches)) => {
let working_matches = if let (_, Some(new_matches)) = match_tuple {
new_matches
} else {
&matches
};
let mut path = dirs::home_dir().expect("home directory"); let mut path = dirs::home_dir().expect("home directory");
let outfile = if working_matches.is_present("outfile") { let outfile = if matches.is_present("outfile") {
working_matches.value_of("outfile").unwrap() matches.value_of("outfile").unwrap()
} else { } else {
path.extend(&[".config", "solana", "id.json"]); path.extend(&[".config", "solana", "id.json"]);
path.to_str().unwrap() path.to_str().unwrap()
}; };
if outfile != "-" {
check_for_overwrite(&outfile, &matches);
}
let serialized_keypair = gen_keypair_file(outfile)?; let serialized_keypair = gen_keypair_file(outfile)?;
if outfile == "-" { if outfile == "-" {
println!("{}", serialized_keypair); println!("{}", serialized_keypair);
} else {
println!("Wrote {}", outfile);
} }
} }
_ => unreachable!(),
} }
Ok(()) Ok(())

View File

@ -260,8 +260,8 @@ if [[ $node_type = replicator ]]; then
configured_flag=$SOLANA_CONFIG_DIR/replicator$label.configured configured_flag=$SOLANA_CONFIG_DIR/replicator$label.configured
mkdir -p "$SOLANA_CONFIG_DIR" mkdir -p "$SOLANA_CONFIG_DIR"
[[ -r "$identity_keypair_path" ]] || $solana_keygen -o "$identity_keypair_path" [[ -r "$identity_keypair_path" ]] || $solana_keygen new -o "$identity_keypair_path"
[[ -r "$storage_keypair_path" ]] || $solana_keygen -o "$storage_keypair_path" [[ -r "$storage_keypair_path" ]] || $solana_keygen new -o "$storage_keypair_path"
identity_pubkey=$($solana_keygen pubkey "$identity_keypair_path") identity_pubkey=$($solana_keygen pubkey "$identity_keypair_path")
storage_pubkey=$($solana_keygen pubkey "$storage_keypair_path") storage_pubkey=$($solana_keygen pubkey "$storage_keypair_path")
@ -318,10 +318,10 @@ elif [[ $node_type = validator ]]; then
configured_flag=$SOLANA_CONFIG_DIR/validator$label.configured configured_flag=$SOLANA_CONFIG_DIR/validator$label.configured
mkdir -p "$SOLANA_CONFIG_DIR" mkdir -p "$SOLANA_CONFIG_DIR"
[[ -r "$identity_keypair_path" ]] || $solana_keygen -o "$identity_keypair_path" [[ -r "$identity_keypair_path" ]] || $solana_keygen new -o "$identity_keypair_path"
[[ -r "$vote_keypair_path" ]] || $solana_keygen -o "$vote_keypair_path" [[ -r "$vote_keypair_path" ]] || $solana_keygen new -o "$vote_keypair_path"
[[ -r "$stake_keypair_path" ]] || $solana_keygen -o "$stake_keypair_path" [[ -r "$stake_keypair_path" ]] || $solana_keygen new -o "$stake_keypair_path"
[[ -r "$storage_keypair_path" ]] || $solana_keygen -o "$storage_keypair_path" [[ -r "$storage_keypair_path" ]] || $solana_keygen new -o "$storage_keypair_path"
default_arg --entrypoint "$entrypoint_address" default_arg --entrypoint "$entrypoint_address"
default_arg --rpc-drone-address "${entrypoint_address%:*}:9900" default_arg --rpc-drone-address "${entrypoint_address%:*}:9900"

View File

@ -8,11 +8,11 @@ set -e
"$here"/clear-config.sh "$here"/clear-config.sh
# Create genesis ledger # Create genesis ledger
$solana_keygen -o "$SOLANA_CONFIG_DIR"/mint-keypair.json $solana_keygen new -o "$SOLANA_CONFIG_DIR"/mint-keypair.json
$solana_keygen -o "$SOLANA_CONFIG_DIR"/bootstrap-leader-keypair.json $solana_keygen new -o "$SOLANA_CONFIG_DIR"/bootstrap-leader-keypair.json
$solana_keygen -o "$SOLANA_CONFIG_DIR"/bootstrap-leader-vote-keypair.json $solana_keygen new -o "$SOLANA_CONFIG_DIR"/bootstrap-leader-vote-keypair.json
$solana_keygen -o "$SOLANA_CONFIG_DIR"/bootstrap-leader-stake-keypair.json $solana_keygen new -o "$SOLANA_CONFIG_DIR"/bootstrap-leader-stake-keypair.json
$solana_keygen -o "$SOLANA_CONFIG_DIR"/bootstrap-leader-storage-keypair.json $solana_keygen new -o "$SOLANA_CONFIG_DIR"/bootstrap-leader-storage-keypair.json
args=("$@") args=("$@")
default_arg --bootstrap-leader-keypair "$SOLANA_CONFIG_DIR"/bootstrap-leader-keypair.json default_arg --bootstrap-leader-keypair "$SOLANA_CONFIG_DIR"/bootstrap-leader-keypair.json

View File

@ -65,7 +65,7 @@ solana-bench-tps)
" "
;; ;;
solana-bench-exchange) solana-bench-exchange)
solana-keygen -o bench.keypair solana-keygen new -o bench.keypair
clientCommand="\ clientCommand="\
solana-bench-exchange \ solana-bench-exchange \
--entrypoint $entrypointIp:8001 \ --entrypoint $entrypointIp:8001 \

View File

@ -102,7 +102,7 @@ fi
echo "+++ $sanityTargetIp: node count ($numSanityNodes expected)" echo "+++ $sanityTargetIp: node count ($numSanityNodes expected)"
( (
set -x set -x
$solana_keygen -o "$client_id" $solana_keygen new -o "$client_id"
nodeArg="num-nodes" nodeArg="num-nodes"
if $rejectExtraNodes; then if $rejectExtraNodes; then

10
run.sh
View File

@ -45,22 +45,22 @@ leader_keypair="$dataDir/leader-keypair.json"
if [[ -e $leader_keypair ]]; then if [[ -e $leader_keypair ]]; then
echo "Use existing leader keypair" echo "Use existing leader keypair"
else else
solana-keygen -o "$leader_keypair" solana-keygen new -o "$leader_keypair"
fi fi
leader_vote_account_keypair="$dataDir/leader-vote-account-keypair.json" leader_vote_account_keypair="$dataDir/leader-vote-account-keypair.json"
if [[ -e $leader_vote_account_keypair ]]; then if [[ -e $leader_vote_account_keypair ]]; then
echo "Use existing leader vote account keypair" echo "Use existing leader vote account keypair"
else else
solana-keygen -o "$leader_vote_account_keypair" solana-keygen new -o "$leader_vote_account_keypair"
fi fi
leader_stake_account_keypair="$dataDir/leader-stake-account-keypair.json" leader_stake_account_keypair="$dataDir/leader-stake-account-keypair.json"
if [[ -e $leader_stake_account_keypair ]]; then if [[ -e $leader_stake_account_keypair ]]; then
echo "Use existing leader stake account keypair" echo "Use existing leader stake account keypair"
else else
solana-keygen -o "$leader_stake_account_keypair" solana-keygen new -o "$leader_stake_account_keypair"
fi fi
solana-keygen -o "$dataDir"/drone-keypair.json solana-keygen new -o "$dataDir"/drone-keypair.json
solana-keygen -o "$dataDir"/leader-storage-account-keypair.json solana-keygen new -o "$dataDir"/leader-storage-account-keypair.json
leaderVoteAccountPubkey=$(\ leaderVoteAccountPubkey=$(\
solana-wallet \ solana-wallet \

View File

@ -43,7 +43,7 @@ pay_and_confirm() {
$solana_wallet "${entrypoint[@]}" confirm "$signature" $solana_wallet "${entrypoint[@]}" confirm "$signature"
} }
$solana_keygen $solana_keygen new
node_readiness=false node_readiness=false
timeout=60 timeout=60