-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Introduce a Slot type
#7997
Introduce a Slot type
#7997
Conversation
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started suggesting all of the naming changes related to slot_number -> slot. But this is cumbersome to do on github, do you mind if I just them locally and push a commit for this?
test-utils/runtime/src/lib.rs
Outdated
|
|
||
| fn generate_key_ownership_proof( | ||
| _slot_number: sp_consensus_babe::SlotNumber, | ||
| _slot_number: sp_consensus_babe::Slot, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| _slot_number: sp_consensus_babe::Slot, | |
| _slot: sp_consensus_babe::Slot, |
test-utils/runtime/src/lib.rs
Outdated
|
|
||
| fn generate_key_ownership_proof( | ||
| _slot_number: sp_consensus_babe::SlotNumber, | ||
| _slot_number: sp_consensus_babe::Slot, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| _slot_number: sp_consensus_babe::Slot, | |
| _slot: sp_consensus_babe::Slot, |
primitives/consensus/babe/src/lib.rs
Outdated
| pub start_slot: Slot, | ||
| /// The duration of this epoch. | ||
| pub duration: SlotNumber, | ||
| pub duration: Slot, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| pub duration: Slot, | |
| pub duration: u64, |
We define epoch_length above as u64 as well.
primitives/consensus/babe/src/lib.rs
Outdated
| pub fn make_transcript( | ||
| randomness: &Randomness, | ||
| slot_number: u64, | ||
| slot_number: Slot, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| slot_number: Slot, | |
| slot: Slot, |
primitives/consensus/babe/src/lib.rs
Outdated
| ) -> Transcript { | ||
| let mut transcript = Transcript::new(&BABE_ENGINE_ID); | ||
| transcript.append_u64(b"slot number", slot_number); | ||
| transcript.append_u64(b"slot number", *slot_number); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| transcript.append_u64(b"slot number", *slot_number); | |
| transcript.append_u64(b"slot number", *slot); |
primitives/consensus/babe/src/lib.rs
Outdated
| label: &BABE_ENGINE_ID, | ||
| items: vec![ | ||
| ("slot number", VRFTranscriptValue::U64(slot_number)), | ||
| ("slot number", VRFTranscriptValue::U64(*slot_number)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ("slot number", VRFTranscriptValue::U64(*slot_number)), | |
| ("slot number", VRFTranscriptValue::U64(*slot)), |
client/consensus/aura/src/digests.rs
Outdated
| } | ||
|
|
||
| fn aura_pre_digest(slot_num: u64) -> Self { | ||
| fn aura_pre_digest(slot_num: Slot) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| fn aura_pre_digest(slot_num: Slot) -> Self { | |
| fn aura_pre_digest(slot: Slot) -> Self { |
client/consensus/aura/src/digests.rs
Outdated
|
|
||
| fn aura_pre_digest(slot_num: u64) -> Self { | ||
| fn aura_pre_digest(slot_num: Slot) -> Self { | ||
| DigestItem::PreRuntime(AURA_ENGINE_ID, slot_num.encode()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| DigestItem::PreRuntime(AURA_ENGINE_ID, slot_num.encode()) | |
| DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode()) |
client/consensus/aura/src/digests.rs
Outdated
|
|
||
| /// Construct a digest item which contains the slot number | ||
| fn aura_pre_digest(slot_num: u64) -> Self; | ||
| fn aura_pre_digest(slot_num: Slot) -> Self; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| fn aura_pre_digest(slot_num: Slot) -> Self; | |
| fn aura_pre_digest(slot: Slot) -> Self; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change LGTM, I pushed a commit with some extra renaming. Will give another extra look before merging to double check tiny changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! I guess a natural next step could be to also create a type for the slot durations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
|
bot merge |
|
Trying merge. |
* Companion for #7997 paritytech/substrate#7997 * rename slot_number to slot * rename SlotNumber type in overseer docs * "Update Substrate" Co-authored-by: André Silva <[email protected]> Co-authored-by: parity-processbot <>
* Companion for #7997 paritytech/substrate#7997 * rename slot_number to slot * rename SlotNumber type in overseer docs * "Update Substrate" Co-authored-by: André Silva <[email protected]> Co-authored-by: parity-processbot <>
* Companion for #7997 paritytech/substrate#7997 * rename slot_number to slot * rename SlotNumber type in overseer docs * "Update Substrate" Co-authored-by: André Silva <[email protected]> Co-authored-by: parity-processbot <>
* Companion for #7997 paritytech/substrate#7997 * rename slot_number to slot * rename SlotNumber type in overseer docs * "Update Substrate" Co-authored-by: André Silva <[email protected]> Co-authored-by: parity-processbot <>
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 wrapperSlot.This makes it especially easy for the outside api to know what type is
expected/returned.
polkadot companion: paritytech/polkadot#2345