diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index 3c9716c08d1c0..06aa1cfcd3fc9 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -686,6 +686,7 @@ mod tests { &parent_hash, parent_number, slot.into(), + 0.into(), ) .unwrap() .unwrap(); diff --git a/client/consensus/babe/src/tests.rs b/client/consensus/babe/src/tests.rs index 25f1f87235702..211564fa215fe 100644 --- a/client/consensus/babe/src/tests.rs +++ b/client/consensus/babe/src/tests.rs @@ -96,7 +96,7 @@ impl Environment for DummyFactory { type Error = Error; fn init(&mut self, parent_header: &::Header) -> Self::CreateProposer { - let parent_slot = crate::find_pre_digest::(parent_header) + let parent_slot = crate::find_pre_digest::(parent_header, &0.into()) .expect("parent header has a pre-digest") .slot(); @@ -131,7 +131,7 @@ impl DummyProposer { Err(e) => return future::ready(Err(e)), }; - let this_slot = crate::find_pre_digest::(block.header()) + let this_slot = crate::find_pre_digest::(block.header(), &0.into()) .expect("baked block has valid pre-digest") .slot(); @@ -145,6 +145,7 @@ impl DummyProposer { self.parent_number, this_slot, |slot| Epoch::genesis(&self.factory.config, slot), + 0.into(), ) .expect("client has data to find epoch") .expect("can compute epoch for baked block"); @@ -450,7 +451,7 @@ async fn run_one_test(mutator: impl Fn(&mut TestHeader, Stage) + Send + Sync + ' // this test fail. let parent_header = client_clone.header(parent).ok().flatten().unwrap(); let slot = Slot::from( - find_pre_digest::(&parent_header).unwrap().slot() + 1, + find_pre_digest::(&parent_header, &0.into()).unwrap().slot() + 1, ); async move { Ok((InherentDataProvider::new(slot),)) } @@ -693,7 +694,7 @@ async fn propose_and_import_block( let mut proposer = proposer_factory.init(parent).await.unwrap(); let slot = slot.unwrap_or_else(|| { - let parent_pre_digest = find_pre_digest::(parent).unwrap(); + let parent_pre_digest = find_pre_digest::(parent, &0.into()).unwrap(); parent_pre_digest.slot() + 1 }); @@ -716,6 +717,7 @@ async fn propose_and_import_block( &parent_hash, *parent.number(), slot, + 0.into(), ) .unwrap() .unwrap(); @@ -806,9 +808,14 @@ async fn importing_block_one_sets_genesis_epoch() { let epoch_changes = data.link.epoch_changes.shared_data(); let epoch_for_second_block = epoch_changes - .epoch_data_for_child_of(descendent_query(&*client), &block_hash, 1, 1000.into(), |slot| { - Epoch::genesis(&data.link.config, slot) - }) + .epoch_data_for_child_of( + descendent_query(&*client), + &block_hash, + 1, + 1000.into(), + |slot| Epoch::genesis(&data.link.config, slot), + 0.into(), + ) .unwrap() .unwrap(); @@ -1307,6 +1314,7 @@ async fn allows_skipping_epochs() { epoch_length + 2, (epoch_length * 3 + 2).into(), |slot| Epoch::genesis(&data.link.config, slot), + 0.into(), ) .unwrap() .unwrap(); @@ -1323,6 +1331,7 @@ async fn allows_skipping_epochs() { epoch_length + 2, (epoch_length * 4 + 1).into(), |slot| Epoch::genesis(&data.link.config, slot), + 0.into(), ) .unwrap() .unwrap(); @@ -1383,6 +1392,7 @@ async fn allows_skipping_epochs_on_some_forks() { epoch_length + 2, (epoch_length * 2 + 2).into(), |slot| Epoch::genesis(&data.link.config, slot), + 0.into(), ) .unwrap() .unwrap(); @@ -1407,6 +1417,7 @@ async fn allows_skipping_epochs_on_some_forks() { epoch_length + 2, (epoch_length * 3 + 2).into(), |slot| Epoch::genesis(&data.link.config, slot), + 0.into(), ) .unwrap() .unwrap(); @@ -1425,6 +1436,7 @@ async fn allows_skipping_epochs_on_some_forks() { epoch_length + 2, (epoch_length * 4 + 1).into(), |slot| Epoch::genesis(&data.link.config, slot), + 0.into(), ) .unwrap() .unwrap(); @@ -1442,6 +1454,7 @@ async fn allows_skipping_epochs_on_some_forks() { epoch_length + 2, (epoch_length * 4 + 1).into(), |slot| Epoch::genesis(&data.link.config, slot), + 0.into(), ) .unwrap() .unwrap(); diff --git a/client/consensus/epochs/src/lib.rs b/client/consensus/epochs/src/lib.rs index f64b4861015c4..840dcd1b7ba37 100644 --- a/client/consensus/epochs/src/lib.rs +++ b/client/consensus/epochs/src/lib.rs @@ -795,7 +795,7 @@ mod tests { let epoch_changes = EpochChanges::<_, _, Epoch>::new(); let genesis_epoch = epoch_changes - .epoch_descriptor_for_child_of(&is_descendent_of, b"0", 0, 10101) + .epoch_descriptor_for_child_of(&is_descendent_of, b"0", 0, 10101, 0.into()) .unwrap() .unwrap(); @@ -807,7 +807,7 @@ mod tests { }; let genesis_epoch_2 = epoch_changes - .epoch_descriptor_for_child_of(&is_descendent_of, b"0", 0, 10102) + .epoch_descriptor_for_child_of(&is_descendent_of, b"0", 0, 10102, 0.into()) .unwrap() .unwrap(); @@ -839,7 +839,7 @@ mod tests { let mut epoch_changes = EpochChanges::<_, _, Epoch>::new(); let genesis_epoch = epoch_changes - .epoch_descriptor_for_child_of(&is_descendent_of, b"0", 0, 100) + .epoch_descriptor_for_child_of(&is_descendent_of, b"0", 0, 100, 0.into()) .unwrap() .unwrap(); @@ -862,7 +862,14 @@ mod tests { { // x is still within the genesis epoch. let x = epoch_changes - .epoch_data_for_child_of(&is_descendent_of, b"A", 1, end_slot - 1, &make_genesis) + .epoch_data_for_child_of( + &is_descendent_of, + b"A", + 1, + end_slot - 1, + &make_genesis, + 0.into(), + ) .unwrap() .unwrap(); @@ -873,7 +880,14 @@ mod tests { // x is now at the next epoch, because the block is now at the // start slot of epoch 1. let x = epoch_changes - .epoch_data_for_child_of(&is_descendent_of, b"A", 1, end_slot, &make_genesis) + .epoch_data_for_child_of( + &is_descendent_of, + b"A", + 1, + end_slot, + &make_genesis, + 0.into(), + ) .unwrap() .unwrap(); @@ -890,6 +904,7 @@ mod tests { 1, epoch_1.end_slot() - 1, &make_genesis, + 0.into(), ) .unwrap() .unwrap(); @@ -923,7 +938,7 @@ mod tests { // insert genesis epoch for A { let genesis_epoch_a_descriptor = epoch_changes - .epoch_descriptor_for_child_of(&is_descendent_of, b"0", 0, 100) + .epoch_descriptor_for_child_of(&is_descendent_of, b"0", 0, 100, 0.into()) .unwrap() .unwrap(); @@ -940,7 +955,7 @@ mod tests { // insert genesis epoch for X { let genesis_epoch_x_descriptor = epoch_changes - .epoch_descriptor_for_child_of(&is_descendent_of, b"0", 0, 1000) + .epoch_descriptor_for_child_of(&is_descendent_of, b"0", 0, 1000, 0.into()) .unwrap() .unwrap(); @@ -958,21 +973,21 @@ mod tests { // respect the chain structure. { let epoch_for_a_child = epoch_changes - .epoch_data_for_child_of(&is_descendent_of, b"A", 1, 101, &make_genesis) + .epoch_data_for_child_of(&is_descendent_of, b"A", 1, 101, &make_genesis, 0.into()) .unwrap() .unwrap(); assert_eq!(epoch_for_a_child, make_genesis(100)); let epoch_for_x_child = epoch_changes - .epoch_data_for_child_of(&is_descendent_of, b"X", 1, 1001, &make_genesis) + .epoch_data_for_child_of(&is_descendent_of, b"X", 1, 1001, &make_genesis, 0.into()) .unwrap() .unwrap(); assert_eq!(epoch_for_x_child, make_genesis(1000)); let epoch_for_x_child_before_genesis = epoch_changes - .epoch_data_for_child_of(&is_descendent_of, b"X", 1, 101, &make_genesis) + .epoch_data_for_child_of(&is_descendent_of, b"X", 1, 101, &make_genesis, 0.into()) .unwrap(); // even though there is a genesis epoch at that slot, it's not in @@ -1014,7 +1029,13 @@ mod tests { let make_genesis = |slot| Epoch { start_slot: slot, duration: 100 }; // Get epoch descriptor valid for 'slot' let epoch_descriptor = epoch_changes - .epoch_descriptor_for_child_of(&is_descendent_of, parent_hash, parent_number, slot) + .epoch_descriptor_for_child_of( + &is_descendent_of, + parent_hash, + parent_number, + slot, + 0.into(), + ) .unwrap() .unwrap(); // Increment it @@ -1111,7 +1132,13 @@ mod tests { let make_genesis = |slot| Epoch { start_slot: slot, duration: 5 }; // Get epoch descriptor valid for 'slot' let epoch_descriptor = epoch_changes - .epoch_descriptor_for_child_of(&is_descendent_of, parent_hash, parent_number, slot) + .epoch_descriptor_for_child_of( + &is_descendent_of, + parent_hash, + parent_number, + slot, + 0.into(), + ) .unwrap() .unwrap(); // Increment it diff --git a/client/consensus/manual-seal/src/consensus/timestamp.rs b/client/consensus/manual-seal/src/consensus/timestamp.rs index 21cf537262bfa..adced3132c05c 100644 --- a/client/consensus/manual-seal/src/consensus/timestamp.rs +++ b/client/consensus/manual-seal/src/consensus/timestamp.rs @@ -63,9 +63,10 @@ impl SlotTimestampProvider { let slot_duration = sc_consensus_babe::configuration(&*client)?.slot_duration(); let time = Self::with_header(&client, slot_duration, |header| { - let slot_number = *sc_consensus_babe::find_pre_digest::(&header, &sp_core::U256::zero()) - .map_err(|err| format!("{}", err))? - .slot(); + let slot_number = + *sc_consensus_babe::find_pre_digest::(&header, &sp_core::U256::zero()) + .map_err(|err| format!("{}", err))? + .slot(); Ok(slot_number) })?; diff --git a/frame/babe/src/lib.rs b/frame/babe/src/lib.rs index fa61dd42eb7a3..d2748f41d8c0a 100644 --- a/frame/babe/src/lib.rs +++ b/frame/babe/src/lib.rs @@ -122,7 +122,6 @@ impl From<&pallet::GenesisConfig> for InitConfig { } } - #[frame_support::pallet] pub mod pallet { use super::*; @@ -905,9 +904,7 @@ impl Pallet { pub fn genesis_init(config: crate::InitConfig) { SegmentIndex::::put(0); Pallet::::initialize_genesis_authorities(&config.authorities); - EpochConfig::::put( - config.epoch_config.clone().expect("epoch_config must not be None"), - ); + EpochConfig::::put(config.epoch_config.clone().expect("epoch_config must not be None")); } }