Navigation Menu

Skip to content
This repository has been archived by the owner on Jun 11, 2022. It is now read-only.

Commit

Permalink
use the ConfigParam setting for number of slots per epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDP committed May 13, 2019
1 parent 618063a commit 028ddda
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions chain-impl-mockchain/src/ledger.rs
Expand Up @@ -68,6 +68,7 @@ pub enum Block0Error {
InitialMessageDuplicatePraosActiveSlotsCoeff,
InitialMessageNoDate,
InitialMessageNoSlotDuration,
InitialMessageNoSlotsPerEpoch,
InitialMessageNoDiscrimination,
InitialMessageNoConsensusVersion,
InitialMessageNoConsensusLeaderId,
Expand Down Expand Up @@ -190,6 +191,7 @@ impl Ledger {
let mut block0_start_time = None;
let mut slot_duration = None;
let mut discrimination = None;
let mut slots_per_epoch = None;

for param in init_ents.iter() {
match param {
Expand All @@ -202,6 +204,9 @@ impl Ledger {
ConfigParam::SlotDuration(d) => {
slot_duration = Some(*d);
}
ConfigParam::SlotsPerEpoch(n) => {
slots_per_epoch = Some(*n);
}
_ => regular_ents.push(param.clone()),
}
}
Expand All @@ -213,6 +218,8 @@ impl Ledger {
discrimination.ok_or(Error::Block0(Block0Error::InitialMessageNoDiscrimination))?;
let slot_duration =
slot_duration.ok_or(Error::Block0(Block0Error::InitialMessageNoSlotDuration))?;
let slots_per_epoch =
slots_per_epoch.ok_or(Error::Block0(Block0Error::InitialMessageNoSlotsPerEpoch))?;

let static_params = LedgerStaticParameters {
block0_initial_hash,
Expand All @@ -225,8 +232,7 @@ impl Ledger {
let tf = TimeFrame::new(timeline, SlotDuration::from_secs(slot_duration as u32));
let slot0 = tf.slot0();

// TODO -- configurable slots per epoch
let era = TimeEra::new(slot0, Epoch(0), 21600);
let era = TimeEra::new(slot0, Epoch(0), slots_per_epoch);

let settings = setting::Settings::new(era).apply(&regular_ents)?;

Expand Down Expand Up @@ -828,6 +834,7 @@ pub mod test {
ie.push(ConfigParam::ConsensusGenesisPraosActiveSlotsCoeff(
Milli::HALF,
));
ie.push(ConfigParam::SlotsPerEpoch(21600));

let mut rng = rand::thread_rng();
let (sk1, _pk1, user1_address) = make_key(&mut rng, &discrimination);
Expand Down
4 changes: 3 additions & 1 deletion chain-impl-mockchain/src/multiverse.rs
Expand Up @@ -291,14 +291,15 @@ mod test {

#[test]
pub fn multiverse() {
const NUM_BLOCK_PER_EPOCH: u32 = 1000;
let mut multiverse = Multiverse::new();

let system_time = SystemTime::UNIX_EPOCH;
let timeline = Timeline::new(system_time);
let tf = TimeFrame::new(timeline, SlotDuration::from_secs(10));

let slot0 = tf.slot0();
let era = TimeEra::new_era(slot0, Epoch(0), 1000);
let era = TimeEra::new(slot0, Epoch(0), NUM_BLOCK_PER_EPOCH);

let mut g = StdGen::new(rand::thread_rng(), 10);
let leader_key = Arbitrary::arbitrary(&mut g);
Expand All @@ -316,6 +317,7 @@ mod test {
ents.push(ConfigParam::ConsensusGenesisPraosActiveSlotsCoeff(
Milli::HALF,
));
ents.push(ConfigParam::SlotsPerEpoch(NUM_BLOCK_PER_EPOCH));
genesis_block.message(Message::Initial(ents));
let genesis_block = genesis_block.make_genesis_block();
let mut date = genesis_block.date();
Expand Down

0 comments on commit 028ddda

Please sign in to comment.