@ -8,7 +8,7 @@ use crate::poh_config::PohConfig;
|
||||
use crate::pubkey::Pubkey;
|
||||
use crate::signature::{Keypair, KeypairUtil};
|
||||
use crate::system_program;
|
||||
use crate::timing::{DEFAULT_SLOTS_PER_EPOCH, DEFAULT_TICKS_PER_SLOT};
|
||||
use crate::timing::{DEFAULT_SLOTS_PER_EPOCH, DEFAULT_SLOTS_PER_SEGMENT, DEFAULT_TICKS_PER_SLOT};
|
||||
use bincode::{deserialize, serialize};
|
||||
use memmap::Mmap;
|
||||
use std::fs::{File, OpenOptions};
|
||||
@ -24,6 +24,7 @@ pub struct GenesisBlock {
|
||||
pub stakers_slot_offset: u64,
|
||||
pub epoch_warmup: bool,
|
||||
pub ticks_per_slot: u64,
|
||||
pub slots_per_segment: u64,
|
||||
pub poh_config: PohConfig,
|
||||
pub fee_calculator: FeeCalculator,
|
||||
pub inflation: Inflation,
|
||||
@ -54,6 +55,7 @@ impl Default for GenesisBlock {
|
||||
slots_per_epoch: DEFAULT_SLOTS_PER_EPOCH,
|
||||
stakers_slot_offset: DEFAULT_SLOTS_PER_EPOCH,
|
||||
ticks_per_slot: DEFAULT_TICKS_PER_SLOT,
|
||||
slots_per_segment: DEFAULT_SLOTS_PER_SEGMENT,
|
||||
poh_config: PohConfig::default(),
|
||||
inflation: Inflation::default(),
|
||||
fee_calculator: FeeCalculator::default(),
|
||||
|
@ -17,6 +17,7 @@ const ID: [u8; 32] = [
|
||||
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
|
||||
pub struct Current {
|
||||
pub slot: Slot,
|
||||
pub segment: Segment,
|
||||
pub epoch: Epoch,
|
||||
pub stakers_epoch: Epoch,
|
||||
}
|
||||
@ -34,11 +35,18 @@ impl Current {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_account(lamports: u64, slot: Slot, epoch: Epoch, stakers_epoch: Epoch) -> Account {
|
||||
pub fn create_account(
|
||||
lamports: u64,
|
||||
slot: Slot,
|
||||
segment: Segment,
|
||||
epoch: Epoch,
|
||||
stakers_epoch: Epoch,
|
||||
) -> Account {
|
||||
Account::new_data(
|
||||
lamports,
|
||||
&Current {
|
||||
slot,
|
||||
segment,
|
||||
epoch,
|
||||
stakers_epoch,
|
||||
},
|
||||
@ -49,6 +57,8 @@ pub fn create_account(lamports: u64, slot: Slot, epoch: Epoch, stakers_epoch: Ep
|
||||
|
||||
use crate::account::KeyedAccount;
|
||||
use crate::instruction::InstructionError;
|
||||
use crate::timing::Segment;
|
||||
|
||||
pub fn from_keyed_account(account: &KeyedAccount) -> Result<Current, InstructionError> {
|
||||
if !check_id(account.unsigned_key()) {
|
||||
return Err(InstructionError::InvalidArgument);
|
||||
@ -62,7 +72,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_create_account() {
|
||||
let account = create_account(1, 0, 0, 0);
|
||||
let account = create_account(1, 0, 0, 0, 0);
|
||||
let current = Current::from(&account).unwrap();
|
||||
assert_eq!(current, Current::default());
|
||||
}
|
||||
|
@ -13,6 +13,9 @@ pub const DEFAULT_TICKS_PER_SLOT: u64 = 4;
|
||||
// 1 Epoch = 400 * 8192 ms ~= 55 minutes
|
||||
pub const DEFAULT_SLOTS_PER_EPOCH: u64 = 8192;
|
||||
|
||||
// Storage segment configuration
|
||||
pub const DEFAULT_SLOTS_PER_SEGMENT: u64 = 16;
|
||||
|
||||
pub const NUM_CONSECUTIVE_LEADER_SLOTS: u64 = 4;
|
||||
|
||||
/// The time window of recent block hash values that the bank will track the signatures
|
||||
@ -61,10 +64,17 @@ pub fn timestamp() -> u64 {
|
||||
duration_as_ms(&now)
|
||||
}
|
||||
|
||||
pub fn get_segment_from_slot(slot: Slot, slots_per_segment: u64) -> Segment {
|
||||
((slot + (slots_per_segment - 1)) / slots_per_segment)
|
||||
}
|
||||
|
||||
/// Slot is a unit of time given to a leader for encoding,
|
||||
/// is some some number of Ticks long. Use a u64 to count them.
|
||||
pub type Slot = u64;
|
||||
|
||||
/// A segment is some number of slots stored by replicators
|
||||
pub type Segment = u64;
|
||||
|
||||
/// Epoch is a unit of time a given leader schedule is honored,
|
||||
/// some number of Slots. Use a u64 to count them.
|
||||
pub type Epoch = u64;
|
||||
|
Reference in New Issue
Block a user