Skip to content
Permalink
Browse files

use the ConfigParam setting for number of slots per epoch

  • Loading branch information...
NicolasDP committed May 13, 2019
1 parent 618063a commit 028ddda8b3ac6ebf4241bb276dd70cb65d2ecf79
Showing with 12 additions and 3 deletions.
  1. +9 −2 chain-impl-mockchain/src/ledger.rs
  2. +3 −1 chain-impl-mockchain/src/multiverse.rs
@@ -68,6 +68,7 @@ pub enum Block0Error {
InitialMessageDuplicatePraosActiveSlotsCoeff,
InitialMessageNoDate,
InitialMessageNoSlotDuration,
InitialMessageNoSlotsPerEpoch,
InitialMessageNoDiscrimination,
InitialMessageNoConsensusVersion,
InitialMessageNoConsensusLeaderId,
@@ -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 {
@@ -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()),
}
}
@@ -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,
@@ -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)?;

@@ -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);
@@ -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);
@@ -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();

0 comments on commit 028ddda

Please sign in to comment.
You can’t perform that action at this time.