add genesis stake placeholders (#6969)

* add investor stake placeholders

fixups

fixups

review comments, fixups

make more data-looky for easier management

rent may be zero

rework with more tables, derived keys

fixups

rebase-fix

fixups

fixups

* genesis is now too big to boot in 10 seconds
This commit is contained in:
Rob Walker
2019-11-21 12:05:31 -08:00
committed by GitHub
parent a2a9f1e331
commit 8a879faac7
20 changed files with 1379 additions and 122 deletions

View File

@ -45,7 +45,7 @@ impl EpochSchedule {
pub fn new(slots_per_epoch: u64) -> Self {
Self::custom(slots_per_epoch, slots_per_epoch, true)
}
pub fn custom(slots_per_epoch: Epoch, leader_schedule_slot_offset: u64, warmup: bool) -> Self {
pub fn custom(slots_per_epoch: u64, leader_schedule_slot_offset: u64, warmup: bool) -> Self {
assert!(slots_per_epoch >= MINIMUM_SLOTS_PER_EPOCH as u64);
let (first_normal_epoch, first_normal_slot) = if warmup {
let next_power_of_two = slots_per_epoch.next_power_of_two();

View File

@ -66,7 +66,7 @@ macro_rules! solana_entrypoint(
/// ```
#[macro_export]
macro_rules! declare_program(
($id:ident, $bs58:expr, $name:ident, $entrypoint:ident) => (
($id:ident, $bs58:expr, $name:ident, $entrypoint:expr) => (
$crate::solana_name_id!($id, $bs58);
#[macro_export]

View File

@ -1,6 +1,5 @@
//! The `timing` module provides std::time utility functions.
use std::time::Duration;
use std::time::{SystemTime, UNIX_EPOCH};
use std::time::{Duration, SystemTime, UNIX_EPOCH};
pub fn duration_as_ns(d: &Duration) -> u64 {
d.as_secs() * 1_000_000_000 + u64::from(d.subsec_nanos())
@ -24,3 +23,42 @@ pub fn timestamp() -> u64 {
.expect("create timestamp in timing");
duration_as_ms(&now)
}
pub const SECONDS_PER_YEAR: f64 = (365.242_199 * 24.0 * 60.0 * 60.0);
/// from years to slots
pub fn years_as_slots(years: f64, tick_duration: &Duration, ticks_per_slot: u64) -> f64 {
// slots is years * slots/year
years *
// slots/year is seconds/year ...
SECONDS_PER_YEAR
// * (ns/s)/(ns/tick) / ticks/slot = 1/s/1/tick = ticks/s
*(1_000_000_000.0 / duration_as_ns(tick_duration) as f64)
// / ticks/slot
/ ticks_per_slot as f64
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_years_as_slots() {
let tick_duration = Duration::from_millis(1000 / 160);
// interestingly large numbers with 160 ticks/second
assert_eq!(years_as_slots(0.0, &tick_duration, 4) as u64, 0);
assert_eq!(
years_as_slots(1.0 / 12f64, &tick_duration, 4) as u64,
109_572_659
);
assert_eq!(years_as_slots(1.0, &tick_duration, 4) as u64, 1_314_871_916);
let tick_duration = Duration::from_millis(1000);
// one second in years with one tick per second + one tick per slot
assert_eq!(
years_as_slots(1.0 / SECONDS_PER_YEAR, &tick_duration, 1),
1.0
);
}
}