Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to solana-keygen #597

Merged
merged 11 commits into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ path = "src/bin/fullnode-config.rs"
name = "solana-genesis"
path = "src/bin/genesis.rs"

[[bin]]
name = "solana-mint"
path = "src/bin/mint.rs"

[[bin]]
name = "solana-drone"
path = "src/bin/drone.rs"
Expand Down
2 changes: 1 addition & 1 deletion multinode-demo/client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fi

client_json="$SOLANA_CONFIG_CLIENT_DIR"/client.json
if [[ ! -r $client_json ]]; then
$solana_mint <<<0 > "$client_json"
$solana_keygen -o "$client_json"
fi

# shellcheck disable=SC2086 # $solana_client_demo should not be quoted
Expand Down
2 changes: 1 addition & 1 deletion multinode-demo/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ solana_fullnode=$(solana_program fullnode)
solana_fullnode_config=$(solana_program fullnode-config)
solana_fullnode_cuda=$(solana_program fullnode-cuda)
solana_genesis=$(solana_program genesis)
solana_mint=$(solana_program mint)
solana_keygen=$(solana_program keygen)

export RUST_LOG=${RUST_LOG:-solana=info} # if RUST_LOG is unset, default to info
export RUST_BACKTRACE=1
Expand Down
4 changes: 2 additions & 2 deletions multinode-demo/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ if $node_type_leader; then
mkdir -p "$SOLANA_CONFIG_PRIVATE_DIR"

echo "Creating $SOLANA_CONFIG_DIR/mint.json with $num_tokens tokens"
$solana_mint <<<"$num_tokens" > "$SOLANA_CONFIG_PRIVATE_DIR"/mint.json
$solana_keygen -o "$SOLANA_CONFIG_PRIVATE_DIR"/mint.json

echo "Creating $SOLANA_CONFIG_DIR/genesis.log"
$solana_genesis < "$SOLANA_CONFIG_PRIVATE_DIR"/mint.json > "$SOLANA_CONFIG_DIR"/genesis.log
$solana_genesis --tokens="$num_tokens" < "$SOLANA_CONFIG_PRIVATE_DIR"/mint.json > "$SOLANA_CONFIG_DIR"/genesis.log

echo "Creating $SOLANA_CONFIG_DIR/leader.json"
$solana_fullnode_config "${leader_address_args[@]}" > "$SOLANA_CONFIG_DIR"/leader.json
Expand Down
2 changes: 1 addition & 1 deletion multinode-demo/wallet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fi

client_json="$SOLANA_CONFIG_CLIENT_DIR"/client.json
if [[ ! -r $client_json ]]; then
$solana_mint <<<0 > "$client_json"
$solana_keygen -o "$client_json"
fi

