2018-03-03 13:41:36 -08:00
|
|
|
//! A command-line executable for generating the chain's genesis block.
|
|
|
|
|
2019-03-13 20:54:30 -07:00
|
|
|
use clap::{crate_description, crate_name, crate_version, value_t_or_exit, App, Arg};
|
2019-02-07 20:52:39 -08:00
|
|
|
use solana::blocktree::create_new_ledger;
|
2019-02-18 22:26:22 -08:00
|
|
|
use solana_sdk::genesis_block::GenesisBlock;
|
2019-04-10 12:51:25 -07:00
|
|
|
use solana_sdk::signature::{read_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
|
|
|
/**
|
2019-03-05 17:01:57 -08:00
|
|
|
* Bootstrap leader gets two lamports:
|
2019-04-10 12:51:25 -07:00
|
|
|
* - 42 lamports to use as stake
|
|
|
|
* - One lamport to keep the node identity public key valid
|
2018-11-15 17:05:31 -08:00
|
|
|
*/
|
2019-04-10 12:51:25 -07:00
|
|
|
pub const BOOTSTRAP_LEADER_LAMPORTS: u64 = 43;
|
2018-11-15 17:05:31 -08:00
|
|
|
|
2018-12-08 21:44:20 -08:00
|
|
|
fn main() -> Result<(), Box<dyn error::Error>> {
|
2019-03-13 20:54:30 -07:00
|
|
|
let matches = App::new(crate_name!())
|
|
|
|
.about(crate_description!())
|
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(
|
2019-03-05 17:01:57 -08:00
|
|
|
Arg::with_name("lamports")
|
2018-07-12 14:42:01 -07:00
|
|
|
.short("t")
|
2019-03-05 17:01:57 -08:00
|
|
|
.long("lamports")
|
|
|
|
.value_name("LAMPORTS")
|
2018-07-12 14:42:01 -07:00
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
2019-03-05 17:01:57 -08:00
|
|
|
.help("Number of lamports 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
|
|
|
)
|
2019-04-10 12:51:25 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("bootstrap_stake_keypair_file")
|
|
|
|
.short("s")
|
|
|
|
.long("bootstrap-stake-keypair")
|
|
|
|
.value_name("BOOTSTRAP STAKE KEYPAIR")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
|
|
|
.help("Path to file containing the bootstrap leader's staking keypair"),
|
|
|
|
)
|
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();
|
2019-04-10 12:51:25 -07:00
|
|
|
let bootstrap_stake_keypair_file = matches.value_of("bootstrap_stake_keypair_file").unwrap();
|
2019-01-24 12:04:04 -08:00
|
|
|
let ledger_path = matches.value_of("ledger_path").unwrap();
|
|
|
|
let mint_keypair_file = matches.value_of("mint_keypair_file").unwrap();
|
2019-03-05 17:01:57 -08:00
|
|
|
let lamports = value_t_or_exit!(matches, "lamports", 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)?;
|
2019-04-10 12:51:25 -07:00
|
|
|
let bootstrap_stake_keypair = read_keypair(bootstrap_stake_keypair_file)?;
|
2019-01-24 12:04:04 -08:00
|
|
|
let mint_keypair = read_keypair(mint_keypair_file)?;
|
2018-12-12 20:42:12 -08:00
|
|
|
|
2019-02-21 16:01:10 -08:00
|
|
|
let (mut genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(
|
2019-03-05 17:01:57 -08:00
|
|
|
lamports,
|
2019-03-09 19:28:43 -08:00
|
|
|
&bootstrap_leader_keypair.pubkey(),
|
2019-03-05 16:28:14 -08:00
|
|
|
BOOTSTRAP_LEADER_LAMPORTS,
|
2019-02-21 16:01:10 -08:00
|
|
|
);
|
|
|
|
genesis_block.mint_id = mint_keypair.pubkey();
|
2019-04-10 12:51:25 -07:00
|
|
|
genesis_block.bootstrap_leader_vote_account_id = bootstrap_stake_keypair.pubkey();
|
2019-04-02 07:57:00 -07:00
|
|
|
genesis_block
|
|
|
|
.native_instruction_processors
|
|
|
|
.extend_from_slice(&[
|
|
|
|
("solana_budget_program".to_string(), solana_budget_api::id()),
|
|
|
|
(
|
|
|
|
"solana_storage_program".to_string(),
|
|
|
|
solana_storage_api::id(),
|
|
|
|
),
|
|
|
|
("solana_token_program".to_string(), solana_token_api::id()),
|
|
|
|
("solana_config_program".to_string(), solana_config_api::id()),
|
|
|
|
(
|
|
|
|
"solana_exchange_program".to_string(),
|
|
|
|
solana_exchange_api::id(),
|
|
|
|
),
|
|
|
|
]);
|
2018-08-03 11:06:06 -07:00
|
|
|
|
2019-02-21 16:01:10 -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
|
|
|
}
|
2019-03-12 11:44:41 -07:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use hashbrown::HashSet;
|
|
|
|
use solana_sdk::pubkey::Pubkey;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_program_ids() {
|
|
|
|
let system = Pubkey::new(&[
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0,
|
|
|
|
]);
|
|
|
|
let native = Pubkey::new(&[
|
|
|
|
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0,
|
|
|
|
]);
|
|
|
|
let bpf = Pubkey::new(&[
|
|
|
|
128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
]);
|
|
|
|
let budget = Pubkey::new(&[
|
|
|
|
129, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
]);
|
|
|
|
let storage = Pubkey::new(&[
|
|
|
|
130, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
]);
|
|
|
|
let token = Pubkey::new(&[
|
|
|
|
131, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
]);
|
|
|
|
let vote = Pubkey::new(&[
|
|
|
|
132, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
]);
|
2019-03-14 07:55:41 -07:00
|
|
|
let config = Pubkey::new(&[
|
|
|
|
133, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
]);
|
2019-03-22 21:07:36 -07:00
|
|
|
let exchange = Pubkey::new(&[
|
|
|
|
134, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
]);
|
2019-03-12 11:44:41 -07:00
|
|
|
|
|
|
|
assert_eq!(solana_sdk::system_program::id(), system);
|
|
|
|
assert_eq!(solana_sdk::native_loader::id(), native);
|
|
|
|
assert_eq!(solana_sdk::bpf_loader::id(), bpf);
|
|
|
|
assert_eq!(solana_budget_api::id(), budget);
|
|
|
|
assert_eq!(solana_storage_api::id(), storage);
|
|
|
|
assert_eq!(solana_token_api::id(), token);
|
|
|
|
assert_eq!(solana_vote_api::id(), vote);
|
2019-03-14 07:55:41 -07:00
|
|
|
assert_eq!(solana_config_api::id(), config);
|
2019-03-22 21:07:36 -07:00
|
|
|
assert_eq!(solana_exchange_api::id(), exchange);
|
2019-03-12 11:44:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_program_id_uniqueness() {
|
|
|
|
let mut unique = HashSet::new();
|
|
|
|
let ids = vec![
|
|
|
|
solana_sdk::system_program::id(),
|
|
|
|
solana_sdk::native_loader::id(),
|
|
|
|
solana_sdk::bpf_loader::id(),
|
|
|
|
solana_budget_api::id(),
|
|
|
|
solana_storage_api::id(),
|
|
|
|
solana_token_api::id(),
|
|
|
|
solana_vote_api::id(),
|
2019-03-14 07:55:41 -07:00
|
|
|
solana_config_api::id(),
|
2019-03-22 21:07:36 -07:00
|
|
|
solana_exchange_api::id(),
|
2019-03-12 11:44:41 -07:00
|
|
|
];
|
|
|
|
assert!(ids.into_iter().all(move |id| unique.insert(id)));
|
|
|
|
}
|
|
|
|
}
|