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 10 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
5 changes: 1 addition & 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 Expand Up @@ -85,6 +81,7 @@ futures = "0.1.21"
clap = "2.31"
reqwest = "0.8.6"
influx_db_client = "0.3.4"
dirs = "1.0.2"

[dev-dependencies]
criterion = "0.2"
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
17 changes: 10 additions & 7 deletions multinode-demo/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,35 @@ done

leader_address_args=("$ip_address_arg")
validator_address_args=("$ip_address_arg" -b 9000)
id_path="$SOLANA_CONFIG_PRIVATE_DIR"/id.json
mint_path="$SOLANA_CONFIG_PRIVATE_DIR"/mint.json

set -e

echo "Cleaning $SOLANA_CONFIG_DIR"
rm -rvf "$SOLANA_CONFIG_DIR"
mkdir -p "$SOLANA_CONFIG_DIR"

rm -rvf "$SOLANA_CONFIG_PRIVATE_DIR"
mkdir -p "$SOLANA_CONFIG_PRIVATE_DIR"

if $node_type_leader; then
rm -rvf "$SOLANA_CONFIG_PRIVATE_DIR"
mkdir -p "$SOLANA_CONFIG_PRIVATE_DIR"
$solana_keygen -o "$id_path"

if $node_type_leader; then
echo "Creating $SOLANA_CONFIG_DIR/mint.json with $num_tokens tokens"
$solana_mint <<<"$num_tokens" > "$SOLANA_CONFIG_PRIVATE_DIR"/mint.json
$solana_keygen -o "$mint_path"

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" < "$mint_path" > "$SOLANA_CONFIG_DIR"/genesis.log

echo "Creating $SOLANA_CONFIG_DIR/leader.json"
$solana_fullnode_config "${leader_address_args[@]}" > "$SOLANA_CONFIG_DIR"/leader.json
$solana_fullnode_config --keypair="$id_path" "${leader_address_args[@]}" > "$SOLANA_CONFIG_DIR"/leader.json
fi


if $node_type_validator; then
echo "Creating $SOLANA_CONFIG_DIR/validator.json"
$solana_fullnode_config "${validator_address_args[@]}" > "$SOLANA_CONFIG_DIR"/validator.json
$solana_fullnode_config --keypair="$id_path" "${validator_address_args[@]}" > "$SOLANA_CONFIG_DIR"/validator.json
fi

ls -lh "$SOLANA_CONFIG_DIR"/
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/fullnode-config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
extern crate clap;
extern crate dirs;
extern crate serde_json;
extern crate solana;

use clap::{App, Arg};
use solana::crdt::{get_ip_addr, parse_port_or_addr};
use solana::fullnode::Config;
use solana::nat::get_public_ip_addr;
use solana::signature::read_pkcs8;
use std::io;
use std::net::SocketAddr;

Expand All @@ -18,6 +20,14 @@ fn main() {
.takes_value(false)
.help("detect network address from local machine configuration"),
)
.arg(
Arg::with_name("keypair")
.short("k")
.long("keypair")
.value_name("PATH")
.takes_value(true)
.help("/path/to/id.json"),
)
.arg(
Arg::with_name("public")
.short("p")
Expand Down Expand Up @@ -54,9 +64,18 @@ fn main() {
bind_addr
};

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

// we need all the receiving sockets to be bound within the expected
// port range that we open on aws
let config = Config::new(&bind_addr);
let config = Config::new(&bind_addr, pkcs8);
let stdout = io::stdout();
serde_json::to_writer(stdout, &config).expect("serialize");
}
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
Loading