set -x
Expand Down
4 changes: 2 additions & 2 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ apps:
- network-bind
genesis:
command: solana-genesis
mint:
command: solana-mint
keygen:
command: solana-keygen
client-demo:
command: solana-client-demo
wallet:
Expand Down
34 changes: 11 additions & 23 deletions src/bin/client-demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ use solana::crdt::{Crdt, NodeInfo};
use solana::drone::DroneRequest;
use solana::fullnode::Config;
use solana::hash::Hash;
use solana::mint::Mint;
use solana::nat::{udp_public_bind, udp_random_bind};
use solana::ncp::Ncp;
use solana::service::Service;
use solana::signature::{GenKeys, KeyPair, KeyPairUtil};
use solana::signature::{read_keypair, GenKeys, KeyPair, KeyPairUtil};
use solana::streamer::default_window;
use solana::thin_client::ThinClient;
use solana::timing::{duration_as_ms, duration_as_s};
Expand Down Expand Up @@ -77,7 +76,7 @@ fn sample_tx_count(
fn generate_and_send_txs(
client: &mut ThinClient,
tx_clients: &[ThinClient],
id: &Mint,
id: &KeyPair,
keypairs: &[KeyPair],
leader: &NodeInfo,
txs: i64,
Expand All @@ -91,7 +90,7 @@ fn generate_and_send_txs(
let transactions: Vec<_> = if !reclaim {
keypairs
.par_iter()
.map(|keypair| Transaction::new(&id.keypair(), keypair.pubkey(), 1, *last_id))
.map(|keypair| Transaction::new(&id, keypair.pubkey(), 1, *last_id))
.collect()
} else {
keypairs
Expand Down Expand Up @@ -164,12 +163,13 @@ fn main() {
.help("/path/to/leader.json"),
)
.arg(
Arg::with_name("mint")
.short("m")
.long("mint")
Arg::with_name("keypair")
.short("k")
.long("keypair")
.value_name("PATH")
.takes_value(true)
.help("/path/to/mint.json"),
.default_value("~/.config/solana/id.json")
.help("/path/to/id.json"),
)
.arg(
Arg::with_name("num_nodes")
Expand Down Expand Up @@ -205,13 +205,7 @@ fn main() {
leader = NodeInfo::new_leader(&server_addr);
};

let id: Mint;
if let Some(m) = matches.value_of("mint") {
id = read_mint(m).expect("client mint");
} else {
eprintln!("No mint found!");
exit(1);
};
let id = read_keypair(matches.value_of("keypair").unwrap()).expect("client keypair");

if let Some(t) = matches.value_of("threads") {
threads = t.to_string().parse().expect("integer");
Expand Down Expand Up @@ -259,7 +253,7 @@ fn main() {
println!("Got last ID {:?}", last_id);

let mut seed = [0u8; 32];
seed.copy_from_slice(&id.keypair().public_key_bytes()[..32]);
seed.copy_from_slice(&id.public_key_bytes()[..32]);
let rnd = GenKeys::new(seed);

println!("Creating keypairs...");
Expand Down Expand Up @@ -433,15 +427,9 @@ fn read_leader(path: &str) -> Config {
serde_json::from_reader(file).unwrap_or_else(|_| panic!("failed to parse {}", path))
}

fn read_mint(path: &str) -> Result<Mint, Box<error::Error>> {
let file = File::open(path.to_string())?;
let mint = serde_json::from_reader(file)?;
Ok(mint)
}

fn request_airdrop(
drone_addr: &SocketAddr,
id: &Mint,
id: &KeyPair,
tokens: u64,
) -> Result<(), Box<error::Error>> {
let mut stream = TcpStream::connect(drone_addr)?;
Expand Down
29 changes: 8 additions & 21 deletions src/bin/drone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ use clap::{App, Arg};
use solana::crdt::NodeInfo;
use solana::drone::{Drone, DroneRequest};
use solana::fullnode::Config;
use solana::mint::Mint;
use std::error;
use solana::signature::read_keypair;
use std::fs::File;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::process::exit;
use std::sync::{Arc, Mutex};
use std::thread;
use tokio::net::TcpListener;
Expand All @@ -35,11 +33,12 @@ fn main() {
.help("/path/to/leader.json"),
)
.arg(
Arg::with_name("mint")
.short("m")
.long("mint")
Arg::with_name("keypair")
.short("k")
.long("keypair")
.value_name("PATH")
.takes_value(true)
.required(true)
.help("/path/to/mint.json"),
)
.arg(
Expand Down Expand Up @@ -68,13 +67,9 @@ fn main() {
leader = NodeInfo::new_leader(&server_addr);
};

let mint: Mint;
if let Some(m) = matches.value_of("mint") {
mint = read_mint(m).expect("client mint");
} else {
eprintln!("No mint found!");
exit(1);
};
let mint_keypair =
read_keypair(matches.value_of("keypair").expect("keypair")).expect("client keypair");

let time_slice: Option<u64>;
if let Some(t) = matches.value_of("time") {
time_slice = Some(t.to_string().parse().expect("integer"));
Expand All @@ -88,8 +83,6 @@ fn main() {
request_cap = None;
}

let mint_keypair = mint.keypair();

let drone_addr: SocketAddr = "0.0.0.0:9900".parse().unwrap();

let drone = Arc::new(Mutex::new(Drone::new(
Expand Down Expand Up @@ -152,9 +145,3 @@ fn read_leader(path: &str) -> Config {
let file = File::open(path).unwrap_or_else(|_| panic!("file not found: {}", path));
serde_json::from_reader(file).unwrap_or_else(|_| panic!("failed to parse {}", path))
}

fn read_mint(path: &str) -> Result<Mint, Box<error::Error>> {
let file = File::open(path.to_string())?;
let mint = serde_json::from_reader(file)?;
Ok(mint)
}
21 changes: 20 additions & 1 deletion src/bin/genesis.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
//! A command-line executable for generating the chain's genesis block.

extern crate atty;
#[macro_use]
extern crate clap;
extern crate serde_json;
extern crate solana;

use atty::{is, Stream};
use clap::{App, Arg};
use solana::entry_writer::EntryWriter;
use solana::mint::Mint;
use std::error;
use std::io::{stdin, stdout, Read};
use std::process::exit;

fn main() -> Result<(), Box<error::Error>> {
let matches = App::new("solana-genesis")
.arg(
Arg::with_name("tokens")
.short("t")
.long("tokens")
.value_name("NUMBER")
.takes_value(true)
.required(true)
.help("Number of tokens with which to initialize mint"),
)
.get_matches();

let tokens = value_t_or_exit!(matches, "tokens", i64);

if is(Stream::Stdin) {
eprintln!("nothing found on stdin, expected a json file");
exit(1);
Expand All @@ -24,7 +41,9 @@ fn main() -> Result<(), Box<error::Error>> {
exit(1);
}

let mint: Mint = serde_json::from_str(&buffer)?;
let pkcs8: Vec<u8> = serde_json::from_str(&buffer)?;
let mint = Mint::new_with_pkcs8(tokens, pkcs8);

let mut writer = stdout();
EntryWriter::write_entries(&mut writer, mint.create_entries())?;
Ok(())
Expand Down
37 changes: 36 additions & 1 deletion src/bin/keygen.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,49 @@
extern crate clap;
extern crate ring;
extern crate serde_json;

use clap::{App, Arg};
use ring::rand::SystemRandom;
use ring::signature::Ed25519KeyPair;
use std::env;
use std::error;
use std::fs::{self, File};
use std::io::Write;
use std::path::Path;

fn main() -> Result<(), Box<error::Error>> {
let matches = App::new("solana-genesis")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this name supposed to be solana-keypair?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solana-keygen, yes. fixed

.arg(
Arg::with_name("outfile")
.short("o")
.long("outfile")
.value_name("PATH")
.takes_value(true)
.help("Number of tokens with which to initialize mint"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this help looks wrong...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, thanks! fixed

)
.get_matches();

let rnd = SystemRandom::new();
let pkcs8_bytes = Ed25519KeyPair::generate_pkcs8(&rnd)?;
let serialized = serde_json::to_string(&pkcs8_bytes.to_vec())?;
println!("{}", serialized);

let mut path = env::home_dir().expect("home directory");
let outfile = if matches.is_present("outfile") {
matches.value_of("outfile").unwrap()
} else {
path.extend(&[".config", "solana", "id.json"]);
path.to_str().unwrap()
};

if outfile == "-" {
println!("{}", serialized);
} else {
if let Some(outdir) = Path::new(outfile).parent() {
fs::create_dir_all(outdir)?;
}
let mut f = File::create(outfile)?;
f.write_all(&serialized.into_bytes())?;
}

Ok(())
}
29 changes: 0 additions & 29 deletions src/bin/mint.rs

This file was deleted.

Loading