Introduce a Slot type (#7997)

* Introduce a `Slot` type

Instead of having some type definition that only was used in half of the
code or directly using `u64`, this adds a new unit type wrapper `Slot`.
This makes it especially easy for the outside api to know what type is
expected/returned.

* Change epoch duratioC

* rename all instances of slot number to slot

* Make the constructor private

Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
Bastian Köcher
2021-01-28 20:44:22 +01:00
committed by GitHub
parent 6c2dd28dfb
commit b6294418f8
34 changed files with 549 additions and 445 deletions
+3 -3
View File
@@ -151,8 +151,8 @@ impl<T: Config> FindAuthor<u32> for Module<T> {
{
for (id, mut data) in digests.into_iter() {
if id == AURA_ENGINE_ID {
if let Ok(slot_num) = u64::decode(&mut data) {
let author_index = slot_num % Self::authorities().len() as u64;
if let Ok(slot) = u64::decode(&mut data) {
let author_index = slot % Self::authorities().len() as u64;
return Some(author_index as u32)
}
}
@@ -242,7 +242,7 @@ impl<T: Config> ProvideInherent for Module<T> {
let timestamp_based_slot = timestamp / Self::slot_duration();
let seal_slot = data.aura_inherent_data()?.saturated_into();
let seal_slot = u64::from(data.aura_inherent_data()?).saturated_into();
if timestamp_based_slot == seal_slot {
Ok(())