Add scheduler config to genesis

Anything that affects how the ledger is interpreted needs to be
in the genesis block or someplace on the ledger before later
parts of the ledger are interpreted. We currently don't have an
on-chain program for cluster parameters, so that leaves only
the genesis block option.
This commit is contained in:
Greg Fitzgerald 2019-02-21 17:01:10 -07:00 committed by Grimes
parent 3e8d96a95b
commit f0f55af35b
4 changed files with 30 additions and 39 deletions

View File

@ -67,18 +67,14 @@ fn main() -> Result<(), Box<dyn error::Error>> {
let mint_keypair = read_keypair(mint_keypair_file)?;
let bootstrap_leader_vote_account_keypair = Keypair::new();
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,
bootstrap_leader_vote_account_id: bootstrap_leader_vote_account_keypair.pubkey(),
};
let (mut genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(
num_tokens,
bootstrap_leader_keypair.pubkey(),
BOOTSTRAP_LEADER_TOKENS,
);
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,
&solana::blocktree::BlocktreeConfig::default(),
)?;
create_new_ledger(ledger_path, &genesis_block)?;
Ok(())
}

View File

@ -23,10 +23,7 @@ use solana_sdk::signature::{Keypair, Signature};
use solana_sdk::storage_program;
use solana_sdk::system_program;
use solana_sdk::system_transaction::SystemTransaction;
use solana_sdk::timing::{
duration_as_us, DEFAULT_SLOTS_PER_EPOCH, DEFAULT_TICKS_PER_SLOT, MAX_ENTRY_IDS,
NUM_TICKS_PER_SECOND,
};
use solana_sdk::timing::{duration_as_us, MAX_ENTRY_IDS, NUM_TICKS_PER_SECOND};
use solana_sdk::token_program;
use solana_sdk::transaction::Transaction;
use solana_sdk::vote_program::{self, VoteState};
@ -80,6 +77,7 @@ pub type Result<T> = result::Result<T, BankError>;
type BankStatusCache = StatusCache<BankError>;
/// Manager for the state of all accounts and programs after processing its entries.
#[derive(Default)]
pub struct Bank {
accounts: Accounts,
@ -109,25 +107,9 @@ pub struct Bank {
leader: Pubkey,
}
impl Default for Bank {
fn default() -> Self {
Self {
accounts: Accounts::default(),
status_cache: RwLock::<BankStatusCache>::default(),
last_id_queue: RwLock::<LastIdQueue>::default(),
parent: Option::<Arc<Bank>>::default(),
hash: RwLock::<Hash>::default(),
ticks_per_slot: DEFAULT_TICKS_PER_SLOT,
slots_per_epoch: DEFAULT_SLOTS_PER_EPOCH,
leader_schedule_slot_offset: DEFAULT_SLOTS_PER_EPOCH,
leader: Pubkey::default(),
}
}
}
impl Bank {
pub fn new(genesis_block: &GenesisBlock) -> Self {
let bank = Self::default();
let mut bank = Self::default();
bank.process_genesis_block(genesis_block);
bank.add_builtin_programs();
bank
@ -177,7 +159,7 @@ impl Bank {
self.parent.is_none()
}
fn process_genesis_block(&self, genesis_block: &GenesisBlock) {
fn process_genesis_block(&mut self, genesis_block: &GenesisBlock) {
assert!(genesis_block.mint_id != Pubkey::default());
assert!(genesis_block.bootstrap_leader_id != Pubkey::default());
assert!(genesis_block.bootstrap_leader_vote_account_id != Pubkey::default());
@ -218,6 +200,10 @@ impl Bank {
.write()
.unwrap()
.genesis_last_id(&genesis_block.last_id());
self.ticks_per_slot = genesis_block.ticks_per_slot;
self.slots_per_epoch = genesis_block.slots_per_epoch;
self.leader_schedule_slot_offset = genesis_block.leader_schedule_slot_offset;
}
pub fn add_native_program(&self, name: &str, program_id: &Pubkey) {

View File

@ -3,6 +3,7 @@
use crate::hash::{hash, Hash};
use crate::pubkey::Pubkey;
use crate::signature::{Keypair, KeypairUtil};
use crate::timing::{DEFAULT_SLOTS_PER_EPOCH, DEFAULT_TICKS_PER_SLOT};
use std::fs::File;
use std::io::Write;
use std::path::Path;
@ -19,6 +20,9 @@ pub struct GenesisBlock {
pub bootstrap_leader_vote_account_id: Pubkey,
pub mint_id: Pubkey,
pub tokens: u64,
pub ticks_per_slot: u64,
pub slots_per_epoch: u64,
pub leader_schedule_slot_offset: u64,
}
impl GenesisBlock {
@ -44,6 +48,9 @@ impl GenesisBlock {
bootstrap_leader_vote_account_id: bootstrap_leader_vote_account_keypair.pubkey(),
mint_id: mint_keypair.pubkey(),
tokens,
ticks_per_slot: DEFAULT_TICKS_PER_SLOT,
slots_per_epoch: DEFAULT_SLOTS_PER_EPOCH,
leader_schedule_slot_offset: DEFAULT_SLOTS_PER_EPOCH,
},
mint_keypair,
)

View File

@ -1266,17 +1266,16 @@ impl Iterator for EntryIterator {
// Returns a tuple (entry_height, tick_height, last_id), corresponding to the
// total number of entries, the number of ticks, and the last id generated in the
// new ledger
#[allow(clippy::trivially_copy_pass_by_ref)]
pub fn create_new_ledger(
ledger_path: &str,
genesis_block: &GenesisBlock,
config: &BlocktreeConfig,
) -> Result<(u64, u64, Hash)> {
let config = BlocktreeConfig::new(genesis_block.ticks_per_slot);
Blocktree::destroy(ledger_path)?;
genesis_block.write(&ledger_path)?;
// Add a single tick linked back to the genesis_block to bootstrap the ledger
let blocktree = Blocktree::open_config(ledger_path, config)?;
let blocktree = Blocktree::open_config(ledger_path, &config)?;
let entries = crate::entry::create_ticks(1, genesis_block.last_id());
blocktree.write_entries(DEFAULT_SLOT_HEIGHT, 0, 0, &entries)?;
@ -1328,11 +1327,14 @@ pub fn create_tmp_sample_ledger(
bootstrap_leader_tokens: u64,
config: &BlocktreeConfig,
) -> (Keypair, String, u64, u64, Hash, Hash) {
let (genesis_block, mint_keypair) =
// TODO: Pass in a genesis block instead of all its parameters.
let (mut genesis_block, mint_keypair) =
GenesisBlock::new_with_leader(num_tokens, bootstrap_leader_id, bootstrap_leader_tokens);
genesis_block.ticks_per_slot = config.ticks_per_slot;
let ledger_path = get_tmp_ledger_path(name);
let (mut entry_height, mut tick_height, mut last_entry_id) =
create_new_ledger(&ledger_path, &genesis_block, config).unwrap();
create_new_ledger(&ledger_path, &genesis_block).unwrap();
let mut last_id = genesis_block.last_id();
if num_extra_ticks > 0 {