2018-03-03 13:41:36 -08:00
|
|
|
//! A command-line executable for generating the chain's genesis block.
|
|
|
|
|
2018-12-14 20:39:10 -08:00
|
|
|
use clap::{crate_version, value_t_or_exit, App, Arg};
|
2019-01-29 15:49:29 -08:00
|
|
|
use solana::db_ledger::create_new_ledger;
|
2019-01-24 12:04:04 -08:00
|
|
|
use solana::genesis_block::GenesisBlock;
|
2019-02-05 08:03:52 -08:00
|
|
|
use solana_sdk::signature::{read_keypair, Keypair, KeypairUtil};
|
2018-07-01 08:04:41 -07:00
|
|
|
use std::error;
|
2018-03-03 13:41:36 -08:00
|
|
|
|
2018-11-15 17:05:31 -08:00
|
|
|
/**
|
|
|
|
* Bootstrap leader gets two tokens:
|
|
|
|
* - one token to create an instance of the vote_program with
|
2018-12-10 12:20:13 -08:00
|
|
|
* - one token for the transaction fee
|
2018-11-15 17:05:31 -08:00
|
|
|
* - one second token to keep the node identity public key valid
|
|
|
|
*/
|
2019-01-09 08:20:23 -08:00
|
|
|
//pub const BOOTSTRAP_LEADER_TOKENS: u64 = 3;
|
|
|
|
// TODO: Until https://github.com/solana-labs/solana/issues/2355 is resolved the bootstrap leader
|
|
|
|
// needs N tokens as its vote account gets re-created on every node restart, costing it tokens
|
|
|
|
pub const BOOTSTRAP_LEADER_TOKENS: u64 = 1_000_000;
|
2018-11-15 17:05:31 -08:00
|
|
|
|
2018-12-08 21:44:20 -08:00
|
|
|
fn main() -> Result<(), Box<dyn error::Error>> {
|
2018-07-12 14:42:01 -07:00
|
|
|
let matches = App::new("solana-genesis")
|
2018-08-06 20:51:12 -07:00
|
|
|
.version(crate_version!())
|
2019-01-24 12:04:04 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("bootstrap_leader_keypair_file")
|
|
|
|
.short("b")
|
|
|
|
.long("bootstrap-leader-keypair")
|
|
|
|
.value_name("BOOTSTRAP LEADER KEYPAIR")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
|
|
|
.help("Path to file containing the bootstrap leader's keypair"),
|
|
|
|
)
|
|
|
|
.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(
|
2018-11-02 14:32:05 -07:00
|
|
|
Arg::with_name("num_tokens")
|
2018-07-12 14:42:01 -07:00
|
|
|
.short("t")
|
2018-11-02 14:32:05 -07:00
|
|
|
.long("num_tokens")
|
|
|
|
.value_name("TOKENS")
|
2018-07-12 14:42:01 -07:00
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
2018-11-02 14:32:05 -07:00
|
|
|
.help("Number of tokens to create in the mint"),
|
2018-12-07 19:01:28 -08:00
|
|
|
)
|
|
|
|
.arg(
|
2019-01-24 12:04:04 -08:00
|
|
|
Arg::with_name("mint_keypair_file")
|
2018-11-02 14:32:05 -07:00
|
|
|
.short("m")
|
|
|
|
.long("mint")
|
|
|
|
.value_name("MINT")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
|
|
|
.help("Path to file containing keys of the mint"),
|
2018-12-07 19:01:28 -08:00
|
|
|
)
|
|
|
|
.get_matches();
|
2018-07-12 14:42:01 -07:00
|
|
|
|
2019-01-24 12:04:04 -08:00
|
|
|
let bootstrap_leader_keypair_file = matches.value_of("bootstrap_leader_keypair_file").unwrap();
|
|
|
|
let ledger_path = matches.value_of("ledger_path").unwrap();
|
|
|
|
let mint_keypair_file = matches.value_of("mint_keypair_file").unwrap();
|
2018-11-05 08:36:22 -08:00
|
|
|
let num_tokens = value_t_or_exit!(matches, "num_tokens", u64);
|
2018-07-12 14:42:01 -07:00
|
|
|
|
2019-01-24 12:04:04 -08:00
|
|
|
let bootstrap_leader_keypair = read_keypair(bootstrap_leader_keypair_file)?;
|
|
|
|
let mint_keypair = read_keypair(mint_keypair_file)?;
|
2018-12-12 20:42:12 -08:00
|
|
|
|
2019-02-05 08:03:52 -08:00
|
|
|
let bootstrap_leader_vote_account_keypair = Keypair::new();
|
2019-01-24 12:04:04 -08:00
|
|
|
let genesis_block = GenesisBlock {
|
|
|
|
mint_id: mint_keypair.pubkey(),
|
|
|
|
tokens: num_tokens,
|
|
|
|
bootstrap_leader_id: bootstrap_leader_keypair.pubkey(),
|
|
|
|
bootstrap_leader_tokens: BOOTSTRAP_LEADER_TOKENS,
|
2019-02-05 08:03:52 -08:00
|
|
|
bootstrap_leader_vote_account_id: bootstrap_leader_vote_account_keypair.pubkey(),
|
2019-01-24 12:04:04 -08:00
|
|
|
};
|
2018-08-03 11:06:06 -07:00
|
|
|
|
2019-01-29 15:49:29 -08:00
|
|
|
create_new_ledger(ledger_path, &genesis_block)?;
|
2018-07-01 08:04:41 -07:00
|
|
|
Ok(())
|
2018-03-03 13:41:36 -08:00
|
|
|
}
|