solana/genesis/src/main.rs

81 lines
3.1 KiB
Rust
Raw Normal View History

//! 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-02-07 20:52:39 -08:00
use solana::blocktree::create_new_ledger;
use solana_sdk::genesis_block::GenesisBlock;
use solana_sdk::signature::{read_keypair, Keypair, KeypairUtil};
2018-07-01 08:04:41 -07:00
use std::error;
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-03-05 16:28:14 -08:00
//pub const BOOTSTRAP_LEADER_LAMPORTS: 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
2019-03-05 16:28:14 -08:00
pub const BOOTSTRAP_LEADER_LAMPORTS: u64 = 1_000_000;
2018-11-15 17:05:31 -08:00
fn main() -> Result<(), Box<dyn error::Error>> {
2018-07-12 14:42:01 -07:00
let matches = App::new("solana-genesis")
.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(
Arg::with_name("num_tokens")
2018-07-12 14:42:01 -07:00
.short("t")
.long("num_tokens")
.value_name("TOKENS")
2018-07-12 14:42:01 -07:00
.takes_value(true)
.required(true)
.help("Number of tokens to create in the mint"),
)
.arg(
2019-01-24 12:04:04 -08:00
Arg::with_name("mint_keypair_file")
.short("m")
.long("mint")
.value_name("MINT")
.takes_value(true)
.required(true)
.help("Path to file containing keys of the mint"),
)
.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();
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)?;
let bootstrap_leader_vote_account_keypair = Keypair::new();
let (mut genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(
num_tokens,
bootstrap_leader_keypair.pubkey(),
2019-03-05 16:28:14 -08:00
BOOTSTRAP_LEADER_LAMPORTS,
);
genesis_block.mint_id = mint_keypair.pubkey();
genesis_block.bootstrap_leader_vote_account_id = bootstrap_leader_vote_account_keypair.pubkey();
create_new_ledger(ledger_path, &genesis_block)?;
2018-07-01 08:04:41 -07:00
Ok(())
}